Skip to content

Commit

Permalink
Build the examples
Browse files Browse the repository at this point in the history
  • Loading branch information
nipunayf committed Aug 11, 2023
1 parent 35743b9 commit 3dff45a
Show file tree
Hide file tree
Showing 40 changed files with 181 additions and 100 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ Execute the following commands to build from the source:

- To build the package:
```
bal pack ./teams
bal build ./ballerina
```
- To run tests after build:
```
bal test ./teams
bal test ./ballerina
```
## Contributing to ballerina

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion teams/Module.md → ballerina/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ if (newTeamId is string) {

2. Use `bal run` command to compile and run the Ballerina program

**[You can find a list of samples here](https://github.com/ballerina-platform/module-ballerinax-microsoft.teams/tree/main/teams/samples)**
**[You can find a list of samples here](https://github.com/ballerina-platform/module-ballerinax-microsoft.teams/tree/main/examples)**
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 34 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Examples

This directory contains a collection of sample code examples written in Ballerina. These examples demonstrate various
use cases of the module. You can follow the instructions below to build and run these examples.

## Running an Example

Execute the following commands to build an example from the source.

* To build an example

`bal build <example-name>`


* To run an example

`bal run <example-name>`

## Building the Examples with the Local Module

**Warning**: Because of the absence of support for reading local repositories for single Ballerina files, the bala of
the module is manually written to the central repository as a workaround. Consequently, the bash script may modify your
local Ballerina repositories.

Execute the following commands to build all the examples against the changes you have made to the module locally.

* To build all the examples

`./build.sh build`


* To run all the examples

`./build.sh run`
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public function main() returns error? {
teams:ConnectionConfig configuration = {
auth: {
refreshUrl: refreshUrl,
refreshToken : refreshToken,
clientId : clientId,
clientSecret : clientSecret
refreshToken: refreshToken,
clientId: clientId,
clientSecret: clientSecret
}
};
teams:Client teamsClient = check new(configuration);
teams:Client teamsClient = check new (configuration);

// This operation is allowed only for channels with a membershipType value of private
log:printInfo("Add member to channel");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public function main() returns error? {
teams:ConnectionConfig configuration = {
auth: {
refreshUrl: refreshUrl,
refreshToken : refreshToken,
clientId : clientId,
clientSecret : clientSecret
refreshToken: refreshToken,
clientId: clientId,
clientSecret: clientSecret
}
};
teams:Client teamsClient = check new(configuration);
teams:Client teamsClient = check new (configuration);

log:printInfo("Add member to chat");
string owner = "<OWNER_ID>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public function main() returns error? {
teams:ConnectionConfig configuration = {
auth: {
refreshUrl: refreshUrl,
refreshToken : refreshToken,
clientId : clientId,
clientSecret : clientSecret
refreshToken: refreshToken,
clientId: clientId,
clientSecret: clientSecret
}
};
teams:Client teamsClient = check new(configuration);
teams:Client teamsClient = check new (configuration);

log:printInfo("Add member to team");
string teamId = "<TEAM_ID>";
Expand All @@ -41,7 +41,7 @@ public function main() returns error? {
userId: userId
};

teams:MemberData|error memberInfo = teamsClient-> addMemberToTeam(teamId, data);
teams:MemberData|error memberInfo = teamsClient->addMemberToTeam(teamId, data);
if (memberInfo is teams:MemberData) {
log:printInfo("Member Added to the team " + memberInfo?.id.toString());
log:printInfo("Success!");
Expand Down
47 changes: 47 additions & 0 deletions examples/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

BAL_EXAMPLES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BAL_CENTRAL_DIR="$HOME/.ballerina/repositories/central.ballerina.io/"
BAL_HOME_DIR="$BAL_EXAMPLES_DIR/../ballerina"

set -e

case "$1" in
build)
BAL_CMD="build"
;;
run)
BAL_CMD="run"
;;
*)
echo "Invalid command provided: '$1'. Please provide 'build' or 'test' as the command."
exit 1
;;
esac

# Read Ballerina package name
BAL_PACKAGE_NAME=$(awk -F'"' '/^name/ {print $2}' "$BAL_HOME_DIR/Ballerina.toml")

# Push the package to the local repository
cd "$BAL_HOME_DIR" &&
bal pack &&
bal push --repository=local

# Remove the cache directories in the repositories
cacheDirs=($(ls -d "$BAL_CENTRAL_DIR"/cache-* 2>/dev/null))
for dir in "${cacheDirs[@]}"; do
[ -d "$dir" ] && rm -r "$dir"
done
echo "Successfully cleaned the cache directories"

# Update the central repository
BAL_DESTINATION_DIR="$HOME/.ballerina/repositories/central.ballerina.io/bala/ballerinax/$BAL_PACKAGE_NAME"
BAL_SOURCE_DIR="$HOME/.ballerina/repositories/local/bala/ballerinax/$BAL_PACKAGE_NAME"
[ -d "$BAL_DESTINATION_DIR" ] && rm -r "$BAL_DESTINATION_DIR"
[ -d "$BAL_SOURCE_DIR" ] && cp -r "$BAL_SOURCE_DIR" "$BAL_DESTINATION_DIR"
echo "Successfully updated the local central repositories"

# Loop through examples in the examples directory
find "$BAL_EXAMPLES_DIR" -type f -name "*.bal" | while read -r BAL_EXAMPLE_FILE; do
bal "$BAL_CMD" --offline "$BAL_EXAMPLE_FILE"
done
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public function main() returns error? {
teams:ConnectionConfig configuration = {
auth: {
refreshUrl: refreshUrl,
refreshToken : refreshToken,
clientId : clientId,
clientSecret : clientSecret
refreshToken: refreshToken,
clientId: clientId,
clientSecret: clientSecret
}
};
teams:Client teamsClient = check new(configuration);
teams:Client teamsClient = check new (configuration);

log:printInfo("Create channel");
string teamId = "<TEAM_ID>";
Expand Down
8 changes: 4 additions & 4 deletions teams/samples/create_chat.bal → examples/create_chat.bal
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public function main() returns error? {
teams:ConnectionConfig configuration = {
auth: {
refreshUrl: refreshUrl,
refreshToken : refreshToken,
clientId : clientId,
clientSecret : clientSecret
refreshToken: refreshToken,
clientId: clientId,
clientSecret: clientSecret
}
};
teams:Client teamsClient = check new(configuration);
teams:Client teamsClient = check new (configuration);

log:printInfo("Create chat");
string owner1 = "<OWNER1_ID>";
Expand Down
8 changes: 4 additions & 4 deletions teams/samples/create_team.bal → examples/create_team.bal
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public function main() returns error? {
teams:ConnectionConfig configuration = {
auth: {
refreshUrl: refreshUrl,
refreshToken : refreshToken,
clientId : clientId,
clientSecret : clientSecret
refreshToken: refreshToken,
clientId: clientId,
clientSecret: clientSecret
}
};
teams:Client teamsClient = check new(configuration);
teams:Client teamsClient = check new (configuration);

log:printInfo("Create team");
teams:Team info = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public function main() returns error? {
teams:ConnectionConfig configuration = {
auth: {
refreshUrl: refreshUrl,
refreshToken : refreshToken,
clientId : clientId,
clientSecret : clientSecret
refreshToken: refreshToken,
clientId: clientId,
clientSecret: clientSecret
}
};
teams:Client teamsClient = check new(configuration);
teams:Client teamsClient = check new (configuration);

log:printInfo("Delete channel"); //////////test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ public function main() returns error? {
teams:ConnectionConfig configuration = {
auth: {
refreshUrl: refreshUrl,
refreshToken : refreshToken,
clientId : clientId,
clientSecret : clientSecret
refreshToken: refreshToken,
clientId: clientId,
clientSecret: clientSecret
}
};
teams:Client teamsClient = check new(configuration);
teams:Client teamsClient = check new (configuration);

log:printInfo("Delete channel member"); //////////test

string teamId = "<TEAM_ID>";
string channelId = "<CHANNEL_ID>";
string membershipId = "<MEMBERSHIP_ID>";
error? channelInfo = teamsClient->deleteChannelMember(teamId, channelId, membershipId);

error? channelInfo = teamsClient->deleteChannelMember(teamId, channelId, membershipId);
if (channelInfo is ()) {
log:printInfo("CSucessfully deleted");
log:printInfo("Success!");
Expand Down
8 changes: 4 additions & 4 deletions teams/samples/delete_team.bal → examples/delete_team.bal
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public function main() returns error? {
teams:ConnectionConfig configuration = {
auth: {
refreshUrl: refreshUrl,
refreshToken : refreshToken,
clientId : clientId,
clientSecret : clientSecret
refreshToken: refreshToken,
clientId: clientId,
clientSecret: clientSecret
}
};
teams:Client teamsClient = check new(configuration);
teams:Client teamsClient = check new (configuration);

log:printInfo("Delete team"); //////////test

Expand Down
8 changes: 4 additions & 4 deletions teams/samples/get_channel.bal → examples/get_channel.bal
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public function main() returns error? {
teams:ConnectionConfig configuration = {
auth: {
refreshUrl: refreshUrl,
refreshToken : refreshToken,
clientId : clientId,
clientSecret : clientSecret
refreshToken: refreshToken,
clientId: clientId,
clientSecret: clientSecret
}
};
teams:Client teamsClient = check new(configuration);
teams:Client teamsClient = check new (configuration);

log:printInfo("Get channel info");
string teamId = "<TEAM_ID>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public function main() returns error? {
teams:ConnectionConfig configuration = {
auth: {
refreshUrl: refreshUrl,
refreshToken : refreshToken,
clientId : clientId,
clientSecret : clientSecret
refreshToken: refreshToken,
clientId: clientId,
clientSecret: clientSecret
}
};
teams:Client teamsClient = check new(configuration);
teams:Client teamsClient = check new (configuration);

log:printInfo("Get channels in team");
string teamId = "<TEAM_ID>";
Expand Down
8 changes: 4 additions & 4 deletions teams/samples/get_chat.bal → examples/get_chat.bal
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public function main() returns error? {
teams:ConnectionConfig configuration = {
auth: {
refreshUrl: refreshUrl,
refreshToken : refreshToken,
clientId : clientId,
clientSecret : clientSecret
refreshToken: refreshToken,
clientId: clientId,
clientSecret: clientSecret
}
};
teams:Client teamsClient = check new(configuration);
teams:Client teamsClient = check new (configuration);

log:printInfo("Get chat info");
string chatId = "<CHAT_ID>";
Expand Down
10 changes: 5 additions & 5 deletions teams/samples/get_team.bal → examples/get_team.bal
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ public function main() returns error? {
teams:ConnectionConfig configuration = {
auth: {
refreshUrl: refreshUrl,
refreshToken : refreshToken,
clientId : clientId,
clientSecret : clientSecret
refreshToken: refreshToken,
clientId: clientId,
clientSecret: clientSecret
}
};
teams:Client teamsClient = check new(configuration);
teams:Client teamsClient = check new (configuration);

log:printInfo("Get team information");
string teamId = "<TEAM_ID>";

teams:TeamData|error teamInfo = teamsClient->getTeam(teamId);
teams:TeamData|error teamInfo = teamsClient->getTeam(teamId);
if (teamInfo is teams:TeamData) {
log:printInfo("Team info " + teamInfo.toString());
log:printInfo("Success!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ public function main() returns error? {
teams:ConnectionConfig configuration = {
auth: {
refreshUrl: refreshUrl,
refreshToken : refreshToken,
clientId : clientId,
clientSecret : clientSecret
refreshToken: refreshToken,
clientId: clientId,
clientSecret: clientSecret
}
};
teams:Client teamsClient = check new(configuration);
teams:Client teamsClient = check new (configuration);

log:printInfo("List channel members");
string teamId = "<TEAM_ID>";
string channelId = "<CHANNEL_ID>";

teams:MemberData[]|error memberInfo = teamsClient->listChannelMembers(teamId, channelId);
if (memberInfo is teams:MemberData[]) {
if (memberInfo is teams:MemberData[]) {
log:printInfo("Member List" + memberInfo.toString());
log:printInfo("Success!");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ public function main() returns error? {
teams:ConnectionConfig configuration = {
auth: {
refreshUrl: refreshUrl,
refreshToken : refreshToken,
clientId : clientId,
clientSecret : clientSecret
refreshToken: refreshToken,
clientId: clientId,
clientSecret: clientSecret
}
};
teams:Client teamsClient = check new(configuration);
teams:Client teamsClient = check new (configuration);

log:printInfo("List chat members");
string chatId = "<CHAT_ID>";

teams:MemberData[]|error chatMember = teamsClient->listChatMembers(chatId);
if (chatMember is teams:MemberData[]) {
if (chatMember is teams:MemberData[]) {
log:printInfo("Member List" + chatMember.toString());
log:printInfo("Success!");
} else {
Expand Down
Loading

0 comments on commit 3dff45a

Please sign in to comment.