From 53d8e65587845e3d9f0b25a57b5cfbbd0d958f46 Mon Sep 17 00:00:00 2001 From: roshanemoraes Date: Fri, 17 Jan 2025 14:10:20 +0530 Subject: [PATCH] Fix Changes --- examples/batch-operations/Dependencies.toml | 1 + examples/order-management/Dependencies.toml | 5 ++ examples/order-management/main.bal | 52 ++++++++++----------- examples/search-operation/Dependencies.toml | 1 + examples/search-operation/main.bal | 2 +- 5 files changed, 34 insertions(+), 27 deletions(-) diff --git a/examples/batch-operations/Dependencies.toml b/examples/batch-operations/Dependencies.toml index 8523bec..f4baec6 100644 --- a/examples/batch-operations/Dependencies.toml +++ b/examples/batch-operations/Dependencies.toml @@ -312,3 +312,4 @@ dependencies = [ modules = [ {org = "wso2", packageName = "batch_operations", moduleName = "batch_operations"} ] + diff --git a/examples/order-management/Dependencies.toml b/examples/order-management/Dependencies.toml index 4150669..191592c 100644 --- a/examples/order-management/Dependencies.toml +++ b/examples/order-management/Dependencies.toml @@ -206,6 +206,9 @@ dependencies = [ {org = "ballerina", name = "lang.value"}, {org = "ballerina", name = "observe"} ] +modules = [ + {org = "ballerina", packageName = "log", moduleName = "log"} +] [[package]] org = "ballerina" @@ -310,6 +313,7 @@ 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"} @@ -317,3 +321,4 @@ dependencies = [ modules = [ {org = "wso2", packageName = "order_management", moduleName = "order_management"} ] + diff --git a/examples/order-management/main.bal b/examples/order-management/main.bal index 7ab99f1..cd12984 100644 --- a/examples/order-management/main.bal +++ b/examples/order-management/main.bal @@ -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; // Configuration for HubSpot API client credentials configurable string clientId = ?; @@ -26,7 +27,7 @@ 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, @@ -34,20 +35,19 @@ public function main() returns error? { 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."); @@ -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: [ { @@ -72,7 +72,6 @@ function createOrder(orders:Client hubspotClient) returns string|error? { ] } ], - objectWriteTraceId: null, properties: { "hs_order_name": "Camping supplies", "hs_currency_code": "USD", @@ -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 { @@ -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); } } + diff --git a/examples/search-operation/Dependencies.toml b/examples/search-operation/Dependencies.toml index fda4e80..2242752 100644 --- a/examples/search-operation/Dependencies.toml +++ b/examples/search-operation/Dependencies.toml @@ -312,3 +312,4 @@ dependencies = [ modules = [ {org = "wso2", packageName = "search_operation", moduleName = "search_operation"} ] + diff --git a/examples/search-operation/main.bal b/examples/search-operation/main.bal index 1bd2b9f..7c45a20 100644 --- a/examples/search-operation/main.bal +++ b/examples/search-operation/main.bal @@ -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: [ {