-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbluesky.h
More file actions
165 lines (144 loc) · 4.54 KB
/
Copy pathbluesky.h
File metadata and controls
165 lines (144 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2024 Brian J. Downs
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __BLUESKY_H
#define __BLUESKY_H
#include <stdlib.h>
#define BS_CLIENT_INIT_ERR_MEM 1
#define BS_CLIENT_INIT_ERR_AUTH 2
#define BS_CLIENT_INIT_ERR_JSON 3
/**
* Default response structure returned for each call to the API. Contains the
* API response, the response code, response size, any error code, and message
* if applicable.
*/
typedef struct {
char *resp;
char *err_msg;
size_t size;
long resp_code;
int err_code;
} bs_client_response_t;
/**
* Contains the errors returned for pagination validation.
*/
enum bs_client_pagination_errs {
BS_CLIENT_PAGINATION_ERR_OVER_LIMIT = 3
};
/**
* Structure used to pass pagination settings. The limit field will be ignored
* if the value is less than 50. The max value supported by the API is 100.
*/
typedef struct {
unsigned int limit;
char *cursor;
} bs_client_pagination_opts;
/**
* Initialize the library.
*/
int
bs_client_init(const char *handle, const char *app_password, char *error);
/**
* Free the memory used in the client response.
*/
void
bs_client_response_free(bs_client_response_t *res);
/**
* Creates a new post to the authenticated user's feed. The response
* memory needs to be freed by the caller.
*
* data argument must be JSON in the following format:
*
* {"$type": "app.bsky.feed.post",
* "text": "Hello World!",
* "createdAt": "2023-08-07T05:31:12.156888Z"}
*/
bs_client_response_t*
bs_client_post(const char *msg);
/**
* Retrieve the profile information for the given handle.
*/
bs_client_response_t*
bs_client_profile_get(const char *handle);
/**
* Retrieve the DID for the given handle.
*/
bs_client_response_t*
bs_client_resolve_handle(const char *handle);
/**
* Retrieve the follows for the given handle.
*/
bs_client_response_t*
bs_client_follows_get(const char *handle,
const bs_client_pagination_opts *opts);
/**
* Retrieve the followers for the given handle.
*/
bs_client_response_t*
bs_client_followers_get(const char *handle,
const bs_client_pagination_opts *opts);
/**
* Retrieve the profile preferences for the authenticated user.
*/
bs_client_response_t*
bs_client_profile_preferences();
/**
* Get the authenticated user's timeline. The JSON response has a field called
* "cursor". If this field is populated, there are more results to retrieve.
* The response memory needs to be freed by the caller.
*/
bs_client_response_t*
bs_client_timeline_get(const bs_client_pagination_opts *opts);
/**
* Retrieve posts from the given user DID.
*/
bs_client_response_t*
bs_client_author_feed_get(const char *did,
const bs_client_pagination_opts *opts);
/**
* Retrieve likes from the given user handle.
*/
bs_client_response_t*
bs_client_handle_likes_get(const char *handle,
const bs_client_pagination_opts *opts);
/**
* Retrieve likes for the given user at-uri. The at-uri needs to be in the
* following format: at://<did>
*/
bs_client_response_t*
bs_client_likes_get(const char *handle, const bs_client_pagination_opts *opts);
/**
* Free the memory used by the client.
*/
void
bs_client_free();
#endif /* __BLUESKY_H */
#ifdef __cplusplus
}
#endif