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

Fix live tests and mock tests #4

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions examples/batch-operations/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,4 @@ dependencies = [
modules = [
{org = "wso2", packageName = "batch_operations", moduleName = "batch_operations"}
]

5 changes: 5 additions & 0 deletions examples/order-management/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ dependencies = [
{org = "ballerina", name = "lang.value"},
{org = "ballerina", name = "observe"}
]
modules = [
{org = "ballerina", packageName = "log", moduleName = "log"}
]

[[package]]
org = "ballerina"
Expand Down Expand Up @@ -310,10 +313,12 @@ version = "0.1.0"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "io"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "oauth2"},
{org = "ballerinai", name = "observe"},
{org = "ballerinax", name = "hubspot.crm.commerce.orders"}
]
modules = [
{org = "wso2", packageName = "order_management", moduleName = "order_management"}
]

52 changes: 26 additions & 26 deletions examples/order-management/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

import ballerina/http;
import ballerina/io;
import ballerina/log;
import ballerina/oauth2;
import ballerinax/hubspot.crm.commerce.orders as orders;
import ballerinax/hubspot.crm.commerce.orders as hsOrders;
Copy link
Member

Choose a reason for hiding this comment

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

Let's not use camel case in package qualifiers. (Package qualifiers are treated differently than the variables, since they kind of act like a namespace).

Suggested change
import ballerinax/hubspot.crm.commerce.orders as hsOrders;
import ballerinax/hubspot.crm.commerce.orders as hsorders;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


// Configuration for HubSpot API client credentials
configurable string clientId = ?;
Expand All @@ -26,28 +27,27 @@ configurable string refreshToken = ?;

public function main() returns error? {
// Initialize the HubSpot client with the given configuration
orders:ConnectionConfig config = {
hsOrders:ConnectionConfig config = {
auth: {
clientId,
clientSecret,
refreshToken,
credentialBearer: oauth2:POST_BODY_BEARER
}
};
final orders:Client hubspotClient = check new orders:Client(
config, serviceUrl = "https://api.hubapi.com/crm/v3/objects");
io:println("HubSpot Client initialized successfully.");
check handleOrderManagement(hubspotClient);
final hsOrders:Client hubspotClient = check new hsOrders:Client(config);
log:printInfo("HubSpot Client initialized successfully.");
handleOrderManagement(hubspotClient);
}

function handleOrderManagement(orders:Client hubspotClient) returns error? {
function handleOrderManagement(hsOrders:Client hubspotClient) {
io:println("Starting Order Management...");
string|error? newOrderId = "";
string|error newOrderId = "";
newOrderId = createOrder(hubspotClient);
if newOrderId is string {
check readOrder(hubspotClient, newOrderId);
check updateOrder(hubspotClient, newOrderId);
check deleteOrder(hubspotClient, newOrderId);
readOrder(hubspotClient, newOrderId);
updateOrder(hubspotClient, newOrderId);
deleteOrder(hubspotClient, newOrderId);
} else {
io:println("Failed to create order.");
io:println("Order Management Exited With Error.");
Expand All @@ -56,8 +56,8 @@ function handleOrderManagement(orders:Client hubspotClient) returns error? {
}

// Create a new order
function createOrder(orders:Client hubspotClient) returns string|error? {
orders:SimplePublicObjectInputForCreate newOrder =
function createOrder(hsOrders:Client hubspotClient) returns string|error {
hsOrders:SimplePublicObjectInputForCreate newOrder =
{
associations: [
{
Expand All @@ -72,7 +72,6 @@ function createOrder(orders:Client hubspotClient) returns string|error? {
]
}
],
objectWriteTraceId: null,
properties: {
"hs_order_name": "Camping supplies",
"hs_currency_code": "USD",
Expand All @@ -83,8 +82,8 @@ function createOrder(orders:Client hubspotClient) returns string|error? {
"hs_shipping_address_street": "123 Fake Street"
}
};
orders:SimplePublicObject|error response = hubspotClient->/orders.post(newOrder);
if response is orders:SimplePublicObject {
hsOrders:SimplePublicObject|error response = hubspotClient->/orders.post(newOrder);
if response is hsOrders:SimplePublicObject {
io:println("Order created successfully with ID: ", response.id);
return response.id;
} else {
Expand All @@ -93,34 +92,35 @@ function createOrder(orders:Client hubspotClient) returns string|error? {
}
}

function readOrder(orders:Client hubspotClient, string orderId) returns error? {
function readOrder(hsOrders:Client hubspotClient, string orderId) {
var response = hubspotClient->/orders/[orderId];
if response is orders:SimplePublicObjectWithAssociations {
if response is hsOrders:SimplePublicObjectWithAssociations {
io:println("Order details retrieved: ", response);
} else {
io:println("Failed to retrieve order with ID: ", orderId);
}
}

function updateOrder(orders:Client hubspotClient, string orderId) returns error? {
orders:SimplePublicObjectInput updateDetails = {
function updateOrder(hsOrders:Client hubspotClient, string orderId) {
hsOrders:SimplePublicObjectInput updateDetails = {
properties: {
"hs_fulfillment_status": "Shipped"
}
};
var response = hubspotClient->/orders/[orderId].patch(updateDetails);
if response is orders:SimplePublicObject {
io:println("Order updated successfully with ID: ", response.id);
if response is hsOrders:SimplePublicObject {
log:printInfo("Order updated successfully with ID: "+ response.id);
} else {
io:println("Failed to update order with ID: ", orderId);
log:printError("Failed to update order with ID: "+ orderId);
}
}

function deleteOrder(orders:Client hubspotClient, string orderId) returns error? {
var response = hubspotClient->/orders/[orderId].delete();
function deleteOrder(hsOrders:Client hubspotClient, string orderId){
http:Response|error response = hubspotClient->/orders/[orderId].delete();
if response is http:Response {
io:println("Order deleted successfully with status: ", response.statusCode);
} else {
io:println("Failed to delete order with ID: ", orderId);
log:printError("Failed to delete order with ID: " + orderId);
}
}

1 change: 1 addition & 0 deletions examples/search-operation/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,4 @@ dependencies = [
modules = [
{org = "wso2", packageName = "search_operation", moduleName = "search_operation"}
]

2 changes: 1 addition & 1 deletion examples/search-operation/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function handleSearchOperations(orders:Client hubspotClient) returns error? {
// Function to search for orders based on specific criteria
function searchOrders(orders:Client hubspotClient) returns error? {
orders:PublicObjectSearchRequest searchRequest = {
query: "example",
query: "apple",
properties: ["hs_order_name", "hs_currency_code"],
filterGroups: [
{
Expand Down
Loading