├── ballerina ├── icon.png ├── Ballerina.toml ├── constants.bal ├── Package.md ├── Module.md ├── utils.bal ├── types.bal ├── tests │ └── test.bal └── endpoint.bal ├── .github ├── CODEOWNERS └── workflows │ ├── test-fail-notification.yaml │ ├── release.yml │ ├── build-with-bal-test-native.yml │ ├── pull-request.yml │ ├── dev-stg-release.yml │ ├── daily-build.yml │ └── ci.yml ├── issue_template.md ├── .gitignore ├── examples ├── README.md ├── getPage.bal ├── listPages.bal ├── getSection.bal ├── listNotebooks.bal ├── createNotebook.bal ├── getNotebook.bal ├── listSections.bal ├── createPage.bal ├── createSection.bal ├── getRecentNotebooks.bal ├── getSectionGroup.bal ├── listSectionGroups.bal ├── createSectionGroup.bal ├── createSectionInSectionGroup.bal ├── createPageWithHTML.bal ├── deletePage.bal └── build.sh ├── pull_request_template.md ├── README.md └── LICENSE /ballerina/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-microsoft.onenote/HEAD/ballerina/icon.png -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Lines starting with '#' are comments. 2 | # Each line is a file pattern followed by one or more owners. 3 | 4 | # See: https://help.github.com/articles/about-codeowners/ 5 | 6 | # These owners will be the default owners for everything in the repo. 7 | * @NipunaRanasinghe @shafreenAnfar 8 | -------------------------------------------------------------------------------- /ballerina/Ballerina.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | distribution = "2201.3.0" 3 | org= "ballerinax" 4 | name= "microsoft.onenote" 5 | version= "2.3.0" 6 | authors = ["Ballerina"] 7 | keywords = ["Content & Files/Notes", "Cost/Freemium", "Vendor/Microsoft"] 8 | icon = "icon.png" 9 | repository = "https://github.com/ballerina-platform/module-ballerinax-microsoft.onenote" 10 | license = ["Apache-2.0"] 11 | 12 | [build-options] 13 | observability-included=true 14 | -------------------------------------------------------------------------------- /.github/workflows/test-fail-notification.yaml: -------------------------------------------------------------------------------- 1 | 2 | name: Test Fail Notification 3 | 4 | on: [workflow_dispatch] 5 | 6 | jobs: 7 | build: 8 | runs-on: ubuntu-latest 9 | steps: 10 | # Send failure notification 11 | - name: Notify failure 12 | run: | 13 | curl -X POST \ 14 | https://api.github.com/repos/ballerina-platform/ballerina-release/dispatches \ 15 | -H 'Accept: application/vnd.github.v3+json' \ 16 | -H 'Authorization: Bearer ${{ secrets.BALLERINA_BOT_TOKEN }}' \ 17 | --data "{ 18 | \"event_type\": \"notify-connector-failure\", 19 | \"client_payload\": { 20 | \"repoName\": \"module-ballerinax-microsoft.onenote\" 21 | } 22 | }" 23 | -------------------------------------------------------------------------------- /issue_template.md: -------------------------------------------------------------------------------- 1 | **Description:** 2 | 3 | 4 | **Suggested Labels:** 5 | 6 | 7 | **Suggested Assignees:** 8 | 9 | 10 | **Affected Product Version:** 11 | 12 | **OS, DB, other environment details and versions:** 13 | 14 | **Steps to reproduce:** 15 | 16 | 17 | **Related Issues:** 18 | 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | # Ballerina configuartion file 26 | *.conf 27 | Config.toml 28 | 29 | # Target folder of ballerina project 30 | onenote/target 31 | 32 | # json files created inside resources folder 33 | /modules 34 | 35 | # resource folder in tests folder 36 | /tests/resources 37 | 38 | # resources folder 39 | onenote/resources/*.json 40 | onenote/modules 41 | 42 | # idea files 43 | *.idea 44 | 45 | # .ballerina files 46 | *.ballerina 47 | 48 | # .DS_Store files 49 | *.DS_Store 50 | 51 | # Ignore Gradle project-specific cache directory 52 | .gradle 53 | 54 | # Ignore Gradle build output directory 55 | build -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | 3 | This directory contains a collection of sample code examples written in Ballerina. These examples demonstrate various 4 | use cases of the module. You can follow the instructions below to build and run these examples. 5 | 6 | ## Running an Example 7 | 8 | Execute the following commands to build an example from the source. 9 | 10 | * To build an example 11 | 12 | `bal build ` 13 | 14 | 15 | * To run an example 16 | 17 | `bal run ` 18 | 19 | ## Building the Examples with the Local Module 20 | 21 | **Warning**: Because of the absence of support for reading local repositories for single Ballerina files, the bala of 22 | the module is manually written to the central repository as a workaround. Consequently, the bash script may modify your 23 | local Ballerina repositories. 24 | 25 | Execute the following commands to build all the examples against the changes you have made to the module locally. 26 | 27 | * To build all the examples 28 | 29 | `./build.sh build` 30 | 31 | 32 | * To run all the examples 33 | 34 | `./build.sh run` -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Deployment 2 | 3 | on: 4 | release: 5 | types: [ published ] 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v2 12 | 13 | # Setup Ballerina Environment 14 | - name: Set Up Ballerina 15 | uses: ballerina-platform/setup-ballerina@v1.1.0 16 | with: 17 | version: 2201.2.1 18 | 19 | # Build Ballerina Project 20 | - name: Ballerina Build 21 | run: bal pack ./ballerina 22 | env: 23 | JAVA_HOME: /usr/lib/jvm/default-jvm 24 | 25 | # Build Module Examples 26 | - name: Ballerina Examples Build 27 | run: chmod +x ./examples/build.sh && ./examples/build.sh build 28 | env: 29 | JAVA_HOME: /usr/lib/jvm/default-jvm 30 | 31 | # Push to Ballerina Central 32 | - name: Ballerina Push 33 | run: bal push 34 | working-directory: ./ballerina 35 | env: 36 | BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_DEV_ACCESS_TOKEN }} 37 | JAVA_HOME: /usr/lib/jvm/default-jvm 38 | -------------------------------------------------------------------------------- /examples/getPage.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerinax/microsoft.onenote; 18 | 19 | onenote:ConnectionConfig configuration = { 20 | auth: { 21 | clientId: "clientId", 22 | clientSecret: "clientSecret", 23 | refreshToken: "refreshToken", 24 | refreshUrl: "refreshUrl" 25 | } 26 | }; 27 | 28 | public function main() returns error? { 29 | onenote:Client oneNoteClient = check new (configuration); 30 | onenote:Page page = check oneNoteClient->getPage("pageId"); 31 | } 32 | -------------------------------------------------------------------------------- /examples/listPages.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerinax/microsoft.onenote; 18 | 19 | onenote:ConnectionConfig configuration = { 20 | auth: { 21 | clientId: "clientId", 22 | clientSecret: "clientSecret", 23 | refreshToken: "refreshToken", 24 | refreshUrl: "refreshUrl" 25 | } 26 | }; 27 | 28 | public function main() returns error? { 29 | onenote:Client oneNoteClient = check new (configuration); 30 | onenote:Page[] pages = check oneNoteClient->listPages("sectionId"); 31 | } 32 | -------------------------------------------------------------------------------- /examples/getSection.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerinax/microsoft.onenote; 18 | 19 | onenote:ConnectionConfig configuration = { 20 | auth: { 21 | clientId: "clientId", 22 | clientSecret: "clientSecret", 23 | refreshToken: "refreshToken", 24 | refreshUrl: "refreshUrl" 25 | } 26 | }; 27 | 28 | public function main() returns error? { 29 | onenote:Client oneNoteClient = check new (configuration); 30 | onenote:Section section = check oneNoteClient->getSection("sectionId"); 31 | } 32 | -------------------------------------------------------------------------------- /examples/listNotebooks.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerinax/microsoft.onenote; 18 | 19 | onenote:ConnectionConfig configuration = { 20 | auth: { 21 | clientId: "clientId", 22 | clientSecret: "clientSecret", 23 | refreshToken: "refreshToken", 24 | refreshUrl: "refreshUrl" 25 | } 26 | }; 27 | 28 | public function main() returns error? { 29 | onenote:Client oneNoteClient = check new (configuration); 30 | onenote:Notebook[] notebooks = check oneNoteClient->listNotebooks(); 31 | } 32 | -------------------------------------------------------------------------------- /examples/createNotebook.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerinax/microsoft.onenote; 18 | 19 | onenote:ConnectionConfig configuration = { 20 | auth: { 21 | clientId: "clientId", 22 | clientSecret: "clientSecret", 23 | refreshToken: "refreshToken", 24 | refreshUrl: "refreshUrl" 25 | } 26 | }; 27 | 28 | public function main() returns error? { 29 | onenote:Client oneNoteClient = check new (configuration); 30 | onenote:Notebook notebook = check oneNoteClient->createNotebook("test"); 31 | } 32 | -------------------------------------------------------------------------------- /examples/getNotebook.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerinax/microsoft.onenote; 18 | 19 | onenote:ConnectionConfig configuration = { 20 | auth: { 21 | clientId: "clientId", 22 | clientSecret: "clientSecret", 23 | refreshToken: "refreshToken", 24 | refreshUrl: "refreshUrl" 25 | } 26 | }; 27 | 28 | public function main() returns error? { 29 | onenote:Client oneNoteClient = check new (configuration); 30 | onenote:Notebook notebook = check oneNoteClient->getNotebook("notebookId"); 31 | } 32 | -------------------------------------------------------------------------------- /examples/listSections.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerinax/microsoft.onenote; 18 | 19 | onenote:ConnectionConfig configuration = { 20 | auth: { 21 | clientId: "clientId", 22 | clientSecret: "clientSecret", 23 | refreshToken: "refreshToken", 24 | refreshUrl: "refreshUrl" 25 | } 26 | }; 27 | 28 | public function main() returns error? { 29 | onenote:Client oneNoteClient = check new (configuration); 30 | onenote:Section[] sections = check oneNoteClient->listSections("notebookId"); 31 | } 32 | -------------------------------------------------------------------------------- /examples/createPage.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerinax/microsoft.onenote; 18 | 19 | onenote:ConnectionConfig configuration = { 20 | auth: { 21 | clientId: "clientId", 22 | clientSecret: "clientSecret", 23 | refreshToken: "refreshToken", 24 | refreshUrl: "refreshUrl" 25 | } 26 | }; 27 | 28 | public function main() returns error? { 29 | onenote:Client oneNoteClient = check new (configuration); 30 | onenote:Page page = check oneNoteClient->createPage("sectionId", "title", "Hello"); 31 | } 32 | -------------------------------------------------------------------------------- /examples/createSection.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerinax/microsoft.onenote; 18 | 19 | onenote:ConnectionConfig configuration = { 20 | auth: { 21 | clientId: "clientId", 22 | clientSecret: "clientSecret", 23 | refreshToken: "refreshToken", 24 | refreshUrl: "refreshUrl" 25 | } 26 | }; 27 | 28 | public function main() returns error? { 29 | onenote:Client oneNoteClient = check new (configuration); 30 | onenote:Section section = check oneNoteClient->createSection("notebookId", "testSection"); 31 | } 32 | -------------------------------------------------------------------------------- /examples/getRecentNotebooks.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerinax/microsoft.onenote; 18 | 19 | onenote:ConnectionConfig configuration = { 20 | auth: { 21 | clientId: "clientId", 22 | clientSecret: "clientSecret", 23 | refreshToken: "refreshToken", 24 | refreshUrl: "refreshUrl" 25 | } 26 | }; 27 | 28 | public function main() returns error? { 29 | onenote:Client oneNoteClient = check new (configuration); 30 | onenote:RecentNotebook[] recentNotebooks = check oneNoteClient->getRecentNotebooks(); 31 | } 32 | -------------------------------------------------------------------------------- /examples/getSectionGroup.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerinax/microsoft.onenote; 18 | 19 | onenote:ConnectionConfig configuration = { 20 | auth: { 21 | clientId: "clientId", 22 | clientSecret: "clientSecret", 23 | refreshToken: "refreshToken", 24 | refreshUrl: "refreshUrl" 25 | } 26 | }; 27 | 28 | public function main() returns error? { 29 | onenote:Client oneNoteClient = check new (configuration); 30 | onenote:SectionGroup sectionGroup = check oneNoteClient->getSectionGroup("sectionGroupId"); 31 | } 32 | -------------------------------------------------------------------------------- /examples/listSectionGroups.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerinax/microsoft.onenote; 18 | 19 | onenote:ConnectionConfig configuration = { 20 | auth: { 21 | clientId: "clientId", 22 | clientSecret: "clientSecret", 23 | refreshToken: "refreshToken", 24 | refreshUrl: "refreshUrl" 25 | } 26 | }; 27 | 28 | public function main() returns error? { 29 | onenote:Client oneNoteClient = check new (configuration); 30 | onenote:SectionGroup[] sectionGroup = check oneNoteClient->listSectionGroups("notebookId"); 31 | } 32 | -------------------------------------------------------------------------------- /examples/createSectionGroup.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerinax/microsoft.onenote; 18 | 19 | onenote:ConnectionConfig configuration = { 20 | auth: { 21 | clientId: "clientId", 22 | clientSecret: "clientSecret", 23 | refreshToken: "refreshToken", 24 | refreshUrl: "refreshUrl" 25 | } 26 | }; 27 | 28 | public function main() returns error? { 29 | onenote:Client oneNoteClient = check new (configuration); 30 | onenote:SectionGroup sectionGroup = check oneNoteClient->createSectionGroup("notebookId", "testSectionGroup"); 31 | } 32 | -------------------------------------------------------------------------------- /examples/createSectionInSectionGroup.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerinax/microsoft.onenote; 18 | 19 | onenote:ConnectionConfig configuration = { 20 | auth: { 21 | clientId: "clientId", 22 | clientSecret: "clientSecret", 23 | refreshToken: "refreshToken", 24 | refreshUrl: "refreshUrl" 25 | } 26 | }; 27 | 28 | public function main() returns error? { 29 | onenote:Client oneNoteClient = check new (configuration); 30 | onenote:Section section = check oneNoteClient->createSectionInSectionGroup("sectionGroupId", "section2"); 31 | } 32 | -------------------------------------------------------------------------------- /ballerina/constants.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | # Graph API related constants 18 | const BASE_URL = "https://graph.microsoft.com/v1.0"; 19 | const VALUE = "value"; 20 | const NOTEBOOKS_PATH = "/me/onenote/notebooks"; 21 | const PAGES_PATH = "/me/onenote/pages/"; 22 | const SECTIONS_PATH = "/me/onenote/sections/"; 23 | const SECTION_GROUP_PATH = "/me/onenote/sectionGroups/"; 24 | const PAGES = "/pages"; 25 | const SECTIONS = "/sections"; 26 | const SECTION_GROUPS = "/sectionGroups"; 27 | 28 | # Symbols 29 | const EMPTY_STRING = ""; 30 | const QUESTION_MARK = "?"; 31 | const SLASH = "/"; 32 | -------------------------------------------------------------------------------- /ballerina/Package.md: -------------------------------------------------------------------------------- 1 | Connects to Microsoft OneNote from Ballerina 2 | 3 | ## Package overview 4 | The `microsoft.onenote` is a [Ballerina](https://ballerina.io/) connector for Microsoft OneNote. 5 | This package provides the capability to access to a user's OneNote notebooks, sections, and pages in a personal 6 | account using the [OneNote REST API](https://docs.microsoft.com/en-us/graph/api/resources/onenote-api-overview?view=graph-rest-1.0) 7 | 8 | | | Version | 9 | | ----------------------------|--------------------------------| 10 | | Ballerina Language | Ballerina Swan Lake 2201.3.0 | 11 | | Microsoft Graph API | v1.0 | 12 | 13 | ## Report issues 14 | To report bugs, request new features, start new discussions, view project boards, etc., go to the [Ballerina Extended Library repository](https://github.com/ballerina-platform/ballerina-extended-library) 15 | 16 | ## Useful links 17 | - Discuss code changes of the Ballerina project in [ballerina-dev@googlegroups.com](mailto:ballerina-dev@googlegroups.com). 18 | - Chat live with us via our [Discord server](https://discord.gg/ballerinalang). 19 | - Post all technical questions on Stack Overflow with the [#ballerina](https://stackoverflow.com/questions/tagged/ballerina) tag 20 | -------------------------------------------------------------------------------- /.github/workflows/build-with-bal-test-native.yml: -------------------------------------------------------------------------------- 1 | name: GraalVM Check 2 | 3 | on: 4 | schedule: 5 | - cron: '30 18 * * *' 6 | workflow_dispatch: 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v2 14 | 15 | - name: Set up GraalVM 16 | uses: graalvm/setup-graalvm@v1 17 | with: 18 | java-version: '17' 19 | distribution: 'graalvm-community' 20 | set-java-home: false 21 | github-token: ${{ secrets.GITHUB_TOKEN }} 22 | 23 | - name: Check GraalVM installation 24 | run: | 25 | echo "GRAALVM_HOME: ${{ env.GRAALVM_HOME }}" 26 | echo "JAVA_HOME: ${{ env.JAVA_HOME }}" 27 | native-image --version 28 | 29 | - name: Set Up Ballerina 30 | uses: ballerina-platform/setup-ballerina@v1.1.0 31 | with: 32 | version: latest 33 | 34 | - name: Run Ballerina tests using the native executable 35 | working-directory: ./ballerina 36 | run: bal test --graalvm 37 | env: 38 | JAVA_HOME: /usr/lib/jvm/default-jvm 39 | REFRESH_URL: ${{ secrets.REFRESH_URL }} 40 | REFRESH_TOKEN: ${{ secrets.REFRESH_TOKEN }} 41 | CLIENT_ID: ${{ secrets.CLIENT_ID }} 42 | CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} 43 | -------------------------------------------------------------------------------- /examples/createPageWithHTML.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerinax/microsoft.onenote; 18 | 19 | onenote:ConnectionConfig configuration = { 20 | auth: { 21 | clientId: "clientId", 22 | clientSecret: "clientSecret", 23 | refreshToken: "refreshToken", 24 | refreshUrl: "refreshUrl" 25 | } 26 | }; 27 | 28 | public function main() returns error? { 29 | onenote:Client oneNoteClient = check new (configuration); 30 | string testHtmlContent = "Test

Hello

"; 31 | onenote:Page page = check oneNoteClient->createPageWithHTML("sectionId", testHtmlContent); 32 | } 33 | -------------------------------------------------------------------------------- /examples/deletePage.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerinax/microsoft.onenote; 18 | import ballerina/log; 19 | 20 | onenote:ConnectionConfig configuration = { 21 | auth: { 22 | clientId: "clientId", 23 | clientSecret: "clientSecret", 24 | refreshToken: "refreshToken", 25 | refreshUrl: "refreshUrl" 26 | } 27 | }; 28 | 29 | public function main() returns error? { 30 | onenote:Client oneNoteClient = check new (configuration); 31 | error? response = check oneNoteClient->deletePage("pageId"); 32 | if (response is error) { 33 | log:printInfo("Failed to delete page"); 34 | } else { 35 | log:printInfo("Deleted page"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /pull_request_template.md: -------------------------------------------------------------------------------- 1 | # Description 2 | 3 | Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. 4 | 5 | Fixes # (issue) 6 | 7 | Related Pull Requests (remove if not relevant) 8 | - Pull request 1 9 | - Pull request 2 10 | 11 | One line release note: 12 | - One line describing the feature/improvement/fix made by this PR 13 | 14 | ## Type of change 15 | 16 | Please delete options that are not relevant. 17 | 18 | - [ ] Bug fix (non-breaking change which fixes an issue) 19 | - [ ] New feature (non-breaking change which adds functionality) 20 | - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) 21 | - [ ] This change requires a documentation update 22 | 23 | # How Has This Been Tested? 24 | 25 | Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration 26 | 27 | - [ ] Test A 28 | - [ ] Test B 29 | 30 | **Test Configuration**: 31 | * Ballerina Version: 32 | * Operating System: 33 | * Java SDK: 34 | 35 | # Checklist: 36 | 37 | ### Security checks 38 | - [ ] Followed secure coding standards in http://wso2.com/technical-reports/wso2-secure-engineering-guidelines? 39 | - [ ] Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets? 40 | -------------------------------------------------------------------------------- /.github/workflows/pull-request.yml: -------------------------------------------------------------------------------- 1 | name: Pull Request 2 | 3 | on: [ pull_request ] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | 11 | # Setup Ballerina Environment 12 | - name: Set Up Ballerina 13 | uses: ballerina-platform/setup-ballerina@v1.1.0 14 | with: 15 | version: latest 16 | 17 | # Build Ballerina Project 18 | - name: Ballerina Build 19 | run: bal pack ./ballerina 20 | env: 21 | JAVA_HOME: /usr/lib/jvm/default-jvm 22 | 23 | # Build Module Examples 24 | - name: Ballerina Examples Build 25 | run: chmod +x ./examples/build.sh && ./examples/build.sh build 26 | env: 27 | JAVA_HOME: /usr/lib/jvm/default-jvm 28 | 29 | # Test Ballerina Project 30 | - name: Ballerina Test 31 | # tests will be skipped if the PR is from a forked repository (as the secrets are not available) 32 | if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} 33 | run: bal test ./ballerina --test-report --code-coverage --coverage-format=xml 34 | env: 35 | JAVA_HOME: /usr/lib/jvm/default-jvm 36 | REFRESH_URL: ${{ secrets.REFRESH_URL }} 37 | REFRESH_TOKEN: ${{ secrets.REFRESH_TOKEN }} 38 | CLIENT_ID: ${{ secrets.CLIENT_ID }} 39 | CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} 40 | 41 | - name: Upload coverage reports to Codecov 42 | uses: codecov/codecov-action@v3 43 | -------------------------------------------------------------------------------- /examples/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BAL_EXAMPLES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | BAL_CENTRAL_DIR="$HOME/.ballerina/repositories/central.ballerina.io/" 5 | BAL_HOME_DIR="$BAL_EXAMPLES_DIR/../ballerina" 6 | 7 | set -e 8 | 9 | case "$1" in 10 | build) 11 | BAL_CMD="build" 12 | ;; 13 | run) 14 | BAL_CMD="run" 15 | ;; 16 | *) 17 | echo "Invalid command provided: '$1'. Please provide 'build' or 'run' as the command." 18 | exit 1 19 | ;; 20 | esac 21 | 22 | # Read Ballerina package name 23 | BAL_PACKAGE_NAME=$(awk -F'"' '/^name/ {print $2}' "$BAL_HOME_DIR/Ballerina.toml") 24 | 25 | # Push the package to the local repository 26 | cd "$BAL_HOME_DIR" && 27 | bal pack && 28 | bal push --repository=local 29 | 30 | # Remove the cache directories in the repositories 31 | cacheDirs=($(ls -d "$BAL_CENTRAL_DIR"/cache-* 2>/dev/null)) 32 | for dir in "${cacheDirs[@]}"; do 33 | [ -d "$dir" ] && rm -r "$dir" 34 | done 35 | echo "Successfully cleaned the cache directories" 36 | 37 | # Update the central repository 38 | BAL_DESTINATION_DIR="$HOME/.ballerina/repositories/central.ballerina.io/bala/ballerinax/$BAL_PACKAGE_NAME" 39 | BAL_SOURCE_DIR="$HOME/.ballerina/repositories/local/bala/ballerinax/$BAL_PACKAGE_NAME" 40 | [ -d "$BAL_DESTINATION_DIR" ] && rm -r "$BAL_DESTINATION_DIR" 41 | [ -d "$BAL_SOURCE_DIR" ] && cp -r "$BAL_SOURCE_DIR" "$BAL_DESTINATION_DIR" 42 | echo "Successfully updated the local central repositories" 43 | 44 | # Loop through examples in the examples directory 45 | find "$BAL_EXAMPLES_DIR" -type f -name "*.bal" | while read -r BAL_EXAMPLE_FILE; do 46 | bal "$BAL_CMD" --offline "$BAL_EXAMPLE_FILE" 47 | done 48 | -------------------------------------------------------------------------------- /.github/workflows/dev-stg-release.yml: -------------------------------------------------------------------------------- 1 | name: Dev/Staging BCentral Release 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | bal_central_environment: 7 | description: Ballerina Central Environment 8 | type: choice 9 | options: 10 | - STAGE 11 | - DEV 12 | required: true 13 | 14 | jobs: 15 | release: 16 | runs-on: ubuntu-latest 17 | env: 18 | BALLERINA_${{ github.event.inputs.bal_central_environment }}_CENTRAL: true 19 | steps: 20 | - uses: actions/checkout@v2 21 | 22 | # Setup Ballerina Environment 23 | - name: Set Up Ballerina 24 | uses: ballerina-platform/setup-ballerina@v1.1.0 25 | with: 26 | version: 2201.2.1 27 | 28 | # Build Ballerina Project 29 | - name: Ballerina Build 30 | run: bal pack ./ballerina 31 | env: 32 | JAVA_HOME: /usr/lib/jvm/default-jvm 33 | 34 | # Build Module Examples 35 | - name: Ballerina Examples Build 36 | run: chmod +x ./examples/build.sh && ./examples/build.sh build 37 | env: 38 | JAVA_HOME: /usr/lib/jvm/default-jvm 39 | 40 | # Push to Ballerina Staging Central 41 | - name: Push to Staging 42 | if: github.event.inputs.bal_central_environment == 'STAGE' 43 | run: bal push 44 | working-directory: ./ballerina 45 | env: 46 | BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_STAGE_ACCESS_TOKEN }} 47 | JAVA_HOME: /usr/lib/jvm/default-jvm 48 | 49 | # Push to Ballerina Dev Central 50 | - name: Push to Dev 51 | if: github.event.inputs.bal_central_environment == 'DEV' 52 | run: bal push 53 | working-directory: ./ballerina 54 | env: 55 | BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_DEV_ACCESS_TOKEN }} 56 | JAVA_HOME: /usr/lib/jvm/default-jvm 57 | -------------------------------------------------------------------------------- /.github/workflows/daily-build.yml: -------------------------------------------------------------------------------- 1 | name: Daily build 2 | 3 | on: 4 | schedule: 5 | - cron: '30 2 * * *' 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v2 13 | 14 | # Setup Ballerina Environment 15 | - name: Set Up Ballerina 16 | uses: ballerina-platform/setup-ballerina@v1.1.0 17 | with: 18 | version: latest 19 | 20 | # Build Ballerina Project 21 | - name: Ballerina Build 22 | run: bal pack ./ballerina 23 | env: 24 | JAVA_HOME: /usr/lib/jvm/default-jvm 25 | 26 | # Build Module Examples 27 | - name: Ballerina Examples Build 28 | run: chmod +x ./examples/build.sh && ./examples/build.sh build 29 | env: 30 | JAVA_HOME: /usr/lib/jvm/default-jvm 31 | 32 | # Test Ballerina Project 33 | - name: Ballerina Test 34 | run: bal test ./ballerina --test-report --code-coverage --coverage-format=xml 35 | env: 36 | JAVA_HOME: /usr/lib/jvm/default-jvm 37 | REFRESH_URL: ${{ secrets.REFRESH_URL }} 38 | REFRESH_TOKEN: ${{ secrets.REFRESH_TOKEN }} 39 | CLIENT_ID: ${{ secrets.CLIENT_ID }} 40 | CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} 41 | 42 | - name: Upload coverage reports to Codecov 43 | uses: codecov/codecov-action@v3 44 | 45 | # Send notification when build fails 46 | - name: Notify failure 47 | if: ${{ failure() }} 48 | run: | 49 | curl -X POST \ 50 | 'https://api.github.com/repos/ballerina-platform/ballerina-release/dispatches' \ 51 | -H 'Accept: application/vnd.github.v3+json' \ 52 | -H 'Authorization: Bearer ${{ secrets.BALLERINA_BOT_TOKEN }}' \ 53 | --data "{ 54 | \"event_type\": \"notify-build-failure\", 55 | \"client_payload\": { 56 | \"repoName\": \"module-ballerinax-microsoft.onenote\" 57 | } 58 | }" 59 | -------------------------------------------------------------------------------- /ballerina/Module.md: -------------------------------------------------------------------------------- 1 | ## Overview 2 | Ballerina connector for Microsoft OneNote connects the [Microsoft OneNote API](https://docs.microsoft.com/en-us/graph/api/resources/onenote-api-overview?view=graph-rest-1.0) through Ballerina. It provides the capability to perform CRUD operations on OneNote notebooks, sections and pages. 3 | 4 | This module supports [Microsoft Graph API](https://docs.microsoft.com/en-us/graph/overview) v1.0 version and only allows to perform functions behalf of the currently logged in user. 5 | 6 | ## Prerequisites 7 | Before using this connector in your Ballerina application, complete the following: 8 | - Create a [Microsoft Office365 account](https://signup.live.com/) 9 | - Obtain tokens - Follow [this link](https://docs.microsoft.com/en-us/graph/auth-v2-user#authentication-and-authorization-steps) 10 | 11 | ## Quickstart 12 | 13 | To use the MS OneNote connector in your Ballerina application, update the .bal file as follows: 14 | 15 | ### Step 1: Import connector 16 | First, import the `ballerinax/microsoft.onenote` module as shown below. 17 | ```ballerina 18 | import ballerinax/microsoft.onenote; 19 | ``` 20 | 21 | ### Step 2: Create a new connector instance 22 | Create a `microsoft.onenote:ConnectionConfig` with the OAuth2 tokens obtained and initialize the connector with it. 23 | ```ballerina 24 | microsoft.onenote:ConnectionConfig configuration = { 25 | auth: { 26 | refreshUrl: , 27 | refreshToken : , 28 | clientId : , 29 | clientSecret : 30 | } 31 | }; 32 | 33 | microsoft.onenote:Client oneNoteClient = check new(configuration); 34 | ``` 35 | 36 | ### Step 3: Invoke connector operation 37 | Now you can use the operations available within the connector. Note that they are in the form of remote operations. 38 | 39 | Following is an example on how to create a notebook using the connector. 40 | 41 | ```ballerina 42 | public function main() returns error? { 43 | Notebook notebook = check oneNoteClient->createNotebook("test"); 44 | } 45 | ``` 46 | 47 | **[You can find a list of samples here](https://github.com/ballerina-platform/module-ballerinax-microsoft.onenote/tree/main/examples)** 48 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - 2201.[0-9]+.x 8 | repository_dispatch: 9 | types: 10 | check_connector_for_breaking_changes 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v2 17 | 18 | # Setup Ballerina Environment 19 | - name: Set Up Ballerina 20 | uses: ballerina-platform/setup-ballerina@v1.1.0 21 | with: 22 | version: latest 23 | 24 | # Build Ballerina Project 25 | - name: Ballerina Build 26 | run: bal pack ./ballerina 27 | env: 28 | JAVA_HOME: /usr/lib/jvm/default-jvm 29 | 30 | # Build Module Examples 31 | - name: Ballerina Examples Build 32 | run: chmod +x ./examples/build.sh && ./examples/build.sh build 33 | env: 34 | JAVA_HOME: /usr/lib/jvm/default-jvm 35 | 36 | # Test Ballerina Project 37 | - name: Ballerina Test 38 | run: bal test ./ballerina --test-report --code-coverage --coverage-format=xml 39 | env: 40 | JAVA_HOME: /usr/lib/jvm/default-jvm 41 | REFRESH_URL: ${{ secrets.REFRESH_URL }} 42 | REFRESH_TOKEN: ${{ secrets.REFRESH_TOKEN }} 43 | CLIENT_ID: ${{ secrets.CLIENT_ID }} 44 | CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} 45 | 46 | - name: Upload coverage reports to Codecov 47 | uses: codecov/codecov-action@v3 48 | 49 | # Send notification when build fails 50 | - name: Alert notifier on failure 51 | if: failure() && (github.event.action == 'check_connector_for_breaking_changes') 52 | run: | 53 | curl -X POST \ 54 | 'https://api.github.com/repos/ballerina-platform/ballerina-release/dispatches' \ 55 | --header 'Accept: application/vnd.github.v3+json' \ 56 | --header 'Authorization: Bearer ${{ secrets.BALLERINA_BOT_TOKEN }}' \ 57 | --data-raw '{ 58 | "event_type": "notify-ballerinax-connector-build-failure", 59 | "client_payload": { 60 | "repoName": "module-ballerinax-microsoft.onenote", 61 | "workflow": "CI" 62 | } 63 | }' 64 | -------------------------------------------------------------------------------- /ballerina/utils.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/http; 18 | 19 | isolated function handleResponse(http:Response httpResponse) returns map|error { 20 | if (httpResponse.statusCode == http:STATUS_OK || httpResponse.statusCode == http:STATUS_CREATED) { 21 | json jsonResponse = check httpResponse.getJsonPayload(); 22 | return >jsonResponse; 23 | } else if (httpResponse.statusCode == http:STATUS_NO_CONTENT || httpResponse.statusCode == http:STATUS_ACCEPTED) { 24 | return {}; 25 | } 26 | json jsonResponse = check httpResponse.getJsonPayload(); 27 | return error(jsonResponse.toString()); 28 | } 29 | 30 | isolated function getNotebookArray(http:Response response) returns Notebook[]|error { 31 | map handledResponse = check handleResponse(response); 32 | return check handledResponse[VALUE].cloneWithType(NotebookArray); 33 | } 34 | 35 | isolated function getRecentNotebookArray(http:Response response) returns RecentNotebook[]|error { 36 | map handledResponse = check handleResponse(response); 37 | return check handledResponse[VALUE].cloneWithType(RecentNotebookArray); 38 | } 39 | 40 | isolated function getSectionArray(http:Response response) returns Section[]|error { 41 | map handledResponse = check handleResponse(response); 42 | return check handledResponse[VALUE].cloneWithType(SectionArray); 43 | } 44 | 45 | isolated function getSectionGroupArray(http:Response response) returns SectionGroup[]|error { 46 | map handledResponse = check handleResponse(response); 47 | return check handledResponse[VALUE].cloneWithType(SectionGroupArray); 48 | } 49 | 50 | isolated function getPagesArray(http:Response response) returns Page[]|error { 51 | map handledResponse = check handleResponse(response); 52 | return check handledResponse[VALUE].cloneWithType(PageArray); 53 | } 54 | 55 | isolated function createHTMLContent(string pageTitle, string pageBody) returns string { 56 | return "" + pageTitle + "

" + pageBody + "

"; 57 | } 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Ballerina Connector For Microsoft OneNote 2 | =================== 3 | 4 | [![Build Status](https://github.com/ballerina-platform/module-ballerinax-microsoft.onenote/workflows/CI/badge.svg)](https://github.com/ballerina-platform/module-ballerinax-msgraph-onedrive/actions?query=workflow%3ACI) 5 | [![codecov](https://codecov.io/gh/ballerina-platform/module-ballerinax-microsoft.onenote/branch/main/graph/badge.svg)](https://codecov.io/gh/ballerina-platform/module-ballerinax-microsoft.onenote) 6 | [![GitHub Last Commit](https://img.shields.io/github/last-commit/ballerina-platform/module-ballerinax-microsoft.onenote.svg)](https://github.com/ballerina-platform/module-ballerinax-microsoft.onenote/commits/main) 7 | [![GraalVM Check](https://github.com/ballerina-platform/module-ballerinax-microsoft.onenote/actions/workflows/build-with-bal-test-native.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerinax-microsoft.onenote/actions/workflows/build-with-bal-test-native.yml) 8 | [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) 9 | 10 | The `microsoft.onenote` is a [Ballerina](https://ballerina.io/) connector for Microsoft OneNote. 11 | 12 | [Microsoft OneNote](https://www.microsoft.com/en-ww/microsoft-365/onenote/digital-note-taking-app) is a cross-functional notebook for all notetaking needs developed by Microsoft in the Office365. 13 | 14 | This connector provides operations for connecting and interacting with Microsoft Graph API OneNote endpoints over the network and access a user's OneNote notebooks, sections, and pages in a personal account. 15 | 16 | For more information about configuration and operations, go to the module. 17 | - [`ballerinax/microsoft.onenote`](onenote/Module.md) 18 | 19 | ## Building from the source 20 | ### Setting up the prerequisites 21 | 22 | 1. Download and install Java SE Development Kit (JDK) version 11. You can install either [OpenJDK](https://adoptopenjdk.net/) or [Oracle JDK](https://www.oracle.com/java/technologies/javase-jdk11-downloads.html). 23 | 24 | > **Note:** Set the JAVA_HOME environment variable to the path name of the directory into which you installed JDK. 25 | 26 | 2. Download and install [Ballerina Swan Lake](https://ballerina.io/). 27 | 28 | ### Building the source 29 | Execute the commands below to build from the source. 30 | 31 | * To build the package: 32 | ``` 33 | bal build ./ballerina 34 | ``` 35 | * To test the package after build: 36 | ``` 37 | bal test ./ballerina 38 | ``` 39 | ## Contributing to Ballerina 40 | As an open source project, Ballerina welcomes contributions from the community. 41 | 42 | For more information, go to the [contribution guidelines](https://github.com/ballerina-platform/ballerina-lang/blob/main/CONTRIBUTING.md). 43 | 44 | ## Code of conduct 45 | All contributors are encouraged to read the [Ballerina Code of Conduct](https://ballerina.io/code-of-conduct). 46 | 47 | ## Useful links 48 | * Discuss about code changes of the Ballerina project in [ballerina-dev@googlegroups.com](mailto:ballerina-dev@googlegroups.com). 49 | * Chat live with us via our [Discord server](https://discord.gg/ballerinalang). 50 | * Post all technical questions on Stack Overflow with the [#ballerina](https://stackoverflow.com/questions/tagged/ballerina) tag. 51 | -------------------------------------------------------------------------------- /ballerina/types.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/http; 18 | import ballerinax/'client.config; 19 | 20 | # Client configuration details. 21 | @display {label: "Connection Config"} 22 | public type ConnectionConfig record {| 23 | *config:ConnectionConfig; 24 | # Configurations related to client authentication 25 | http:BearerTokenConfig|config:OAuth2RefreshTokenGrantConfig auth; 26 | |}; 27 | 28 | # Represents a Notebook. 29 | # 30 | # + createdBy - Identity of the user, device, and application which created the item 31 | # + createdDateTime - The date and time when the notebook was created 32 | # + id - The unique identifier of the notebook 33 | # + isDefault - Indicates whether this is the user's default notebook 34 | # + isShared - Indicates whether the notebook is shared. If true, the contents of the notebook can be seen by people 35 | # other than the owner. 36 | # + lastModifiedBy - Identity of the user, device, and application which created the item 37 | # + lastModifiedDateTime - The date and time when the notebook was last modified 38 | # + links - Links for opening the notebook. The oneNoteClientURL link opens the notebook in the OneNote native client 39 | # if it's installed. The oneNoteWebURL link opens the notebook in OneNote on the web. 40 | # + displayName - The name of the notebook. 41 | # + sectionGroupsUrl - The URL for the sectionGroups navigation property, which returns all the section groups in the notebook 42 | # + sectionsUrl - The URL for the sections navigation property, which returns all the sections in the notebook 43 | # + self - The endpoint where you can get details about the notebook 44 | # + userRole - Possible values are: Owner, Contributor, Reader, None. Owner represents owner-level access to the notebook. 45 | # Contributor represents read/write access to the notebook. Reader represents read-only access to the notebook. 46 | @display {label: "Notebook"} 47 | public type Notebook record { 48 | string id; 49 | string displayName; 50 | json createdBy; 51 | string createdDateTime; 52 | boolean isDefault; 53 | boolean isShared; 54 | json lastModifiedBy; 55 | string lastModifiedDateTime; 56 | json links; 57 | string sectionGroupsUrl; 58 | string sectionsUrl; 59 | string self; 60 | string userRole; 61 | }; 62 | 63 | # Represents a RecentNotebook. 64 | # 65 | # + displayName - The name of the notebook 66 | # + lastAccessedTime - The date and time when the notebook was last accessed 67 | # + links - Links for opening the notebook 68 | # + sourceService - Source service 69 | @display {label: "Recent Notebook"} 70 | public type RecentNotebook record { 71 | string displayName; 72 | string lastAccessedTime; 73 | json links; 74 | string sourceService; 75 | }; 76 | 77 | # Represents a Section. 78 | # 79 | # + createdBy - Identity of the user, device, and application which created the item 80 | # + createdDateTime - The date and time when the section was created 81 | # + id - The unique identifier of the section 82 | # + isDefault - Indicates whether this is the user's default section 83 | # + lastModifiedBy - Identity of the user, device, and application which created the item 84 | # + lastModifiedDateTime - The date and time when the section was last modified 85 | # + displayName - The name of the section 86 | # + pagesUrl - The pages endpoint where you can get details for all the pages in the section 87 | # + self - The endpoint where you can get details about the section 88 | @display {label: "Section"} 89 | public type Section record { 90 | string id; 91 | string displayName; 92 | json createdBy; 93 | string createdDateTime; 94 | boolean isDefault; 95 | json lastModifiedBy; 96 | string lastModifiedDateTime; 97 | string pagesUrl; 98 | string self; 99 | }; 100 | 101 | # Represents a SectionGroup. 102 | # 103 | # + createdBy - Identity of the user, device, and application which created the item 104 | # + createdDateTime - The date and time when the section group was created 105 | # + id - The unique identifier of the section group 106 | # + lastModifiedBy - Identity of the user, device, and application which created the item 107 | # + lastModifiedDateTime - The date and time when the section group was last modified 108 | # + sectionGroupsUrl - The URL for the sectionGroups navigation property, which returns all the section groups in the section group 109 | # + sectionsUrl - The URL for the sections navigation property, which returns all the sections in the section group 110 | # + self - The endpoint where you can get details about the section group 111 | # + displayName - The name of the section group 112 | @display {label: "Section Group"} 113 | public type SectionGroup record { 114 | string id; 115 | string displayName; 116 | json createdBy; 117 | string createdDateTime; 118 | json lastModifiedBy; 119 | string lastModifiedDateTime; 120 | string sectionGroupsUrl; 121 | string sectionsUrl; 122 | string self; 123 | }; 124 | 125 | # Represents a Page. 126 | # 127 | # + createdDateTime - The date and time when the page was created 128 | # + id - The unique identifier of the page 129 | # + lastModifiedDateTime - The date and time when the page was last modified 130 | # + self - The endpoint where you can get details about the page 131 | # + title - The title of the page 132 | # + content - The page's HTML content 133 | # + contentUrl - The URL for the page's HTML content 134 | # + createdByAppId - The unique identifier of the application that created the page. Read-only 135 | @display {label: "Page"} 136 | public type Page record { 137 | string id; 138 | string title; 139 | string createdDateTime; 140 | string lastModifiedDateTime; 141 | string self; 142 | byte[] content?; 143 | string contentUrl; 144 | string createdByAppId?; 145 | }; 146 | 147 | type NotebookArray Notebook[]; 148 | type SectionArray Section[]; 149 | type SectionGroupArray SectionGroup[]; 150 | type PageArray Page[]; 151 | type RecentNotebookArray RecentNotebook[]; 152 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /ballerina/tests/test.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/log; 18 | import ballerina/os; 19 | import ballerina/test; 20 | import ballerina/lang.runtime; 21 | 22 | configurable string refreshUrl = os:getEnv("REFRESH_URL"); 23 | configurable string refreshToken = os:getEnv("REFRESH_TOKEN"); 24 | configurable string clientId = os:getEnv("CLIENT_ID"); 25 | configurable string clientSecret = os:getEnv("CLIENT_SECRET"); 26 | 27 | ConnectionConfig configuration = { 28 | auth: { 29 | clientId: clientId, 30 | clientSecret: clientSecret, 31 | refreshToken: refreshToken, 32 | refreshUrl: refreshUrl 33 | } 34 | }; 35 | 36 | Client oneNoteClient = check new(configuration); 37 | string testNotebookName = "My Notebook"; 38 | string testSectionName = "Quick Notes"; 39 | string testPageTitle = "Test Page Title"; 40 | string testSectionGroupName = "Test Section Group"; 41 | string notebookId = "1-8ad0487a-f612-4368-9be6-d863712f9254"; 42 | string sectionId = EMPTY_STRING; 43 | string sectionGroupId = EMPTY_STRING; 44 | string pageId = EMPTY_STRING; 45 | string pageId2 = EMPTY_STRING; 46 | string pageId3 = EMPTY_STRING; 47 | 48 | @test:Config { 49 | enable: true 50 | } 51 | function testListNotebooks() returns error? { 52 | log:printInfo("oneNoteClient->listNotebooks()"); 53 | Notebook[] notebooks = check oneNoteClient->listNotebooks(); 54 | log:printInfo("Number of notebooks available: " + notebooks.length().toString()); 55 | log:printInfo("Name of test notebook: " + notebooks[0].displayName); 56 | test:assertEquals(notebookId, notebooks[0].id); 57 | } 58 | 59 | @test:Config { 60 | enable: true 61 | } 62 | function testListNotebooksWithQuery() returns error? { 63 | log:printInfo("oneNoteClient->testListNotebooksWithQuery()"); 64 | Notebook[] notebooks = check oneNoteClient->listNotebooks("$top=2&$count=true"); 65 | log:printInfo("Number of notebooks available: " + notebooks.length().toString()); 66 | test:assertEquals(notebookId, notebooks[0].id); 67 | } 68 | 69 | @test:Config { 70 | enable: true, 71 | dependsOn: [testListNotebooks] 72 | } 73 | function testGetNotebook() returns error? { 74 | log:printInfo("oneNoteClient->getNotebook()"); 75 | Notebook notebook = check oneNoteClient->getNotebook(notebookId); 76 | log:printInfo("Notebook name: " + notebook.displayName); 77 | test:assertEquals(testNotebookName, notebook.displayName); 78 | } 79 | 80 | @test:Config { 81 | enable: true 82 | } 83 | function testGetRecentNotebooks() returns error? { 84 | log:printInfo("oneNoteClient->getRecentNotebooks()"); 85 | RecentNotebook[] recentNotebooks = check oneNoteClient->getRecentNotebooks(); 86 | log:printInfo("Number of notebooks: " + recentNotebooks.length().toString()); 87 | log:printInfo("Display name of test notebook: " + recentNotebooks[0].displayName); 88 | test:assertEquals(testNotebookName, recentNotebooks[0].displayName); 89 | } 90 | 91 | @test:Config { 92 | enable: true, 93 | dependsOn: [testListNotebooks] 94 | } 95 | function testListSections() returns error? { 96 | log:printInfo("oneNoteClient->testListSections()"); 97 | Section[] sections = check oneNoteClient->listSections(notebookId); 98 | log:printInfo("No of sections in notebook " + notebookId + " -> " + sections.length().toString()); 99 | log:printInfo("Display name of test section: " + sections[0].displayName); 100 | sectionId = sections[0].id; 101 | test:assertEquals(testSectionName, sections[0].displayName); 102 | } 103 | 104 | @test:Config { 105 | enable: true, 106 | dependsOn: [testListNotebooks] 107 | } 108 | function testListSectionsWithQuery() returns error? { 109 | log:printInfo("oneNoteClient->testListSectionsWithQuery()"); 110 | Section[] sections = check oneNoteClient->listSections(notebookId, "$top=2&$count=true"); 111 | log:printInfo("No of sections in notebook " + notebookId + " -> " + sections.length().toString()); 112 | test:assertEquals(testSectionName, sections[0].displayName); 113 | } 114 | 115 | @test:Config { 116 | enable: true, 117 | dependsOn: [testListSections] 118 | } 119 | function testGetSection() returns error? { 120 | log:printInfo("oneNoteClient->testGetSection()"); 121 | Section section = check oneNoteClient->getSection(sectionId); 122 | log:printInfo("Name of the section: " + section.displayName); 123 | test:assertEquals(sectionId, section.id); 124 | } 125 | 126 | @test:Config { 127 | enable: false, 128 | dependsOn: [testListSections] 129 | } 130 | function testCreateSection() returns error? { 131 | log:printInfo("oneNoteClient->testCreateSection()"); 132 | Section section = check oneNoteClient->createSection("0-4158FCD360E478B!432", "testSection"); 133 | log:printInfo("Name of the created section: " + section.displayName); 134 | test:assertEquals("testSection", section.displayName); 135 | } 136 | 137 | @test:Config { 138 | enable: true, 139 | dependsOn: [testListSections] 140 | } 141 | function testListSectionGroups() returns error? { 142 | log:printInfo("oneNoteClient->testListSectionGroups()"); 143 | SectionGroup[] sectionGroup = check oneNoteClient->listSectionGroups(notebookId); 144 | log:printInfo("No of section groups: " + sectionGroup.length().toString()); 145 | log:printInfo("Display name of test section group: " + sectionGroup[0].displayName); 146 | sectionGroupId = sectionGroup[0].id; 147 | test:assertEquals(testSectionGroupName, sectionGroup[0].displayName); 148 | } 149 | 150 | @test:Config { 151 | enable: true, 152 | dependsOn: [testListSections] 153 | } 154 | function testListSectionGroupsWithQuery() returns error? { 155 | log:printInfo("oneNoteClient->testListSectionGroupsWithQuery()"); 156 | SectionGroup[] sectionGroup = check oneNoteClient->listSectionGroups(notebookId, "$top=2&$count=true"); 157 | log:printInfo("No of section groups: " + sectionGroup.length().toString()); 158 | test:assertEquals(testSectionGroupName, sectionGroup[0].displayName); 159 | } 160 | 161 | @test:Config { 162 | enable: false 163 | } 164 | function testCreateNotebook() returns error? { 165 | log:printInfo("oneNoteClient->createNotebook()"); 166 | string name = "testNotebook1"; 167 | Notebook notebook = check oneNoteClient->createNotebook(name); 168 | log:printInfo("Created Notebook name: " + notebook.displayName + " Id: " + notebook.id); 169 | test:assertEquals(name, notebook.displayName); 170 | } 171 | 172 | @test:Config { 173 | enable: false, 174 | dependsOn: [testListNotebooks] 175 | } 176 | function testCreateSectionGroup() returns error? { 177 | log:printInfo("oneNoteClient->testCreateSectionGroup()"); 178 | string name = "testSectionGroup"; 179 | SectionGroup sectionGroup = check oneNoteClient->createSectionGroup(notebookId, name); 180 | log:printInfo("Created section group: " + sectionGroup.displayName); 181 | test:assertEquals(name, sectionGroup.displayName); 182 | } 183 | 184 | @test:Config { 185 | enable: false, 186 | dependsOn: [testListSectionGroups] 187 | } 188 | function testCreateSectionInSectionGroup() returns error? { 189 | log:printInfo("oneNoteClient->testCreateSectionInSectionGroup()"); 190 | string name = "section2"; 191 | Section section = check oneNoteClient->createSectionInSectionGroup(sectionGroupId, "section2"); 192 | log:printInfo("Created section: " + section.displayName); 193 | test:assertEquals(name, section.displayName); 194 | } 195 | 196 | @test:Config { 197 | enable: true, 198 | dependsOn: [testListSectionGroups] 199 | } 200 | function getSectionGroup() returns error? { 201 | log:printInfo("oneNoteClient->getSectionGroup()"); 202 | SectionGroup sectionGroup = check oneNoteClient->getSectionGroup(sectionGroupId); 203 | log:printInfo("Section group name: " + sectionGroup.displayName); 204 | test:assertEquals(sectionGroupId, sectionGroup.id); 205 | } 206 | 207 | @test:Config { 208 | enable: true, 209 | dependsOn: [testListSections, testDeletePage] 210 | } 211 | function testListPages() returns error? { 212 | log:printInfo("oneNoteClient->testListPages()"); 213 | runtime:sleep(5); 214 | Page[] pages = check oneNoteClient->listPages(sectionId); 215 | log:printInfo("No of pages: " + pages.length().toString()); 216 | boolean testPageFound = false; 217 | foreach Page page in pages { 218 | log:printInfo("Title: " + page.title); 219 | if (page.title == testPageTitle) { 220 | testPageFound = true; 221 | pageId = page.id; 222 | } 223 | } 224 | test:assertTrue(testPageFound); 225 | } 226 | 227 | @test:Config { 228 | enable: true, 229 | dependsOn: [testListSections, testListPages] 230 | } 231 | function testListPagesWithQuery() returns error? { 232 | log:printInfo("oneNoteClient->testListPagesWithQuery()"); 233 | Page[] pages = check oneNoteClient->listPages(sectionId, "$top=5&$count=true"); 234 | log:printInfo("No of pages: " + pages.length().toString()); 235 | boolean testPageFound = false; 236 | foreach Page page in pages { 237 | log:printInfo(page.title); 238 | if (page.title == testPageTitle) { 239 | testPageFound = true; 240 | } 241 | } 242 | test:assertTrue(testPageFound); 243 | } 244 | 245 | @test:Config { 246 | enable: true, 247 | dependsOn: [testListPages] 248 | } 249 | function testGetPage() returns error? { 250 | log:printInfo("oneNoteClient->testGetPage()"); 251 | Page page = check oneNoteClient->getPage(pageId); 252 | log:printInfo("Page title: " + page.title); 253 | test:assertEquals(testPageTitle, page.title); 254 | } 255 | 256 | @test:Config { 257 | enable: true, 258 | dependsOn: [testListSections] 259 | } 260 | function testCreatePageWithHTML() returns error? { 261 | log:printInfo("oneNoteClient->testCreatePageWithHTML()"); 262 | string testHtmlContent = "Test Page Title

Hello

"; 263 | Page page = check oneNoteClient->createPageWithHTML(sectionId, testHtmlContent); 264 | log:printInfo("Created page title: " + page.title); 265 | pageId2 = page.id; 266 | test:assertEquals("Test Page Title", page.title); 267 | } 268 | 269 | @test:Config { 270 | enable: true, 271 | dependsOn: [testCreatePageWithHTML] 272 | } 273 | function testDeleteHTMLPage() returns error? { 274 | log:printInfo("oneNoteClient->testDeleteHTMLPage()"); 275 | runtime:sleep(5); 276 | error? response = oneNoteClient->deletePage(pageId2); 277 | if (response is error) { 278 | test:assertFail("Error in deleting page: " + pageId2 + response.toString()); 279 | } 280 | } 281 | 282 | @test:Config { 283 | enable: true, 284 | dependsOn: [testDeleteHTMLPage] 285 | } 286 | function testCreatePage() returns error? { 287 | log:printInfo("oneNoteClient->testCreatePage()"); 288 | Page page = check oneNoteClient->createPage(sectionId, pageTitle = "Test Page2 Title", pageBody = "Hi"); 289 | log:printInfo("Created page title: " + page.title); 290 | pageId3 = page.id; 291 | test:assertEquals("Test Page2 Title", page.title); 292 | } 293 | 294 | @test:Config { 295 | enable: true, 296 | dependsOn: [testCreatePage] 297 | } 298 | function testDeletePage() returns error? { 299 | log:printInfo("oneNoteClient->testDeletePage()"); 300 | runtime:sleep(5); 301 | error? response = oneNoteClient->deletePage(pageId3); 302 | if (response is error) { 303 | test:assertFail("Error in deleting page: " + pageId3 + response.toString()); 304 | } 305 | } 306 | -------------------------------------------------------------------------------- /ballerina/endpoint.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/http; 18 | import ballerinax/'client.config; 19 | 20 | # Ballerina Microsoft OneNote connector provides the capability to access Microsoft Graph OneNote API 21 | # It provides capability to perform perform CRUD (Create, Read, Update, and Delete) operations on [OneNote] 22 | # (https://docs.microsoft.com/en-us/graph/api/resources/onenote-api-overview?view=graph-rest-1.0). 23 | # 24 | # + httpClient - HTTP Client 25 | @display { 26 | label: "Microsoft OneNote", 27 | iconPath: "icon.png" 28 | } 29 | public isolated client class Client { 30 | private final http:Client httpClient; 31 | 32 | # Initializes the connector. During initialization you can pass either http:BearerTokenConfig if you have a bearer 33 | # token or http:OAuth2RefreshTokenGrantConfig if you have OAuth tokens. 34 | # Create a Microsoft account and obtain tokens following 35 | # [this guide](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols) 36 | # 37 | # + config - Configuration required to initialize the client 38 | # + return - An error if initialization fails 39 | public isolated function init(ConnectionConfig config) returns error? { 40 | http:ClientConfiguration httpClientConfig = check config:constructHTTPClientConfig(config); 41 | self.httpClient = check new (BASE_URL, httpClientConfig); 42 | } 43 | 44 | // Notebooks 45 | 46 | # Creates a notebook. 47 | # 48 | # + noteBookName - Display name for notebook 49 | # + return - Notebook if successful or else an error 50 | @display {label: "Create Notebook"} 51 | remote isolated function createNotebook(@display {label: "Notebook Name"} string noteBookName) returns 52 | Notebook|error { 53 | string path = NOTEBOOKS_PATH; 54 | return check self.httpClient->post(path, {"displayName": noteBookName}, targetType = Notebook); 55 | } 56 | 57 | # Lists notebooks. 58 | # 59 | # + oDataQuery - Optional. OData Query. Example: "$top=2&$count=true". 60 | # For details, refer https://docs.microsoft.com/en-us/graph/query-parameters#odata-system-query-options 61 | # + return - Notebook[] if successful or else an error 62 | @display {label: "List Notebooks"} 63 | remote isolated function listNotebooks(@display {label: "OData Query"} string? oDataQuery = ()) 64 | returns Notebook[]|error { 65 | string path = NOTEBOOKS_PATH; 66 | if (oDataQuery is string) { 67 | path = path + QUESTION_MARK + oDataQuery; 68 | } 69 | http:Response response = check self.httpClient->get(path); 70 | return getNotebookArray(response); 71 | } 72 | 73 | # Gets a notebook. 74 | # 75 | # + notebookId - Notebook ID 76 | # + return - Notebook if successful or else an error 77 | @display {label: "Get Notebook"} 78 | remote isolated function getNotebook(@display {label: "Notebook ID"} string notebookId) returns Notebook|error { 79 | string path = NOTEBOOKS_PATH + SLASH + notebookId; 80 | return check self.httpClient->get(path, targetType = Notebook); 81 | } 82 | 83 | # Lists recent notebooks. 84 | # 85 | # + return - RecentNotebook[] if successful or else an error 86 | @display {label: "Get Recent Notebooks"} 87 | remote isolated function getRecentNotebooks() returns RecentNotebook[]|error { 88 | string path = NOTEBOOKS_PATH + "/getRecentNotebooks(includePersonalNotebooks=true)"; 89 | http:Response response = check self.httpClient->get(path); 90 | return getRecentNotebookArray(response); 91 | } 92 | 93 | // Sections 94 | 95 | # Lists sections. 96 | # 97 | # + notebookId - Notebook ID 98 | # + oDataQuery - Optional. OData Query. Example: "$top=2&$count=true". 99 | # For details, refer https://docs.microsoft.com/en-us/graph/query-parameters#odata-system-query-options 100 | # + return - Section[] if successful or else an error 101 | @display {label: "List Sections"} 102 | remote isolated function listSections(@display {label: "Notebook ID"} string notebookId, 103 | @display {label: "OData Query"} string? oDataQuery = ()) returns 104 | Section[]|error { 105 | string path = NOTEBOOKS_PATH + SLASH + notebookId + SECTIONS; 106 | if (oDataQuery is string) { 107 | path = path + QUESTION_MARK + oDataQuery; 108 | } 109 | http:Response response = check self.httpClient->get(path); 110 | return getSectionArray(response); 111 | } 112 | 113 | # Gets a section. 114 | # 115 | # + sectionId - Section ID 116 | # + return - Section if successful or else an error 117 | @display {label: "Get Section"} 118 | remote isolated function getSection(@display {label: "Section ID"} string sectionId) returns Section|error { 119 | string path = SECTIONS_PATH + sectionId; 120 | return check self.httpClient->get(path, targetType = Section); 121 | } 122 | 123 | # Creates a section. 124 | # 125 | # + notebookId - Notebook ID 126 | # + sectionName - Display name for the section 127 | # + return - Section if successful or else an error 128 | @display {label: "Create Section"} 129 | remote isolated function createSection(@display {label: "Notebook ID"} string notebookId, 130 | @display {label: "Section Name"} string sectionName) returns Section|error { 131 | string path = NOTEBOOKS_PATH + SLASH + notebookId + SECTIONS; 132 | return check self.httpClient->post(path, {displayName: sectionName}, targetType = Section); 133 | } 134 | 135 | // Section Groups 136 | 137 | # Lists section groups. 138 | # 139 | # + notebookId - Notebook ID 140 | # + oDataQuery - Optional. OData Query. Example: "$top=2&$count=true". 141 | # For details, refer https://docs.microsoft.com/en-us/graph/query-parameters#odata-system-query-options 142 | # + return - SectionGroup[] if successful or else an error 143 | @display {label: "List Section Groups"} 144 | remote isolated function listSectionGroups(@display {label: "Notebook ID"} string notebookId, 145 | @display {label: "OData Query"} string? oDataQuery = ()) returns 146 | SectionGroup[]|error { 147 | string path = NOTEBOOKS_PATH + SLASH + notebookId + SECTION_GROUPS; 148 | if (oDataQuery is string) { 149 | path = path + QUESTION_MARK + oDataQuery; 150 | } 151 | http:Response response = check self.httpClient->get(path); 152 | return getSectionGroupArray(response); 153 | } 154 | 155 | # Creates a section group. 156 | # 157 | # + notebookId - Notebook ID 158 | # + sectionGroupName - Display name for the section 159 | # + return - Section if successful or else an error 160 | @display {label: "Create Section Group"} 161 | remote isolated function createSectionGroup(@display {label: "Notebook ID"} string notebookId, 162 | @display {label: "Section Group Name"} string sectionGroupName) returns 163 | SectionGroup|error { 164 | string path = NOTEBOOKS_PATH + SLASH + notebookId + SECTION_GROUPS; 165 | return check self.httpClient->post(path, {displayName: sectionGroupName}, targetType = SectionGroup); 166 | } 167 | 168 | # Gets a section group. 169 | # 170 | # + sectionGroupId - Section group ID 171 | # + return - Section if successful or else an error 172 | @display {label: "Get Section Group"} 173 | remote isolated function getSectionGroup(@display {label: "Section Group ID"} string sectionGroupId) returns 174 | SectionGroup|error { 175 | string path = SECTION_GROUP_PATH + sectionGroupId; 176 | return check self.httpClient->get(path, targetType = SectionGroup); 177 | } 178 | 179 | # Creates a section in a section group. 180 | # 181 | # + sectionGroupId - Section group ID 182 | # + sectionName - Display name for the section 183 | # + return - Section if successful or else an error 184 | @display {label: "Create Section in SectionGroup"} 185 | remote isolated function createSectionInSectionGroup(@display {label: "Section Group ID"} string sectionGroupId, 186 | @display {label: "Section Name"} string sectionName) returns 187 | Section|error { 188 | string path = SECTION_GROUP_PATH + sectionGroupId + SECTIONS; 189 | return check self.httpClient->post(path, {displayName: sectionName}, targetType = Section); 190 | } 191 | 192 | // Pages 193 | 194 | # Lists pages of a section. 195 | # 196 | # + sectionId - Section ID 197 | # + oDataQuery - Optional. OData Query. Example: "$top=2&$count=true". 198 | # For details, refer https://docs.microsoft.com/en-us/graph/query-parameters#odata-system-query-options 199 | # + return - Page[] if successful or else an error 200 | @display {label: "List Pages"} 201 | remote isolated function listPages(@display {label: "Section ID"} string sectionId, 202 | @display {label: "OData Query"} string? oDataQuery = ()) returns Page[]|error { 203 | string path = SECTIONS_PATH + sectionId + PAGES; 204 | if (oDataQuery is string) { 205 | path = path + QUESTION_MARK + oDataQuery; 206 | } 207 | http:Response response = check self.httpClient->get(path); 208 | return getPagesArray(response); 209 | } 210 | 211 | # Gets a page. 212 | # 213 | # + pageId - Page ID 214 | # + return - Page if successful or else an error 215 | @display {label: "Get Page"} 216 | remote isolated function getPage(@display {label: "Page ID"} string pageId) returns Page|error { 217 | string path = PAGES_PATH + pageId; 218 | return check self.httpClient->get(path, targetType = Page); 219 | } 220 | 221 | # Creates a page. 222 | # 223 | # + sectionId - Section ID 224 | # + pageTitle - Page title 225 | # + pageBody - Page body 226 | # + return - Page if page creation is successful or else an error 227 | @display {label: "Create Page"} 228 | remote isolated function createPage(@display {label: "Section ID"} string sectionId, 229 | @display {label: "Page Title"} string pageTitle, 230 | @display {label: "Page Body"} string pageBody) returns Page|error { 231 | string path = SECTIONS_PATH + sectionId + PAGES; 232 | http:Request request = new(); 233 | string htmlContent = createHTMLContent(pageTitle, pageBody); 234 | request.setTextPayload(htmlContent); 235 | check request.setContentType("text/html"); 236 | return check self.httpClient->post(path, request, targetType = Page); 237 | } 238 | 239 | # Creates a page with HTML content. 240 | # 241 | # + sectionId - Section ID 242 | # + htmlContent - HTML Content 243 | # + return - Page if page creation is successful or else an error 244 | @display {label: "Create Page With HTML"} 245 | remote isolated function createPageWithHTML(@display {label: "Section ID"} string sectionId, 246 | @display {label: "HTML Content"} string htmlContent) returns Page|error { 247 | string path = SECTIONS_PATH + sectionId + PAGES; 248 | http:Request request = new(); 249 | request.setTextPayload(htmlContent); 250 | check request.setContentType("text/html"); 251 | return check self.httpClient->post(path, request, targetType = Page); 252 | } 253 | 254 | # Deletes a page. 255 | # 256 | # + pageId - Page ID 257 | # + return - `()` if the page deletion is successful or else an error if failed 258 | @display {label: "Delete Page"} 259 | remote isolated function deletePage(@display {label: "Page ID"} string pageId) returns error? { 260 | string path = PAGES_PATH + pageId; 261 | http:Response response = check self.httpClient->delete(path); 262 | _ = check handleResponse(response); 263 | } 264 | } 265 | --------------------------------------------------------------------------------