Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build Project with Generated Client, Update package.md, Test and Validate Functionality #3

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
266f36d
Add generated client code and documentation
Irash-Perera Jan 7, 2025
fb7f7b6
Add mock service and tests for feedback submissions
Irash-Perera Jan 8, 2025
1ef4433
Update README.md
Irash-Perera Jan 8, 2025
0433f60
[Automated] Update the toml files
Irash-Perera Jan 8, 2025
9c5114a
Refactor README.md for clarity and formatting improvements
Irash-Perera Jan 8, 2025
1dd440e
Refactor mock service documentation and clean up test cases
Irash-Perera Jan 8, 2025
916bb44
Update distribution version and change package organization for feedb…
Irash-Perera Jan 8, 2025
e32b1b5
Add copyright notice and license information.
Irash-Perera Jan 8, 2025
4e782c3
Sanitized API endpoints in tests and utils for consistency
Irash-Perera Jan 8, 2025
5a67586
[Automated] Update the toml files
Irash-Perera Jan 9, 2025
f83b32b
[Automated] Update the toml files
Irash-Perera Jan 9, 2025
a1cb28b
Refactor README and module documentation
Irash-Perera Jan 9, 2025
92eda7f
Update keywords in Ballerina.toml for improved discoverability
Irash-Perera Jan 9, 2025
ebb7f5b
Refactor README and Module documentation
Irash-Perera Jan 9, 2025
ca351d7
Add auto-generated file notice to client, types, and utils modules
Irash-Perera Jan 9, 2025
f38d715
Fix missing newlines at the end of several files in tests and examples
Irash-Perera Jan 9, 2025
aa5c33f
Update README and Module documentation for HubSpot CRM connector
Irash-Perera Jan 9, 2025
4c74cb7
Refactor client configuration
Irash-Perera Jan 9, 2025
273f8ec
Fix typo
Irash-Perera Jan 9, 2025
9b1eaff
Update sanitation documentation for OpenAPI specification.
Irash-Perera Jan 9, 2025
90cabf5
Update README and Module documentation
Irash-Perera Jan 9, 2025
c754d69
Refactor feedback review example mock tests
Irash-Perera Jan 9, 2025
bb376b7
Remove unused HTTP import from test file
Irash-Perera Jan 9, 2025
dfc5c11
Remove commented-out BearerTokenConfig from test file
Irash-Perera Jan 9, 2025
7319775
Enhance feedback review example with detailed comments and update tes…
Irash-Perera Jan 9, 2025
e3075d3
Update copyright year in license file
Irash-Perera Jan 9, 2025
84bc8bd
Update OpenAPI client generation command to include license file
Irash-Perera Jan 9, 2025
e606099
Update README and module documentation to reflect pagination in feedb…
Irash-Perera Jan 9, 2025
6810b7c
Fix feedback submission type reference in documentation
Irash-Perera Jan 9, 2025
2fa2bef
Sanitized feedback submissions API endpoints and update related tests…
Irash-Perera Jan 10, 2025
f1dc871
Refactor README and module documentation
Irash-Perera Jan 10, 2025
39092ba
Add configuration template and update tests for live and mock server …
Irash-Perera Jan 10, 2025
26f3528
Update module references in documentation to use 'hubspot.crm.obj.fee…
Irash-Perera Jan 10, 2025
655cdb3
Format code for consistency in mock service and test files
Irash-Perera Jan 10, 2025
468d92c
[Automated] Update the toml files
Irash-Perera Jan 10, 2025
433a05f
Add icon
Irash-Perera Jan 10, 2025
826bfcf
Refactor client initialization and update test configurations for liv…
Irash-Perera Jan 10, 2025
c8e4c48
Update README and module documentation to include refresh token in au…
Irash-Perera Jan 10, 2025
0616704
Simplify API paths by removing common prefix from endpoints for impro…
Irash-Perera Jan 12, 2025
fe1b2c3
Update sanitations.md
Irash-Perera Jan 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ build

# Ignore Docker env file
docker.env

openapi-spec
Irash-Perera marked this conversation as resolved.
Show resolved Hide resolved
206 changes: 181 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,208 @@

## Overview

[//]: # (TODO: Add overview mentioning the purpose of the module, supported REST API versions, and other high-level details.)
[HubSpot](https://developers.hubspot.com) is an AI-powered customer relationship management (CRM) platform.

The `ballerinax/hubspot.crm.object.feedback` offers APIs to connect and interact with the [HubSpot Feedback Submission API](https://developers.hubspot.com/docs/reference/api/crm/objects/feedback-submissions) endpoints, specifically based on the [HubSpot REST API](https://developers.hubspot.com/docs/reference/api).
Irash-Perera marked this conversation as resolved.
Show resolved Hide resolved

> **Note:** This package may be changed in the future based on the HubSpot API changes, since it is currently under development and is subject to change based on testing and feedback. By using this package, you are agreeing to accept any future changes that might occur and understand the risk associated with testing an unstable API. Refer to the [HubSpot Developer Terms](https://legal.hubspot.com/developer-terms) & [Developer Beta Terms](https://legal.hubspot.com/developerbetaterms) for more information.
>
> The feedback submissions endpoints are currently read only. Feedback submissions cannot be submitted or edited through the API.

## Setup guide

[//]: # (TODO: Add detailed steps to obtain credentials and configure the module.)
To use the HubSpot Feedback connector, you must have access to the HubSpot API through a HubSpot developer account and a HubSpot App under it. Therefore you need to register for a developer account at HubSpot if you don't have one already.

### Step 1: Create/Login to a HubSpot Developer Account

If you have an account already, go to the [HubSpot developer portal](https://app.hubspot.com/)

If you don't have a HubSpot Developer Account you can sign up to a free account [here](https://developers.hubspot.com/get-started)

### Step 2 (Optional): Create a [Developer Test Account](https://developers.hubspot.com/beta-docs/getting-started/account-types#developer-test-accounts) under your account

Within app developer accounts, you can create developer test accounts to test apps and integrations without affecting any real HubSpot data.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Step 2 (Optional): Create a [Developer Test Account](https://developers.hubspot.com/beta-docs/getting-started/account-types#developer-test-accounts) under your account
Within app developer accounts, you can create developer test accounts to test apps and integrations without affecting any real HubSpot data.
### Step 2 (Optional): Create a Developer Test Account
Within app developer accounts, you can create a [developer test account](https://developers.hubspot.com/beta-docs/getting-started/account-types#developer-test-accounts) under your account to test apps and integrations without affecting any real HubSpot data.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check all the comments that are marked as resolved, without being fixed.


> **Note:** These accounts are only for development and testing purposes. In production you should not use Developer Test Accounts.

### Step 2 (Optional): Create a Developer Test Account

1. Go to the Test accounts section from the left sidebar.
![Test accounts section](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.object.feedback/main/docs/resources/test-account.png)

2. Click on the `Create developer test account` button on the top right corner.
![Create developer test account](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.object.feedback/main/docs/resources/create-test-account.png)

3. In the pop-up window, provide a name for the test account and click on the `Create` button.
![Create test account](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.object.feedback/main/docs/resources/create-account.png)
You will see the newly created test account in the list of test accounts.
![Test account portal](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.object.feedback/main/docs/resources/test-account-portal.png)

### Step 3: Create a HubSpot App

1. Now navigate to the `Apps` section from the left sidebar and click on the `Create app` button on the top right corner.
![Create app](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.object.feedback/main/docs/resources/create-app.png)

2. Provide a public app name and description for your app.
![App name and description](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.object.feedback/main/docs/resources/app-name-desc.png)

### Step 4: Setup Authentication

1. Move to the `Auth` tab.
![Configure authentication](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.object.feedback/main/docs/resources/config-auth.png)

2. In the `Scopes` section, add the following scopes for your app using the `Add new scopes` button.
- `e-commerce`
- `tickets`
- `crm.objects.goals.read`
- `media_bridge.read`
- `crm.objects.custom.read`
- `crm.objects.custom.write`
- `crm.objects.feedback_submissions.read`

![Add scopes](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.object.feedback/main/docs/resources/add-scopes.png)

3. In the `Redirect URL` section, add the redirect URL for your app. This is the URL where the user will be redirected after the authentication process. You can use `localhost` for testing purposes. Then click the `Create App` button.

![Redirect URL](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.object.feedback/main/docs/resources/redirect-url.png)

### Step 5: Get the Client ID and Client Secret

Navigate to the `Auth` tab and you will see the `Client ID` and `Client Secret` for your app. Make sure to save these values.
![Client ID and Client Secret](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.object.feedback/main/docs/resources/client-id-secret.png)

### Step 6: Setup Authentication Flow

Before proceeding with the Quickstart, ensure you have obtained the Access Token using the following steps:

1. Create an authorization URL using the following format:

```
https://app.hubspot.com/oauth/authorize?client_id=<YOUR_CLIENT_ID>&scope=<YOUR_SCOPES>&redirect_uri=<YOUR_REDIRECT_URI>
```

Replace the `<YOUR_CLIENT_ID>`, `<YOUR_REDIRECT_URI>` and `<YOUR_SCOPES>` with your specific value.
2. Paste it in the browser and select your developer test account to intall the app when prompted.
!![Account select](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.object.feedback/main/docs/resources/account-select.png)

3. A code will be displayed in the browser. Copy the code.

4. Run the following curl command. Replace the `<YOUR_CLIENT_ID>`, `<YOUR_REDIRECT_URI`> and `<YOUR_CLIENT_SECRET>` with your specific value. Use the code you received in the above step 3 as the `<CODE>`.

- Linux/macOS

```bash
curl --request POST \
--url https://api.hubapi.com/oauth/v1/token \
--header 'content-type: application/x-www-form-urlencoded' \
--data 'grant_type=authorization_code&code=<CODE>&redirect_uri=<YOUR_REDIRECT_URI>&client_id=<YOUR_CLIENT_ID>&client_secret=<YOUR_CLIENT_SECRET>'
```
- Windows

```bash
curl --request POST ^
--url https://api.hubapi.com/oauth/v1/token ^
--header 'content-type: application/x-www-form-urlencoded' ^
--data 'grant_type=authorization_code&code=<CODE>&redirect_uri=<YOUR_REDIRECT_URI>&client_id=<YOUR_CLIENT_ID>&client_secret=<YOUR_CLIENT_SECRET>'
```

This command will return the access token necessary for API calls.

```json
{
"token_type": "bearer",
"refresh_token": "<Refresh Token>",
"access_token": "<Access Token>",
"expires_in": 1800
}
```
5. Store the access token securely for use in your application.

## Quickstart
Irash-Perera marked this conversation as resolved.
Show resolved Hide resolved

[//]: # (TODO: Add a quickstart guide to demonstrate a basic functionality of the module, including sample code snippets.)
To use the `Hubspot CRM Feedback Submission` connector in your Ballerina application, update the `.bal` file as follows:

### Step 1: Import the module

Import the `hubspot.crm.obj.feedback` module and `oauth2` module.

```ballerina
import ballerinax/hubspot.crm.obj.feedback as feedback;
import ballerina/oauth2;
```

### Step 2: Instantiate a new connector

1. Create a `Config.toml` file and, configure the obtained credentials in the above steps as follows:

```toml
clientId = <Client Id>
clientSecret = <Client Secret>
refreshToken = <Refresh Token>
```

2. Instantiate a `feedback:ConnectionConfig` with the obtained credentials and initialize the connector with it.

```ballerina
configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string refreshToken = ?;

feedback:ConnectionConfig config = {
auth: {
clientId,
clientSecret,
refreshToken,
credentialBearer: oauth2:POST_BODY_BEARER
}
};

final feedback:Client baseClient = check new feedback:Client(config);
```

### Step 3: Invoke the connector operation

Now, utilize the available connector operations. A sample usecase is shown below.

#### View Submitted Feedbacks

```ballerina
public function main() returns error? {
feedback:CollectionResponseSimplePublicObjectWithAssociationsForwardPaging allFeedbackSubmissions = check baseClient->/feedback_submissions;
io:println("All feedback submissions: ", allFeedbackSubmissions);
}
```

## Examples

The `HubSpot CRM Feedback` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/module-ballerinax-hubspot.crm.object.feedback/tree/main/examples/), covering the following use cases:
The `HubSpot CRM Feedback` connector provides practical examples illustrating usage in various scenarios.

[//]: # (TODO: Add examples)
[Feedback Reviewing](https://github.com/module-ballerinax-hubspot.crm.object.feedback/tree/main/examples/) - This example demonstrates the usage of the HubSpot CRM Feedback connector to read a page of feedback submissions, read an object identified by `{feedbackSubmissionId}`, read a batch of feedback submissions by internal ID, or unique property values, and search feedback submissions.

> **Note**: The feedback submissions endpoints are currently read only. Feedback submissions cannot be submitted or edited through the API. You can only create properties in the [feedback surveys tool within HubSpot](https://knowledge.hubspot.com/customer-feedback/create-a-custom-survey?_gl=1*1h5ce0o*_ga*MzIyODQzMTUyLjE3MzYzNjE3OTU.*_ga_LXTM6CQ0XK*MTczNjQwNjg4NS4zLjEuMTczNjQwNjg5OS40Ni4wLjA.&_ga=2.97072604.213367396.1736361795-322843152.1736361795#survey), and the properties cannot be edited after creation.
Irash-Perera marked this conversation as resolved.
Show resolved Hide resolved

## Build from the source

### Setting up the prerequisites

1. Download and install Java SE Development Kit (JDK) version 21. You can download it from either of the following sources:

* [Oracle JDK](https://www.oracle.com/java/technologies/downloads/)
* [OpenJDK](https://adoptium.net/)
* [Oracle JDK](https://www.oracle.com/java/technologies/downloads/)
* [OpenJDK](https://adoptium.net/)

> **Note:** After installation, remember to set the `JAVA_HOME` environment variable to the directory where JDK was installed.

>
2. Download and install [Ballerina Swan Lake](https://ballerina.io/).

3. Download and install [Docker](https://www.docker.com/get-started).

> **Note**: Ensure that the Docker daemon is running before executing any tests.

>
4. Export Github Personal access token with read package permissions as follows,

```bash
export packageUser=<Username>
export packagePAT=<Personal access token>
```
```bash
export packageUser=<Username>
export packagePAT=<Personal access token>
```

### Build options

Expand All @@ -57,43 +220,36 @@ Execute the commands below to build from the source.
```bash
./gradlew clean build
```

2. To run the tests:

```bash
./gradlew clean test
```

3. To build the without the tests:

```bash
./gradlew clean build -x test
```

4. To run tests against different environments:

```bash
./gradlew clean test -Pgroups=<Comma separated groups/test cases>
```

5. To debug the package with a remote debugger:

```bash
./gradlew clean build -Pdebug=<port>
```

6. To debug with the Ballerina language:

```bash
./gradlew clean build -PbalJavaDebug=<port>
```

7. Publish the generated artifacts to the local Ballerina Central repository:

```bash
./gradlew clean build -PpublishToLocalCentral=true
```

```bash
./gradlew clean build -PpublishToLocalCentral=true
```
8. Publish the generated artifacts to the Ballerina Central repository:

```bash
Expand All @@ -115,4 +271,4 @@ All the contributors are encouraged to read the [Ballerina Code of Conduct](http
* For more information go to the [`hubspot.crm.object.feedback` package](https://central.ballerina.io/ballerinax/hubspot.crm.object.feedback/latest).
Irash-Perera marked this conversation as resolved.
Show resolved Hide resolved
* For example demonstrations of the usage, go to [Ballerina By Examples](https://ballerina.io/learn/by-example/).
* Chat live with us via our [Discord server](https://discord.gg/ballerinalang).
* Post all technical questions on Stack Overflow with the [#ballerina](https://stackoverflow.com/questions/tagged/ballerina) tag.
* Post all technical questions on Stack Overflow with the [#ballerina](https://stackoverflow.com/questions/tagged/ballerina) tag.
10 changes: 5 additions & 5 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[package]
distribution = "2201.10.0"
org = "ballerinax"
name = "hubspot.crm.object.feedback"
version = "1.0.0"
name = "hubspot.crm.obj.feedback"
version = "0.1.0"
license = ["Apache-2.0"]
authors = ["Ballerina"]
keywords = []
# icon = "icon.png" # TODO: update icon.png
keywords = ["hubspot", "crm", "feedback"]
# icon = "icon.png"
repository = "https://github.com/ballerina-platform/module-ballerinax-hubspot.crm.object.feedback"

[build-options]
observabilityIncluded = true

[platform.java21]
[platform.java17]
graalvmCompatible = true
Loading