Skip to content

Instantly share code, notes, and snippets.

@ldclakmal
Last active May 1, 2020 13:45
Show Gist options
  • Save ldclakmal/dee772771f9d31e749c0dbeed6cd9a85 to your computer and use it in GitHub Desktop.
Save ldclakmal/dee772771f9d31e749c0dbeed6cd9a85 to your computer and use it in GitHub Desktop.
Twitter Client in Ballerina
import ballerina/encoding;
import ballerina/http;
# The Twitter client object.
public type Client client object {
http:Client twitterClient;
Credential twitterCredential;
public function __init(Configuration twitterConfig) {
self.twitterClient = new(TWITTER_API_URL, twitterConfig.clientConfig);
self.twitterCredential = {
accessToken: twitterConfig.accessToken,
accessTokenSecret: twitterConfig.accessTokenSecret,
consumerKey: twitterConfig.consumerKey,
consumerSecret: twitterConfig.consumerSecret
};
}
public remote function tweet(string status) returns @tainted Status|error {
// Build the HTTP request with the authentication information required by Twitter REST API.
// Call the REST API to tweet.
// Get the result of the API invocation.
// If the API invocation is success, build the `Status` record and return.
// Else, return a meaningful error.
}
};
type Credential record {
string accessToken;
string accessTokenSecret;
string consumerKey;
string consumerSecret;
};
public type Configuration record {
string accessToken;
string accessTokenSecret;
string consumerKey;
string consumerSecret;
http:ClientConfiguration clientConfig = {};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment