-
Notifications
You must be signed in to change notification settings - Fork 218
Custom Queries
We are trying hard to make every feature as easy as a single line of code. But obviously there are time when what you want to do is not yet implemented in the library.
Yet, to simplify your life we have created the TwitterAccessor
class. This will allow you to perform any action possible in the Twitter library by specifying a simple query!
Let's see how this works!
When performing a query, you can specify a type which should be a DTO (Data Transfer Object). These objects defined in the library have very little to no logic. Their only goal is to convert the result from Twitter into an object.
When you have a DTO object, you can create a "concrete" object by using the associated static class and its GenerateFromDTO
method.
// Example to create an IUser from an IUserDTO
var user = User.GenerateUserFromDTO(userDTO);
// GET from simple query
var userDTO = TwitterAccessor.ExecuteGETQuery<IUserDTO>("https://api.twitter.com/1.1/users/show.json?screen_name=tweetinviapi");
// POST from simple query
var tweetDTO = TwitterAccessor.ExecutePOSTQuery<ITweetDTO>("https://api.twitter.com/1.1/statuses/update.json?status=hello");
var userJson = TwitterAccessor.TwitterAccessor.ExecuteJsonGETQuery("https://api.twitter.com/1.1/users/show.json?screen_name=tweetinviapi");
Cursor queries allow developer to access a high number of results by iterating over cursors. For example if a user has more than 5000 followers you will need to use a cursor query to access all the followers of that user.
The library contains the method ExecuteCursorGETQuery<T1, T2>
which takes 2 types :
- T1 : DTO type that will be available as a result of the query
- T2 : A type implementing IBaseCursorQueryDTO that will allow Tweetinvi to access the information it needs to automatically iterate over the results sent by Twitter.