diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 17301a6..f120218 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -147,6 +147,15 @@ dependencies = [ {org = "ballerina", name = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + [[package]] org = "ballerina" name = "lang.int" @@ -205,6 +214,9 @@ dependencies = [ {org = "ballerina", name = "lang.value"}, {org = "ballerina", name = "observe"} ] +modules = [ + {org = "ballerina", packageName = "log", moduleName = "log"} +] [[package]] org = "ballerina" @@ -245,6 +257,9 @@ dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"} ] +modules = [ + {org = "ballerina", packageName = "os", moduleName = "os"} +] [[package]] org = "ballerina" @@ -255,6 +270,20 @@ dependencies = [ {org = "ballerina", name = "time"} ] +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + [[package]] org = "ballerina" name = "time" @@ -262,6 +291,9 @@ version = "2.4.0" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] +modules = [ + {org = "ballerina", packageName = "time", moduleName = "time"} +] [[package]] org = "ballerina" @@ -293,6 +325,10 @@ version = "4.0.0" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "http"}, + {org = "ballerina", name = "log"}, + {org = "ballerina", name = "os"}, + {org = "ballerina", name = "test"}, + {org = "ballerina", name = "time"}, {org = "ballerina", name = "url"}, {org = "ballerinai", name = "observe"} ] diff --git a/ballerina/tests/README.md b/ballerina/tests/README.md new file mode 100644 index 0000000..39fe177 --- /dev/null +++ b/ballerina/tests/README.md @@ -0,0 +1,85 @@ +# Running Tests + +## Prerequisites +You need a bearer token and a Access token from twittter(X) developer account. + +To do this, refer to [Ballerina Twitter Connector](https://github.com/ballerina-platform/module-ballerinax-twitter/blob/main/ballerina/Module.md). + +And You need Find Your User ID For run some of the tests. +Via This Website you can find it [Twitter ID Finder](https://twiteridfinder.com/). + +# Running Tests + +There are two test environments for running the Twitter(X) connector tests. The default test environment is the mock server for Twitter API. The other test environment is the actual Twitter (X) API. + +You can run the tests in either of these environments and each has its own compatible set of tests. + + Test Groups | Environment +-------------|--------------------------------------------------- + mock_tests | Mock server for Twitter(X) API (Defualt Environment) + live_tests | Twitter(X) API + +## Running Tests in the Mock Server + +To execute the tests on the mock server, ensure that the `IS_LIVE_SERVER` environment variable is either set to `false` or unset before initiating the tests. + +This environment variable can be configured within the `Config.toml` file located in the tests directory or specified as an environmental variable. + +#### Using a Config.toml File + +Create a `Config.toml` file in the tests directory and the following content: + +```toml +isLiveServer = false +``` + +#### Using Environment Variables + +Alternatively, you can set your authentication credentials as environment variables: +If you are using linux or mac, you can use following method: +```bash + export IS_LIVE_SERVER=false +``` +If you are using Windows you can use following method: +```bash + set IS_LIVE_SERVER=false +``` +Then, run the following command to run the tests: + +```bash + ./gradlew clean test +``` + +## Running Tests Against Twitter(X) Live API + +#### Using a Config.toml File + +Create a `Config.toml` file in the tests directory and add your authentication credentials a + +```toml + isLiveServer = true + token = "" + userId = "" +``` + +#### Using Environment Variables + +Alternatively, you can set your authentication credentials as environment variables: +If you are using linux or mac, you can use following method: +```bash + export IS_LIVE_SERVER=true + export TWITTER_TOKEN ="" + export TWITTER_USER_ID ="" +``` + +If you are using Windows you can use following method: +```bash + setx IS_LIVE_SERVER true + setx TWITTER_TOKEN + setx TWITTER_USER_ID +``` +Then, run the following command to run the tests: + +```bash + ./gradlew clean test +``` diff --git a/ballerina/tests/mock_service.bal b/ballerina/tests/mock_service.bal new file mode 100644 index 0000000..01184f3 --- /dev/null +++ b/ballerina/tests/mock_service.bal @@ -0,0 +1,208 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/http; +import ballerina/log; + +listener http:Listener httpListener = new (9090); + +http:Service mockService = service object { + + # Remove a bookmarked Post + # + # + id - The ID of the authenticated source User whose bookmark is to be removed. + # + tweet_id - The ID of the Post that the source User is removing from bookmarks. + # + return - returns can be any of following types + # http:Ok (The request has succeeded.) + # http:Response (The request has failed.) + resource function delete users/[UserIdMatchesAuthenticatedUser id]/bookmarks/[TweetId tweet_id]() returns BookmarkMutationResponse|http:Response { + return { + "data":{"bookmarked":false} + }; + } + + # Causes the User (in the path) to unlike the specified Post + # + # + id - The ID of the authenticated source User that is requesting to unlike the Post. + # + tweet_id - The ID of the Post that the User is requesting to unlike. + # + return - returns can be any of following types + # http:Ok (The request has succeeded.) + # http:Response (The request has failed.) + resource function delete users/[UserIdMatchesAuthenticatedUser id]/likes/[TweetId tweet_id]() returns UsersLikesDeleteResponse|http:Response { + return { + "data":{"liked":false} + }; + } + + # Causes the User (in the path) to unretweet the specified Post + # + # + id - The ID of the authenticated source User that is requesting to repost the Post. + # + source_tweet_id - The ID of the Post that the User is requesting to unretweet. + # + return - returns can be any of following types + # http:Ok (The request has succeeded.) + # http:Response (The request has failed.) + resource function delete users/[UserIdMatchesAuthenticatedUser id]/retweets/[TweetId source_tweet_id]() returns UsersRetweetsDeleteResponse|http:Response { + return { + "data":{"retweeted":false} + }; + } + + # Unfollow User + # + # + source_user_id - The ID of the authenticated source User that is requesting to unfollow the target User. + # + target_user_id - The ID of the User that the source User is requesting to unfollow. + # + return - returns can be any of following types + # http:Ok (The request has succeeded.) + # http:Response (The request has failed.) + resource function delete users/[UserIdMatchesAuthenticatedUser source_user_id]/following/[UserId target_user_id]() returns UsersFollowingDeleteResponse|http:Response { + return { + "data":{"following":false} + }; + } + + # Unmute User by User ID + # + # + source_user_id - The ID of the authenticated source User that is requesting to unmute the target User. + # + target_user_id - The ID of the User that the source User is requesting to unmute. + # + return - returns can be any of following types + # http:Ok (The request has succeeded.) + # http:Response (The request has failed.) + resource function delete users/[UserIdMatchesAuthenticatedUser source_user_id]/muting/[UserId target_user_id]() returns MuteUserMutationResponse|http:Response { + return { + "data":{"muting":false} + }; + } + + # Post lookup by Post ID + # + # + id - A single Post ID. + # + tweet\.fields - A comma separated list of Tweet fields to display. + # + expansions - A comma separated list of fields to expand. + # + media\.fields - A comma separated list of Media fields to display. + # + poll\.fields - A comma separated list of Poll fields to display. + # + user\.fields - A comma separated list of User fields to display. + # + place\.fields - A comma separated list of Place fields to display. + # + return - returns can be any of following types + # http:Ok (The request has succeeded.) + # http:Response (The request has failed.) + resource function get tweets/[TweetId id](("attachments"|"author_id"|"card_uri"|"context_annotations"|"conversation_id"|"created_at"|"edit_controls"|"edit_history_tweet_ids"|"entities"|"geo"|"id"|"in_reply_to_user_id"|"lang"|"non_public_metrics"|"note_tweet"|"organic_metrics"|"possibly_sensitive"|"promoted_metrics"|"public_metrics"|"referenced_tweets"|"reply_settings"|"scopes"|"source"|"text"|"username"|"withheld")[]? tweet\.fields, ("attachments.media_keys"|"attachments.media_source_tweet"|"attachments.poll_ids"|"author_id"|"edit_history_tweet_ids"|"entities.mentions.username"|"geo.place_id"|"in_reply_to_user_id"|"entities.note.mentions.username"|"referenced_tweets.id"|"referenced_tweets.id.author_id"|"author_screen_name")[]? expansions, ("alt_text"|"duration_ms"|"height"|"media_key"|"non_public_metrics"|"organic_metrics"|"preview_image_url"|"promoted_metrics"|"public_metrics"|"type"|"url"|"variants"|"width")[]? media\.fields, ("duration_minutes"|"end_datetime"|"id"|"options"|"voting_status")[]? poll\.fields, ("connection_status"|"created_at"|"description"|"entities"|"id"|"location"|"most_recent_tweet_id"|"name"|"pinned_tweet_id"|"profile_image_url"|"protected"|"public_metrics"|"receives_your_dm"|"subscription_type"|"url"|"username"|"verified"|"verified_type"|"withheld")[]? user\.fields, ("contained_within"|"country"|"country_code"|"full_name"|"geo"|"id"|"name"|"place_type")[]? place\.fields) returns Get2TweetsIdResponse|http:Response { + return { + "data":{"edit_history_tweet_ids":["1806286701704462623"],"id":"1806286701704462623","text":"aasbcascbasjbc"} + }; + } + + resource function get users/'by/username/[string username](("connection_status"|"created_at"|"description"|"entities"|"id"|"location"|"most_recent_tweet_id"|"name"|"pinned_tweet_id"|"profile_image_url"|"protected"|"public_metrics"|"receives_your_dm"|"subscription_type"|"url"|"username"|"verified"|"verified_type"|"withheld")[]? user\.fields, ("most_recent_tweet_id"|"pinned_tweet_id")[]? expansions, ("attachments"|"author_id"|"card_uri"|"context_annotations"|"conversation_id"|"created_at"|"edit_controls"|"edit_history_tweet_ids"|"entities"|"geo"|"id"|"in_reply_to_user_id"|"lang"|"non_public_metrics"|"note_tweet"|"organic_metrics"|"possibly_sensitive"|"promoted_metrics"|"public_metrics"|"referenced_tweets"|"reply_settings"|"scopes"|"source"|"text"|"username"|"withheld")[]? tweet\.fields) returns Get2UsersByUsernameUsernameResponse|http:Response { + return { + "data":{"id":"350224247","name":"Kumar Sangakkara","username":"KumarSanga2"} + }; + } + + # Creation of a Post + # + # + return - returns can be any of following types + # http:Created (The request has succeeded.) + # http:Response (The request has failed.) + resource function post tweets(@http:Payload TweetCreateRequest payload) returns TweetCreateResponse|http:Response { + return { + "data":{"id":"1807808193139204482","text":"Twitter Test at[1719850035,0.227505100]","edit_history_tweet_ids":["1807808193139204482"]} + }; + } + + # Add Post to Bookmarks + # + # + id - The ID of the authenticated source User for whom to add bookmarks. + # + return - returns can be any of following types + # http:Ok (The request has succeeded.) + # http:Response (The request has failed.) + resource function post users/[UserIdMatchesAuthenticatedUser id]/bookmarks(@http:Payload BookmarkAddRequest payload) returns BookmarkMutationResponse|http:Response { + return { + "data":{"bookmarked":true} + }; + } + + # Follow User + # + # + id - The ID of the authenticated source User that is requesting to follow the target User. + # + return - returns can be any of following types + # http:Ok (The request has succeeded.) + # http:Response (The request has failed.) + resource function post users/[UserIdMatchesAuthenticatedUser id]/following(@http:Payload UsersFollowingCreateRequest payload) returns UsersFollowingCreateResponse|http:Response { + return { + "data":{"following":true,"pending_follow":false} + }; + } + + # Causes the User (in the path) to like the specified Post + # + # + id - The ID of the authenticated source User that is requesting to like the Post. + # + return - returns can be any of following types + # http:Ok (The request has succeeded.) + # http:Response (The request has failed.) + resource function post users/[UserIdMatchesAuthenticatedUser id]/likes(@http:Payload UsersLikesCreateRequest payload) returns UsersLikesCreateResponse|http:Response { + return { + "data":{"liked":true} + }; + } + + # Mute User by User ID. + # + # + id - The ID of the authenticated source User that is requesting to mute the target User. + # + return - returns can be any of following types + # http:Ok (The request has succeeded.) + # http:Response (The request has failed.) + resource function post users/[UserIdMatchesAuthenticatedUser id]/muting(@http:Payload MuteUserRequest payload) returns MuteUserMutationResponse|http:Response { + return { + "data":{"muting":true} + }; + } + + # Causes the User (in the path) to repost the specified Post. + # + # + id - The ID of the authenticated source User that is requesting to repost the Post. + # + return - returns can be any of following types + # http:Ok (The request has succeeded.) + # http:Response (The request has failed.) + resource function post users/[UserIdMatchesAuthenticatedUser id]/retweets(@http:Payload UsersRetweetsCreateRequest payload) returns UsersRetweetsCreateResponse|http:Response { + return { + "data":{"retweeted":true,"rest_id":"1807808194787590411"} + }; + } + + # User lookup by IDs + # + # + ids - A list of User IDs, comma-separated. You can specify up to 100 IDs. + # + user\.fields - A comma separated list of User fields to display. + # + expansions - A comma separated list of fields to expand. + # + tweet\.fields - A comma separated list of Tweet fields to display. + # + return - returns can be any of following types + # http:Ok (The request has succeeded.) + # http:Response (The request has failed.) + resource function get users(UserId[] ids, ("connection_status"|"created_at"|"description"|"entities"|"id"|"location"|"most_recent_tweet_id"|"name"|"pinned_tweet_id"|"profile_image_url"|"protected"|"public_metrics"|"receives_your_dm"|"subscription_type"|"url"|"username"|"verified"|"verified_type"|"withheld")[]? user\.fields, ("most_recent_tweet_id"|"pinned_tweet_id")[]? expansions, ("attachments"|"author_id"|"card_uri"|"context_annotations"|"conversation_id"|"created_at"|"edit_controls"|"edit_history_tweet_ids"|"entities"|"geo"|"id"|"in_reply_to_user_id"|"lang"|"non_public_metrics"|"note_tweet"|"organic_metrics"|"possibly_sensitive"|"promoted_metrics"|"public_metrics"|"referenced_tweets"|"reply_settings"|"scopes"|"source"|"text"|"username"|"withheld")[]? tweet\.fields) returns Get2UsersResponse|http:Response { + return { + "data":[{"id":"350224247","name":"Kumar Sangakkara","username":"KumarSanga2"}] + }; + } +}; + +function init() returns error? { + if isLiveServer { + log:printInfo("Skiping mock server initialization as the tests are running on live server"); + return; + } + log:printInfo("Initiating mock server"); + check httpListener.attach(mockService, "/"); + check httpListener.'start(); +} \ No newline at end of file diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal new file mode 100644 index 0000000..52a01d7 --- /dev/null +++ b/ballerina/tests/test.bal @@ -0,0 +1,174 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/test; +import ballerina/time; +import ballerina/os; + +configurable boolean isLiveServer = os:getEnv("IS_LIVE_SERVER") == "true"; +configurable string userId = isLiveServer ? os:getEnv("TWITTER_USER_ID") : "test"; +configurable string token = isLiveServer ? os:getEnv("TWITTER_TOKEN") : "test"; +configurable string serviceUrl = isLiveServer ? "https://api.twitter.com/2" : "http://localhost:9090"; + +ConnectionConfig config = {auth: {token}}; +final Client twitter = check new Client(config, serviceUrl); + +@test:Config { + groups: ["live_tests", "mock_tests"] +} +isolated function testPostTweet() returns error? { + time:Utc utc = time:utcNow(); + string tweetText = "Twitter Test at " + utc.toString(); + TweetCreateResponse response = check twitter->/tweets.post(payload = { + text: tweetText + }); + test:assertTrue(response?.data !is ()); + test:assertTrue(response?.errors is ()); +} + +@test:Config { + groups: ["live_tests", "mock_tests"] +} +isolated function testgetUserIdByUseName() returns error? { + Get2UsersByUsernameUsernameResponse response = check twitter->/users/'by/username/["KumarSanga2"]; + test:assertTrue(response?.data !is ()); + test:assertTrue(response?.errors is ()); +} + +@test:Config { + groups: ["live_tests", "mock_tests"] +} +isolated function testUserLikeAPost() returns error? { + UsersLikesCreateResponse response = check twitter->/users/[userId]/likes.post( + payload = { + tweet_id:"1806286701704462623" + } + ); + test:assertTrue(response?.data !is ()); + test:assertTrue(response?.errors is ()); +} + +@test:Config { + groups: ["live_tests", "mock_tests"] +} +isolated function testUserUnlikeAPost() returns error? { + UsersLikesDeleteResponse response = check twitter->/users/[userId]/likes/["1806286701704462623"].delete(); + test:assertTrue(response?.data !is ()); + test:assertTrue(response?.errors is ()); +} + +@test:Config { + groups: ["live_tests", "mock_tests"] +} +isolated function testPostLookup() returns error? { + Get2TweetsIdResponse response = check twitter->/tweets/["1806286701704462623"](); + test:assertTrue(response?.data !is ()); + test:assertTrue(response?.errors is ()); +} + +@test:Config { + groups: ["live_tests", "mock_tests"] +} +isolated function testBookmarkPost() returns error? { + BookmarkMutationResponse response = check twitter->/users/[userId]/bookmarks.post( + payload = {tweet_id: "1806286701704462623"} + ); + test:assertTrue(response?.data !is ()); + test:assertTrue(response?.errors is ()); +} + +@test:Config { + groups: ["live_tests", "mock_tests"] +} +isolated function testBookmarkDelete() returns error? { + BookmarkMutationResponse response = check twitter->/users/[userId]/bookmarks/["1806286701704462623"].delete(); + test:assertTrue(response?.data !is ()); + test:assertTrue(response?.errors is ()); +} + +@test:Config { + groups: ["live_tests", "mock_tests"] +} +isolated function testRetweet() returns error? { + UsersRetweetsCreateResponse response = check twitter->/users/[userId]/retweets.post( + payload = {tweet_id: "1806286701704462623"} + ); + test:assertTrue(response?.data !is ()); + test:assertTrue(response?.errors is ()); +} + +@test:Config { + groups: ["live_tests", "mock_tests"] +} +isolated function testDeleteRetweet() returns error? { + UsersRetweetsDeleteResponse response = check twitter->/users/[userId]/retweets/["1806286701704462623"].delete(); + test:assertTrue(response?.data !is ()); + test:assertTrue(response?.errors is ()); +} + +@test:Config { + groups: ["live_tests", "mock_tests"] +} +isolated function testFollowSpecificUser() returns error? { + UsersFollowingCreateResponse response = check twitter->/users/[userId]/following.post( + payload={ + target_user_id:"1803011651249278976" + } + ); + test:assertTrue(response?.data !is ()); + test:assertTrue(response?.errors is ()); +} + +@test:Config { + groups: ["live_tests", "mock_tests"] +} +isolated function testUnfollowSpecificUser() returns error? { + UsersFollowingDeleteResponse response = check twitter->/users/[userId]/following/["1803011651249278976"].delete(); + test:assertTrue(response?.data !is ()); + test:assertTrue(response?.errors is ()); +} + +@test:Config { + groups: ["live_tests", "mock_tests"] +} +isolated function muteSpecificUser() returns error? { + MuteUserMutationResponse response = check twitter->/users/[userId]/muting.post( + payload={ + target_user_id:"1803011651249278976" + } + ); + test:assertTrue(response?.data !is ()); + test:assertTrue(response?.errors is ()); +} + +@test:Config { + groups: ["live_tests", "mock_tests"] +} + +isolated function unmuteSpecificUser() returns error? { + MuteUserMutationResponse response = check twitter->/users/[userId]/muting/["1803011651249278976"].delete(); + test:assertTrue(response?.data !is ()); + test:assertTrue(response?.errors is ()); +} + +@test:Config { + groups: ["live_tests", "mock_tests"] +} +isolated function findSpecificUser() returns error? { + Get2UsersResponse response = check twitter->/users(ids = ["1803011651249278976"]); + test:assertTrue(response?.data !is ()); + test:assertTrue(response?.errors is ()); +} \ No newline at end of file diff --git a/examples/build.gradle b/examples/build.gradle deleted file mode 100644 index 551424f..0000000 --- a/examples/build.gradle +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) - * - * WSO2 LLC. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -apply plugin: 'java-library' - -description = 'Ballerina - Twitter Examples' - -def filePath = project.fileTree("${project.projectDir}") -def examples = filePath.matching { - include("**/*.bal") - exclude("**/deprecated/**/*.bal") -} - -task testExamples { - dependsOn ":${project.packageName}-ballerina:build" - - doLast { - examples.each { example -> executeBalCommand ("run ${example}", "${project.rootDir}") } - } -} - -task buildExamples { - dependsOn ":${project.packageName}-ballerina:build" - - gradle.taskGraph.whenReady { graph -> - if (graph.hasTask(":${project.packageName}-examples:test")) { - buildExamples.enabled = false - } else { - testExamples.enabled = false - } - } - doLast { - // TODO: Enabled --offline due to a bug in pulling incorrect versions from the central repository. - examples.each { example -> executeBalCommand ("build --offline ${example}", "${project.rootDir}") } - } -} - -test.dependsOn testExamples -build.dependsOn buildExamples diff --git a/examples/getFollowers.bal b/examples/getFollowers.bal deleted file mode 100644 index a380f44..0000000 --- a/examples/getFollowers.bal +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/twitter; - -configurable string apiKey = ?; -configurable string apiSecret = ?; -configurable string accessToken = ?; -configurable string accessTokenSecret = ?; - -public function main() returns error? { - - // Add the Twitter credentials as the Configuration - twitter:ConnectionConfig configuration = { - apiKey: apiKey, - apiSecret: apiSecret, - accessToken: accessToken, - accessTokenSecret: accessTokenSecret - }; - - twitter:Client twitterClient = check new (configuration); - - // Set the User ID - int USER_ID = 0; - - twitter:User[] followers = check twitterClient->getFollowers(USER_ID); - log:printInfo("Followers: " + followers.toString()); -} diff --git a/examples/getLastTenTweets.bal b/examples/getLastTenTweets.bal deleted file mode 100644 index a611a24..0000000 --- a/examples/getLastTenTweets.bal +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/twitter; - -configurable string apiKey = ?; -configurable string apiSecret = ?; -configurable string accessToken = ?; -configurable string accessTokenSecret = ?; - -public function main() returns error? { - - // Add the Twitter credentials as the Configuration - twitter:ConnectionConfig configuration = { - apiKey: apiKey, - apiSecret: apiSecret, - accessToken: accessToken, - accessTokenSecret: accessTokenSecret - }; - - twitter:Client twitterClient = check new (configuration); - - twitter:Tweet[] response = check twitterClient->getLast10Tweets(); - foreach twitter:Tweet tweet in response { - log:printInfo(tweet.toString()); - } -} diff --git a/examples/retweet.bal b/examples/retweet.bal deleted file mode 100644 index 5b2e942..0000000 --- a/examples/retweet.bal +++ /dev/null @@ -1,44 +0,0 @@ - // Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/twitter; - -configurable string apiKey = ?; -configurable string apiSecret = ?; -configurable string accessToken = ?; -configurable string accessTokenSecret = ?; - -public function main() returns error? { - - // Add the Twitter credentials as the Configuration - twitter:ConnectionConfig configuration = { - apiKey: apiKey, - apiSecret: apiSecret, - accessToken: accessToken, - accessTokenSecret: accessTokenSecret - }; - - twitter:Client twitterClient = check new (configuration); - - string tweetContent = "Retweet"; - - // Set the Tweet ID - int TWEET_ID = 0; - - twitter:Tweet response = check twitterClient->retweet(TWEET_ID); - log:printInfo("Retweeted a Tweet : " + response.toString()); -} diff --git a/examples/tweet.bal b/examples/tweet.bal deleted file mode 100644 index 269c01f..0000000 --- a/examples/tweet.bal +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/log; -import ballerinax/twitter; - -configurable string apiKey = ?; -configurable string apiSecret = ?; -configurable string accessToken = ?; -configurable string accessTokenSecret = ?; - -public function main() returns error? { - - // Add the Twitter credentials as the Configuration - twitter:ConnectionConfig configuration = { - apiKey: apiKey, - apiSecret: apiSecret, - accessToken: accessToken, - accessTokenSecret: accessTokenSecret - }; - - twitter:Client twitterClient = check new (configuration); - - string tweetContent = "Learn Ballerina"; - string link = "https://ballerina.io/learn/by-example/introduction/"; - - twitter:Tweet response = check twitterClient->tweet(tweetContent, link); - log:printInfo("Tweet posted in timeline: " + response.toString()); -} diff --git a/gradle.properties b/gradle.properties index c20a9ad..fa452de 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,5 +9,5 @@ downloadPluginVersion=5.4.0 releasePluginVersion=2.8.0 testngVersion=7.6.1 eclipseLsp4jVersion=0.12.0 -ballerinaGradlePluginVersion=2.2.4 +ballerinaGradlePluginVersion=2.2.6 ballerinaLangVersion=2201.9.0