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

Generate Code, Add test, Add Examples #3

Merged
merged 73 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
a9b8dd6
[Automated] Update the toml files
Pranavan-S Jan 8, 2025
d72e22d
Generate code based on discounts.json and add test cases
Pranavan-S Jan 8, 2025
694f68c
add documentation
Pranavan-S Jan 8, 2025
b41ce24
add example
Pranavan-S Jan 8, 2025
330d8ef
remove unnecessary newline at end of file in main.bal
Pranavan-S Jan 8, 2025
deb6243
update README and module documentation to clarify HubSpot Discounts A…
Pranavan-S Jan 8, 2025
6c8c6c5
create example discount_manager
Pranavan-S Jan 8, 2025
5b6acb5
add README for Hubspot Discount Manager example
Pranavan-S Jan 8, 2025
1ee4005
add README for Festival Discounts example
Pranavan-S Jan 8, 2025
26e4393
update examples README to enhance clarity on discount management and …
Pranavan-S Jan 8, 2025
36c9dfa
remove unnecessary blank lines in test functions for improved readabi…
Pranavan-S Jan 8, 2025
d06cede
update distribution version to 2201.10.3 in Dependencies.toml
Pranavan-S Jan 8, 2025
8840742
[Automated] Update the toml files
Pranavan-S Jan 9, 2025
2186bb4
[Automated] Update the toml files
Pranavan-S Jan 9, 2025
2d98209
add mock service for discount management and update service URL confi…
Pranavan-S Jan 9, 2025
8393f93
fix: update image paths in documentation and add examples for discoun…
Pranavan-S Jan 9, 2025
e09eaee
docs: add examples for discount management in README
Pranavan-S Jan 9, 2025
044a57f
feat: enhance mock service with batch upsert functionality and update…
Pranavan-S Jan 9, 2025
f69201d
fix: correct formatting in test configuration annotation
Pranavan-S Jan 9, 2025
564ba32
docs: update example links in README for discount management
Pranavan-S Jan 9, 2025
79de690
refactor: update variable names for consistency in discount tests
Pranavan-S Jan 9, 2025
60bad3f
docs: update README for improved clarity and consistency in instructions
Pranavan-S Jan 9, 2025
1391c37
fix: update mock service response formatting for consistency
Pranavan-S Jan 9, 2025
68533aa
fix: handle errors with check for discount operations in main function
Pranavan-S Jan 9, 2025
06d6cf1
fix: improve error handling in discount operations and update respons…
Pranavan-S Jan 9, 2025
9657dd4
refactor: update variable name for consistency in README example
Pranavan-S Jan 9, 2025
b0189d4
refactor: update variable names for consistency in discount managemen…
Pranavan-S Jan 9, 2025
ba3c359
fix: update documentation for consistency in formatting and terminology
Pranavan-S Jan 9, 2025
ce13e19
fix: update OpenAPI CLI command for client generation and improve lic…
Pranavan-S Jan 9, 2025
fc23485
fix: update OpenAPI specification source link for improved usability
Pranavan-S Jan 9, 2025
9e6876e
Add icon.png into ballrina folder
Pranavan-S Jan 9, 2025
d550f43
fix: update Ballerina.toml to include keywords and set icon
Pranavan-S Jan 9, 2025
bfc8510
fix: improve wording in README for clarity on using HubSpot CRM Comme…
Pranavan-S Jan 9, 2025
de82233
fix: update copyright year in auto-generated files to 2025
Pranavan-S Jan 9, 2025
94959de
remove taxes. add discounts.
Pranavan-S Jan 9, 2025
ac82ab4
[Automated] Update the toml files
Pranavan-S Jan 9, 2025
6f7abcc
fix: update author attribution in sanitations.md
Pranavan-S Jan 9, 2025
da925aa
Add new line at the end
Pranavan-S Jan 9, 2025
64862e4
Add new line at the end
Pranavan-S Jan 9, 2025
b5b28f9
Add new line at the end.
Pranavan-S Jan 9, 2025
2b233f4
fix: remove unnecessary blank lines in discount manager and festival …
Pranavan-S Jan 9, 2025
8dd4485
fix: update README examples to reference Ballerina Hubspot CRM Discou…
Pranavan-S Jan 9, 2025
a904726
fix: update distribution version and remove unused dependencies in De…
Pranavan-S Jan 9, 2025
43a1a22
[Automated] Update the toml files
Pranavan-S Jan 9, 2025
dd46a0d
fix: update README and module documentation for consistency in "Auth"…
Pranavan-S Jan 9, 2025
1348871
fix: improve error handling in payment processing module
Pranavan-S Jan 9, 2025
e90facf
fix: correct formatting in mock_service.bal for consistency
Pranavan-S Jan 9, 2025
a8a7155
fix: add missing newline at the end of Dependencies.toml files for co…
Pranavan-S Jan 9, 2025
7c36ab4
fix: remove example text for clarity in README and module documentation
Pranavan-S Jan 9, 2025
3849e21
fix: remove unnecessary blank lines in README and module documentatio…
Pranavan-S Jan 9, 2025
5077295
[Automated] Update the toml files
Pranavan-S Jan 9, 2025
7c6c7b1
[Automated] Update the toml files
Pranavan-S Jan 9, 2025
cbcb9a9
fix: improve function signatures for better readability in mock_servi…
Pranavan-S Jan 9, 2025
7cc5f57
fix: improve code readability by formatting long lines in tests.bal
Pranavan-S Jan 9, 2025
8ad6e70
fix: improve code readability by formatting long lines and enhancing …
Pranavan-S Jan 9, 2025
257874e
fix: update Ballerina.toml to add keywords and icon for better projec…
Pranavan-S Jan 9, 2025
fb02b8c
fix: update author formatting in sanitations.md for consistency
Pranavan-S Jan 9, 2025
595623d
fix: improve code readability by formatting long lines in discount ma…
Pranavan-S Jan 9, 2025
3224e3f
fix: update copyright year in license.txt to 2025
Pranavan-S Jan 9, 2025
fe7d793
fix: enhance usability and readability in sanitations.md by updating …
Pranavan-S Jan 9, 2025
7b282e6
[Automated] Update the toml files
Pranavan-S Jan 9, 2025
9c91ad7
fix: update example links in documentation to use raw GitHub URLs
Pranavan-S Jan 10, 2025
61d948c
[Automated] Update the toml files
Pranavan-S Jan 10, 2025
a589dfd
fix: improve formatting and clarity in README, Module, and Package do…
Pranavan-S Jan 10, 2025
e65b615
fix: update example links in documentation to use GitHub URLs
Pranavan-S Jan 10, 2025
35d4621
fix: update example links in documentation to use direct GitHub URLs
Pranavan-S Jan 10, 2025
f15e985
fix: update the last updated date in the sanitation documentation
Pranavan-S Jan 10, 2025
e4a9692
fix: improve code formatting and update mock service client configura…
Pranavan-S Jan 10, 2025
0640e7e
fix: update example links in documentation to point to the correct re…
Pranavan-S Jan 10, 2025
ded7158
fix: update example links in documentation to point to the correct Gi…
Pranavan-S Jan 10, 2025
fbfa85a
fix: add test groups for better organization of live and mock tests
Pranavan-S Jan 10, 2025
e322680
Merge branch 'main' of https://github.com/ballerina-platform/module-b…
Pranavan-S Jan 10, 2025
daf7b24
Only enable mock_tests
Pranavan-S Jan 10, 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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ jobs:
secrets: inherit
with:
repo-name: module-ballerinax-hubspot.crm.commerce.discounts
additional-test-flags: '-Pgropus=mock_tests'

1 change: 1 addition & 0 deletions .github/workflows/dev-stg-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ jobs:
secrets: inherit
with:
environment: ${{ github.event.inputs.environment }}
additional-publish-flags: '-Pgropus=mock_tests'
149 changes: 144 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,160 @@

## Overview

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

The `ballerinax/hubspot.crm.commerce.discounts` connector offers APIs to connect and interact with the [Hubspot Discounts API](https://developers.hubspot.com/docs/guides/api/crm/commerce/discounts) endpoints, specifically based on the [HubSpot REST API](https://developers.hubspot.com/docs/reference/api/overview).


## Setup guide

[//]: # (TODO: Add detailed steps to obtain credentials and configure the module.)
You need a [HubSpot developer account](https://developers.hubspot.com/get-started) with an [app](https://developers.hubspot.com/docs/guides/apps/public-apps/overview) to use HubSpot connectors.
>To create a HubSpot Developer account, [click here](https://app.hubspot.com/signup-hubspot/developers?_ga=2.207749649.2047916093.1734412948-232493525.1734412948&step=landing_page)

### Step 1: Create HubSpot Developer Project
1. [Login](https://app.hubspot.com/login) to HubSpot developer account.

2. Create a public app by clicking on "Create app".

![Building public image](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.commerce.discounts/main/docs/setup/resources/build_public_app.png)

3. Click on "Create app".

![Creating App](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.commerce.discounts/main/docs/setup/resources/create_app.png)

4. Under "App Info"
- Enter Public app name.
- Update App logo (optional).
- Update Description (optional).

![Entering App details](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.commerce.discounts/main/docs/setup/resources/enter_app_details.png)

- Then move to "Auth" tab.

5. Setup the "Redirect URLs" with respective links.

![Auth Tab](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.commerce.discounts/main/docs/setup/resources/auth_page.png)

Finally Create the app.

### Step 2: Get Client ID and Client secret.
Navigate to "Auth" tab.

![Client ID & Secret](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.commerce.discounts/main/docs/setup/resources/client_id_secret.png)

### Step 3: Get access token and refresh token.

1. Set scopes under "Auth" tab for your app based on the [API requirements](https://developers.hubspot.com/docs/reference/api).

![API Reference page](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.commerce.discounts/main/docs/setup/resources/exmaple_api_reference.png).

Enable scopes required for HubSpot CRM Discounts API.
- `crm.objects.line_items.read`
- `crm.objects.line_items.write`
- `oauth`

2. Under "Auth" tab under Sample install URL (OAuth) section copy the full URL.
```
https://app.hubspot.com/oauth/authorize?client_id=<client_id>&redirect_uri=<redirect_url>&scope=<scopes>
```

3. Choose the preferred account.

![Choosing Accounts](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.commerce.discounts/main/docs/setup/resources/account_chose.png)

Choose account and authorize the client.

4. Check URL tab and find the authorization code.

5. Send a http request to the HubSpot.
* 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=http://localhost:9090&client_id=<client_id>&client_secret=<client_secret>'
```

6. Above command returns the access token and refresh token.

7. Use these tokens to authorize the client.

## Quickstart

[//]: # (TODO: Add a quickstart guide to demonstrate a basic functionality of the module, including sample code snippets.)
Follow the below steps to use the `HubSpot CRM Commerce Discounts` connector in your Ballerina application.

### Step 1: Import the module

Import the `hubspot.crm.commerce.discounts` module and `oauth2` module.

```ballerina
import ballerina/oauth2;
import ballerinax/hubspot.crm.commerce.discounts;
```

### Step 2: Instantiate a new connector

1. Instantiate a `OAuth2RefreshTokenGrantConfig` with the obtained credentials and initialize the connector with it.

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

ConnectionConfig config = {
auth: {
clientId,
clientSecret,
refreshToken,
credentialBearer: oauth2:POST_BODY_BEARER
}
};
final Client hubSpotClient = check new (config);
```

2. Create a `Config.toml` file inside the Ballerina package and add the following configurations with the values retrieved in the earlier steps.
```toml
clientId = <Client Id>
clientSecret = <Client Secret>
refreshToken = <Refresh Token>
```

### Step 3: Invoke the connector operation
Now, utilize the available connector operations. A sample use case is shown below.

#### Create a New Discount
```ballerina
SimplePublicObjectInputForCreate payload = {
associations: [],
objectWriteTraceId: "1234",
properties: {
"hs_label": "test_discount",
"hs_duration": "ONCE",
"hs_type": "PERCENT",
"hs_value": "40",
"hs_sort_order": "2"
}
};

SimplePublicObject createResponse = check hubspotClient->/.post(payload, {});
```

#### List all discounts
```ballerina
GetCrmV3ObjectsDiscountsQueries params = {
'limit: 10,
archived: false,
properties: ["hs_label", "hs_value", "hs_type"]
};

CollectionResponseSimplePublicObjectWithAssociationsForwardPaging response = check hubspotClient->/.get({}, params);
```

## Examples
The HubSpot CRM Commerce Discounts connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/ballerina-platform/module-ballerinax-hubspot.crm.commerce.discounts/tree/main/examples/), covering the following use cases:

The `HubSpot CRM Commerce Discounts` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/module-ballerinax-hubspot.crm.commerce.discounts/tree/main/examples/), covering the following use cases:
1. [Discount Manager](https://github.com/ballerina-platform/module-ballerinax-hubspot.crm.commerce.discounts/tree/main/examples/discount_manager) - see how the Hubspot API can be used to create discount and manage it through endpoints.
2. [Festival Discounts](https://github.com/ballerina-platform/module-ballerinax-hubspot.crm.commerce.discounts/tree/main/examples/festival_discounts) - see how the Hubspot API can be used to create and to manage multiple discounts at a time.

[//]: # (TODO: Add examples)

## Build from the source

Expand Down
6 changes: 3 additions & 3 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ name = "hubspot.crm.commerce.discounts"
version = "1.0.0"
license = ["Apache-2.0"]
authors = ["Ballerina"]
keywords = []
# icon = "icon.png" # TODO: update icon.png
keywords = ["discounts", "hubspot", "CRM", "commerce"]
icon = "icon.png"
repository = "https://github.com/ballerina-platform/module-ballerinax-hubspot.crm.commerce.discounts"

[build-options]
observabilityIncluded = true

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