1 module twitter.api;
2 
3 import vibe.data.json;
4 
5 ///
6 struct TwitterCredentials
7 {
8     ///
9     string consumerKey;
10     ///
11     string consumerSecret;
12     ///
13     string accessToken;
14     ///
15     string accessTokenSecret;
16 }
17 
18 ///
19 struct TwitterUser
20 {
21     ///
22     bool verified;
23     ///
24     @optional string profile_background_image_url;
25     ///
26     string created_at;
27     ///
28     bool protected_;
29     ///
30     bool profile_background_tile;
31     ///
32     @optional bool live_following;
33     ///
34     bool following;
35     ///
36     long favourites_count;
37     ///
38     long id;
39     ///
40     bool notifications;
41     ///
42     bool contributors_enabled;
43     ///
44     long friends_count;
45     ///
46     string lang;
47     ///
48     string screen_name;
49     ///
50     string name;
51     ///
52     long followers_count;
53     ///
54     @optional string url;
55 
56     // is_translation_enabled":false,
57     // profile_banner_url":"https://pbs.twimg.com/profile_banners/2985037894/1519517845",
58     // profile_use_background_image":true,
59     // utc_offset":null,
60     // is_translator":false,
61     // profile_background_color":"1A1B1F",
62     // profile_text_color":"000000",
63     // default_profile":false,
64     // location":"Lake Arrowhead, CA - USA",
65     // time_zone":null,
66     // translator_type":"none",
67     // profile_background_image_url_https":"https://pbs.twimg.com/profile_background_images/610926403563859970/IW0XUTqt.jpg",
68     // statuses_count":5736,
69     // follow_request_sent":false,
70     // muting":false,
71     // has_extended_profile":false,
72     // profile_sidebar_fill_color":"000000",
73     // profile_link_color":"1B95E0",
74     // profile_sidebar_border_color":"000000",
75     // default_profile_image":false,
76     // geo_enabled":true,
77     // description":"Directory - helping you make the most of your stay in Lake Arrowhead, California. Promos & Coupons. Breaking News. info@LakeArrowhead.us http://LakeArrowhead.us",
78     // profile_image_url_https":"https://pbs.twimg.com/profile_images/967552520561213440/K1YyT64q_normal.jpg",
79     // listed_count":437,
80     // blocking":false,
81     // blocked_by":false,
82     // id_str":"2985037894",
83     // profile_image_url":"http://pbs.twimg.com/profile_images/967552520561213440/K1YyT64q_normal.jpg"
84 }
85 
86 ///
87 template CursoredList()
88 {
89     ///
90     string previous_cursor_str;
91     ///
92     string next_cursor_str;
93     ///
94     long previous_cursor;
95     ///
96     long next_cursor;
97 }
98 
99 ///
100 struct FollowersList
101 {
102     mixin CursoredList;
103     ///
104     TwitterUser[] users;
105 }
106 
107 ///
108 struct Status
109 {
110     ///
111     TwitterUser user;
112     ///
113     bool truncated;
114     ///
115     bool is_quote_status;
116     ///
117     string text;
118     ///
119     string id_str;
120     ///
121     string created_at;
122     ///
123     string lang;
124     ///
125     long retweet_count;
126     ///
127     long favorite_count;
128     ///
129     long id;
130     ///
131     bool retweeted;
132     ///
133     bool favorited;
134 }
135 
136 ///
137 struct SearchResult
138 {
139     ///
140     Status[] statuses;
141     ///
142     Json search_metadata;
143 }
144 
145 ///
146 struct IdsList
147 {
148     mixin CursoredList;
149     ///
150     ulong[] ids;
151 }
152 
153 ///
154 interface TwitterAPI
155 {
156     ///
157     FollowersList followers(string screen_name, long cursor = -1,
158             bool skip_status = true, bool include_user_entities = false);
159 
160     /// see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friends-ids
161     IdsList friendsIds(string screen_name, long cursor = -1);
162 
163     /// see https://developer.twitter.com/en/docs/developer-utilities/rate-limit-status/api-reference/get-application-rate_limit_status
164     Json appRateLimitStatus();
165 
166     ///
167     Status status(string status);
168 
169     ///
170     Status statusShow(long id);
171 
172     /// see https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets.html
173     SearchResult searchTweets(string q, string lang = null, int count = 15);
174 
175     /// see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/post-friendships-create
176     TwitterUser friendshipsCreate(ulong user_id);
177 
178     /// see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/post-friendships-destroy
179     TwitterUser friendshipsDestroy(ulong user_id);
180 }