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: refactor client initialization for leads to improve readability … #5

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
6 changes: 3 additions & 3 deletions examples/fitness_center_leads/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ configurable string refreshToken = ?;
// Client initialization
final leads:Client hsLeads = check new ({
auth: {
clientId: clientId,
clientSecret: clientSecret,
refreshToken: refreshToken,
clientId,
clientSecret,
refreshToken,
credentialBearer: oauth2:POST_BODY_BEARER
}
});
Expand Down
63 changes: 30 additions & 33 deletions examples/real_estate_inquiry_leads/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,37 @@ configurable string clientSecret = ?;
configurable string refreshToken = ?;

// Client initialization
final leads:Client hsLeads = check initClient();

function initClient() returns leads:Client|error {
leads:OAuth2RefreshTokenGrantConfig auth = {
clientId: clientId,
clientSecret: clientSecret,
refreshToken: refreshToken,
final leads:Client hsLeads = check new ({
auth: {
clientId,
clientSecret,
refreshToken,
credentialBearer: oauth2:POST_BODY_BEARER
};
return new ({auth});
}
});

public function main() returns error? {
string contactId = "85187963930";

// Create new lead
leads:SimplePublicObject createdLead = check createLeadWithContact("John Doe", contactId);
io:println("Lead created with id: ", createdLead.id);

// Update lead
leads:SimplePublicObject updatedLead = check updateLeadName(createdLead.id, "Jane Doe");
io:println("Lead updated with name: ", updatedLead.properties["hs_lead_name"]);

// Get lead details
leads:SimplePublicObjectWithAssociations leadDetails = check getLeadById(createdLead.id);
io:println("Lead retrieved: ", leadDetails);

// Get all leads
leads:CollectionResponseSimplePublicObjectWithAssociationsForwardPaging allLeads = check getAllLeads();
io:println("Total leads: ", allLeads.results.length());

// Delete the created lead
http:Response deleteResponse = check deleteLead(createdLead.id);
io:println("Lead deleted successfully: ", deleteResponse.statusCode);
}

function createLeadWithContact(string leadName, string contactId) returns leads:SimplePublicObject|error {
Expand Down Expand Up @@ -82,27 +103,3 @@ function getAllLeads(boolean archived = false) returns leads:CollectionResponseS
function deleteLead(string leadId) returns http:Response|error {
return hsLeads->/[leadId].delete();
}

public function main() returns error? {
string contactId = "85187963930";

// Create new lead
leads:SimplePublicObject createdLead = check createLeadWithContact("John Doe", contactId);
io:println("Lead created with id: ", createdLead.id);

// Update lead
leads:SimplePublicObject updatedLead = check updateLeadName(createdLead.id, "Jane Doe");
io:println("Lead updated with name: ", updatedLead.properties["hs_lead_name"]);

// Get lead details
leads:SimplePublicObjectWithAssociations leadDetails = check getLeadById(createdLead.id);
io:println("Lead retrieved: ", leadDetails);

// Get all leads
leads:CollectionResponseSimplePublicObjectWithAssociationsForwardPaging allLeads = check getAllLeads();
io:println("Total leads: ", allLeads.results.length());

// Delete the created lead
http:Response deleteResponse = check deleteLead(createdLead.id);
io:println("Lead deleted successfully: ", deleteResponse.statusCode);
}
Loading