Last active
May 1, 2020 13:45
-
-
Save ldclakmal/dee772771f9d31e749c0dbeed6cd9a85 to your computer and use it in GitHub Desktop.
Twitter Client in Ballerina
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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