Browse Source

Added support vor bookmarks (Glitch-Soc)

tastytea 1 week ago
parent
commit
8a0f709a6e
Signed by: tastytea <tastytea@tastytea.de> GPG Key ID: CFC39497F1B26E07
5 changed files with 72 additions and 4 deletions
  1. 3
    3
      README.md
  2. 55
    0
      examples/example17_bookmarks.cpp
  3. 3
    0
      src/api/get.cpp
  4. 6
    0
      src/api/post.cpp
  5. 5
    1
      src/mastodon-cpp.hpp

+ 3
- 3
README.md View File

@@ -262,9 +262,9 @@ Feature complete as of Mastodon 2.6.1
262 262
 
263 263
 * [x] max_toot_chars in /api/v1/instance
264 264
 
265
-* [ ] GET /api/v1/bookmarks
266
-* [ ] POST /api/v1/statuses/:id/bookmark
267
-* [ ] POST /api/v1/statuses/:id/underbookmark
265
+* [x] GET /api/v1/bookmarks
266
+* [x] POST /api/v1/statuses/:id/bookmark
267
+* [x] POST /api/v1/statuses/:id/unbookmark
268 268
 
269 269
 # Copyright
270 270
 

+ 55
- 0
examples/example17_bookmarks.cpp View File

@@ -0,0 +1,55 @@
1
+/*  This file is part of mastodon-cpp.
2
+ *  Print the first 20 characters from every bookmark (Glitch-Soc only).
3
+ */
4
+
5
+// Don't compile this if the Easy-interface is turned off
6
+#ifndef WITHOUT_EASY
7
+
8
+#include <iostream>
9
+#include <vector>
10
+#include <string>
11
+#include <cstdint>
12
+#ifdef MASTODON_CPP
13
+    #include "mastodon-cpp.hpp"
14
+    #include "easy/all.hpp"
15
+#else
16
+    #include <mastodon-cpp/mastodon-cpp.hpp>
17
+    #include <mastodon-cpp/easy/all.hpp>
18
+#endif
19
+
20
+using std::cout;
21
+using Mastodon::API;
22
+using Mastodon::Easy;
23
+
24
+int main(int argc, char *argv[])
25
+{
26
+    if (argc < 3)
27
+    {
28
+        std::cerr << "usage: " << argv[0] << " <instance> <access token>\n";
29
+        return 1;
30
+    }
31
+
32
+    Easy masto(argv[1], argv[2]);
33
+    std::string answer;
34
+    std::uint16_t ret;
35
+    ret = masto.get(API::v1::bookmarks, answer);
36
+
37
+    cout << "Return code: " << ret << '\n';
38
+
39
+    std::vector<string> statuses = Easy::json_array_to_vector(answer);
40
+    for (const string &json : statuses)
41
+    {
42
+        cout << Easy::Status(json).content().substr(0, 20) << '\n';
43
+    }
44
+
45
+    return 0;
46
+}
47
+
48
+#else
49
+#include <cstdio>
50
+int main()
51
+{
52
+    printf("mastodon-cpp was compiled without Easy support.\n");
53
+    return 255;
54
+}
55
+#endif  // WITHOUT_EASY

+ 3
- 0
src/api/get.cpp View File

@@ -147,6 +147,9 @@ const uint_fast16_t API::get(const Mastodon::API::v1 &call,
147 147
         case v1::endorsements:
148 148
             strcall = "/api/v1/endorsements";
149 149
             break;
150
+        case v1::bookmarks:
151
+            strcall = "/api/v1/bookmarks";
152
+            break;
150 153
         default:
151 154
             ttdebug << "ERROR: Invalid call.\n";
152 155
             return 11;

+ 6
- 0
src/api/post.cpp View File

@@ -122,6 +122,12 @@ const uint_fast16_t API::post(const Mastodon::API::v1 &call,
122 122
         case v1::accounts_id_unpin:
123 123
             strcall = "/api/v1/accounts/" + strid + "/unpin";
124 124
             break;
125
+        case v1::statuses_id_bookmark:
126
+            strcall = "/api/v1/statuses/" + strid + "/bookmark";
127
+            break;
128
+        case v1::statuses_id_unbookmark:
129
+            strcall = "/api/v1/statuses/" + strid + "/unbookmark";
130
+            break;
125 131
         default:
126 132
             ttdebug << "ERROR: Invalid call.\n";
127 133
             return 11;

+ 5
- 1
src/mastodon-cpp.hpp View File

@@ -265,7 +265,11 @@ public:
265 265
         streaming_hashtag,
266 266
         streaming_list,
267 267
         // Push
268
-        push_subscription
268
+        push_subscription,
269
+        // Glitch-Soc
270
+        bookmarks,
271
+        statuses_id_bookmark,
272
+        statuses_id_unbookmark
269 273
     };
270 274
 
271 275
     /*!

Loading…
Cancel
Save