misskey 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +331 -1
- data/lib/misskey.rb +21 -27
- data/lib/websocket.rb +7 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2c4008ac213ee40bf57c9755520e34002d91fa6f730e7fd0d316a71ec4d25aa5
|
|
4
|
+
data.tar.gz: aff4ba972e9212006a148beacda5673a0b689c9302194f748a65dba610ffb613
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 802c89d8a5645c7d4b4f7b40896be93a1b786227e8e7d90ddd3ca71e4489d8140d46388239b1e9a57bd67b5f06f9124861e47b3ff8f7d0bc8a31cfa41fa4c389
|
|
7
|
+
data.tar.gz: 7ccdc70381209c61f3165586bd99db68b5a0e99bb6eb73813a714099d28cc62c990efc0ebc2a22c651528879d9096ab47a1d2e469500d4b6a2af02d7358984be
|
data/README.md
CHANGED
|
@@ -1,3 +1,333 @@
|
|
|
1
1
|
# Misskey.rb
|
|
2
2
|
|
|
3
|
-
A Ruby module for interacting with the Misskey API
|
|
3
|
+
A Ruby module for interacting with the Misskey API. Releases hosted on [Rubygems](https://rubygems.org/gems/misskey). **This is not affiliated with Syuilo in any way!!**
|
|
4
|
+
|
|
5
|
+
## Installation :neofox_science:
|
|
6
|
+
Either add it to your Gemfile:
|
|
7
|
+
```Gemfile
|
|
8
|
+
gem "misskey"
|
|
9
|
+
```
|
|
10
|
+
or install it directly with Gem:
|
|
11
|
+
```sh
|
|
12
|
+
gem install misskey
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Contributing :neofox_laptop:
|
|
16
|
+
Because it would be really difficult for me to implement *every* Misskey API feature, I would really appreciate contributions!
|
|
17
|
+
|
|
18
|
+
When contributing please make sure to follow these guidelines. These may change as time goes on:
|
|
19
|
+
|
|
20
|
+
1) No LLM-generated commits please! Vibecoded software tends to get really messy and introduce more issues than it solves. Also everything around LLMs are highly unethical and I don't want to support that. Thanks!
|
|
21
|
+
|
|
22
|
+
2) Please do not create multiple functions that do the same thing.
|
|
23
|
+
|
|
24
|
+
3) Follow common sense.
|
|
25
|
+
|
|
26
|
+
Thank you! :neofox_heart:
|
|
27
|
+
|
|
28
|
+
## Using :neofox_notice:
|
|
29
|
+
I didn't have the energy to make a real wiki for this and I have no idea how to use the Rubygems documentation thingy so I just stuck it in one big readme. I am deeply sorry about this :neofox_googly_shocked:
|
|
30
|
+
|
|
31
|
+
Like I said in the contributing guide, this doesn't implement every Misskey API feature and if you want to see a feature added it would mean a lot to me if you could contribute! Thanks :neofox_heart:
|
|
32
|
+
|
|
33
|
+
All responses from the API are automatically parsed from JSON to a Ruby Array so you shouldn't need to worry about that.
|
|
34
|
+
|
|
35
|
+
### Authentication **(REQUIRED!!!)**
|
|
36
|
+
#### `Misskey.auth.instanceURI`
|
|
37
|
+
This sets the instance URI that your client will connect to. This and `Misskey.auth.token` are **required** when using Misskey.rb.
|
|
38
|
+
|
|
39
|
+
This can be used like a variable. You can change it or access it at any time. See some examples below:
|
|
40
|
+
|
|
41
|
+
Changing the value:
|
|
42
|
+
```ruby
|
|
43
|
+
require "misskey"
|
|
44
|
+
|
|
45
|
+
Misskey.auth.instanceURI = "sharkey.skydevs.me"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Calling the value:
|
|
49
|
+
```ruby
|
|
50
|
+
require "misskey"
|
|
51
|
+
|
|
52
|
+
Misskey.auth.instanceURI = "sharkey.skydevs.me"
|
|
53
|
+
|
|
54
|
+
# Getting the value
|
|
55
|
+
puts Misskey.auth.instanceURI
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Pretty simple :neofox_floof_happy:
|
|
59
|
+
|
|
60
|
+
#### `Misskey.auth.token`
|
|
61
|
+
This sets the API key/token that your client will connect to. This and `Misskey.auth.instanceURI` are **required** when using Misskey.rb.
|
|
62
|
+
|
|
63
|
+
This can be used like a variable. You can change it or access it at any time. See some examples below:
|
|
64
|
+
|
|
65
|
+
Changing the value:
|
|
66
|
+
```ruby
|
|
67
|
+
require "misskey"
|
|
68
|
+
|
|
69
|
+
Misskey.auth.token = "blahblahtokenweeewooooooo"
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Calling the value:
|
|
73
|
+
```ruby
|
|
74
|
+
require "misskey"
|
|
75
|
+
|
|
76
|
+
Misskey.auth.token = "wafwaftokenaaaaaa"
|
|
77
|
+
|
|
78
|
+
# Getting the value
|
|
79
|
+
puts Misskey.auth.token
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
You can also use this in pair with the `dotenv` module:
|
|
83
|
+
```ruby
|
|
84
|
+
require "misskey"
|
|
85
|
+
require "dotenv"
|
|
86
|
+
|
|
87
|
+
Dotenv.load "./.env"
|
|
88
|
+
Misskey.auth.token = ENV["APIKey"]
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Also pretty simple :neofox_floof_happy:
|
|
92
|
+
|
|
93
|
+
### Notes
|
|
94
|
+
#### `Misskey.notes.create`
|
|
95
|
+
Creates a note.
|
|
96
|
+
|
|
97
|
+
Order of arguments are as follows: `noteContent` also known as the body text (REQUIRED), `visibility`, `localonly`, `cw` also known as a content warning.
|
|
98
|
+
|
|
99
|
+
Visibility options include: `public`, `home`, `followers`, and `specified`. `specified` is also known as a direct note or private message.
|
|
100
|
+
|
|
101
|
+
Some examples:
|
|
102
|
+
```ruby
|
|
103
|
+
require "misskey"
|
|
104
|
+
|
|
105
|
+
Misskey.auth.token = "tokenwaaaaaaa"
|
|
106
|
+
Misskey.auth.instanceURI = "sharkey.skydevs.me"
|
|
107
|
+
|
|
108
|
+
Misskey.notes.create "Hello world!! :neofox_floof:"
|
|
109
|
+
```
|
|
110
|
+
It will automatically convert things like ":neofox_floof:" to their respective emojis as seen above.
|
|
111
|
+
```ruby
|
|
112
|
+
require "misskey"
|
|
113
|
+
|
|
114
|
+
Misskey.auth.token = "tokenwaaaaaaa"
|
|
115
|
+
Misskey.auth.instanceURI = "sharkey.skydevs.me"
|
|
116
|
+
|
|
117
|
+
Misskey.notes.create "Hello there, this is a home note.", "home"
|
|
118
|
+
```
|
|
119
|
+
The example above shows a client creating a note with the visibility "home"
|
|
120
|
+
```ruby
|
|
121
|
+
require "misskey"
|
|
122
|
+
|
|
123
|
+
Misskey.auth.token = "tokenwaaaaaaa"
|
|
124
|
+
Misskey.auth.instanceURI = "sharkey.skydevs.me"
|
|
125
|
+
|
|
126
|
+
Misskey.notes.create "Hi this is local!", "public", true
|
|
127
|
+
```
|
|
128
|
+
The example above shows a client creating a public local (aka defederated) note.
|
|
129
|
+
```ruby
|
|
130
|
+
require "misskey"
|
|
131
|
+
|
|
132
|
+
Misskey.auth.token = "tokenwaaaaaaa"
|
|
133
|
+
Misskey.auth.instanceURI = "sharkey.skydevs.me"
|
|
134
|
+
|
|
135
|
+
Misskey.notes.create "Hi this is local and features a content warning!", "public", true, "Holy moly it's a post by me wow beware"
|
|
136
|
+
```
|
|
137
|
+
As the note body suggests, this is a local note that has a content warning.
|
|
138
|
+
|
|
139
|
+
You may refer to the [Misskey API docs](https://sharkey.skydevs.me/api-doc#tag/notes/POST/notes/create) for more info.
|
|
140
|
+
|
|
141
|
+
#### `Misskey.notes.create.reply`
|
|
142
|
+
Very similar to `Misskey.notes.create` except it features a new required argument called `replyId`.
|
|
143
|
+
|
|
144
|
+
Arguments for this are as follows: `replyId` (REQUIRED), `noteContent` (REQUIRED), visibility, localOnly, cw
|
|
145
|
+
|
|
146
|
+
An example:
|
|
147
|
+
```ruby
|
|
148
|
+
require "misskey"
|
|
149
|
+
|
|
150
|
+
Misskey.auth.token = "tokenwaaaaaaa"
|
|
151
|
+
Misskey.auth.instanceURI = "sharkey.skydevs.me"
|
|
152
|
+
|
|
153
|
+
Misskey.notes.create.reply "someReplyId", "Hello there, this is a reply."
|
|
154
|
+
```
|
|
155
|
+
You may refer to the [Misskey API docs](https://sharkey.skydevs.me/api-doc#tag/notes/POST/notes/create) for more info.
|
|
156
|
+
|
|
157
|
+
#### `Misskey.notes.timeline`
|
|
158
|
+
Retrieves the home timeline of the currently logged-in user I believe? Not too sure because I only tested it on a dummy account that doesn't follow anyone.
|
|
159
|
+
|
|
160
|
+
There is one optional argument which is `limit`. As the name suggests, it sets a limit to how many notes should be retrieved. By default it's set to 10.
|
|
161
|
+
|
|
162
|
+
Here's an example:
|
|
163
|
+
```ruby
|
|
164
|
+
require "misskey"
|
|
165
|
+
|
|
166
|
+
Misskey.auth.token = "tokenwaaaaaaa"
|
|
167
|
+
Misskey.auth.instanceURI = "sharkey.skydevs.me"
|
|
168
|
+
|
|
169
|
+
puts Misskey.notes.timeline
|
|
170
|
+
```
|
|
171
|
+
You may refer to the [Misskey API docs](https://sharkey.skydevs.me/api-doc#tag/notes/POST/notes/timeline) for more info.
|
|
172
|
+
|
|
173
|
+
### `Misskey.getOnlineUsersCount`
|
|
174
|
+
Pretty self-explanatory, gets the number of users online. Using it is really simple, here's an example:
|
|
175
|
+
```ruby
|
|
176
|
+
require "misskey"
|
|
177
|
+
|
|
178
|
+
Misskey.auth.token = "tokenwaaaaaaa"
|
|
179
|
+
Misskey.auth.instanceURI = "sharkey.skydevs.me"
|
|
180
|
+
|
|
181
|
+
puts "There are #{Misskey.getOnlineUsersCount} user(s) online right now!"
|
|
182
|
+
```
|
|
183
|
+
Slightly more complicated example:
|
|
184
|
+
```ruby
|
|
185
|
+
require "misskey"
|
|
186
|
+
|
|
187
|
+
Misskey.auth.token = "tokenwaaaaaaa"
|
|
188
|
+
Misskey.auth.instanceURI = "sharkey.skydevs.me"
|
|
189
|
+
|
|
190
|
+
case Misskey.getOnlineUserscount.to_i
|
|
191
|
+
when 0
|
|
192
|
+
puts "There are no users online :("
|
|
193
|
+
when 1
|
|
194
|
+
puts "There is 1 user online."
|
|
195
|
+
when > 1
|
|
196
|
+
puts "There are #{Misskey.getOnlineUserscount} users online"
|
|
197
|
+
end
|
|
198
|
+
```
|
|
199
|
+
You may refer to the [Misskey API docs](https://sharkey.skydevs.me/api-doc#tag/meta/POST/get-online-users-count) for more info.
|
|
200
|
+
|
|
201
|
+
### `Misskey.serverInfo`
|
|
202
|
+
Retrieves the instance/server information. Example:
|
|
203
|
+
```ruby
|
|
204
|
+
require "misskey"
|
|
205
|
+
|
|
206
|
+
Misskey.auth.token = "tokenwaaaaaaa"
|
|
207
|
+
Misskey.auth.instanceURI = "sharkey.skydevs.me"
|
|
208
|
+
|
|
209
|
+
puts Misskey.serverInfo
|
|
210
|
+
```
|
|
211
|
+
You may refer to the [Misskey API docs](https://sharkey.skydevs.me/api-doc#tag/meta/POST/server-info) for more info.
|
|
212
|
+
|
|
213
|
+
### `Misskey.i`
|
|
214
|
+
Retrieves the information about the currently logged-in user. Example:
|
|
215
|
+
```ruby
|
|
216
|
+
require "misskey"
|
|
217
|
+
|
|
218
|
+
Misskey.auth.token = "tokenwaaaaaaa"
|
|
219
|
+
Misskey.auth.instanceURI = "sharkey.skydevs.me"
|
|
220
|
+
|
|
221
|
+
puts Misskey.i
|
|
222
|
+
```
|
|
223
|
+
You may refer to the [Misskey API docs](https://sharkey.skydevs.me/api-doc#tag/account/POST/i) for more info.
|
|
224
|
+
|
|
225
|
+
#### `Misskey.i.notifications`
|
|
226
|
+
Retrieves the currently logged-in user's notifications. Has one argument which is `limit`. By default, `limit` is set to 10. Here's an example
|
|
227
|
+
```ruby
|
|
228
|
+
require "misskey"
|
|
229
|
+
|
|
230
|
+
Misskey.auth.token = "tokenwaaaaaaa"
|
|
231
|
+
Misskey.auth.instanceURI = "sharkey.skydevs.me"
|
|
232
|
+
|
|
233
|
+
puts Misskey.i.notifications
|
|
234
|
+
```
|
|
235
|
+
You may refer to the [Misskey API docs](https://sharkey.skydevs.me/api-doc#tag/account/POST/i/notifications) for more info.
|
|
236
|
+
|
|
237
|
+
### Websockets!! (THis is my favorite thing about this library :neofox_floof_cute:)
|
|
238
|
+
#### `Misskey.websocket.connect`
|
|
239
|
+
Connects your client to Misskey via the websocket protocol. Automatically runs in a separate thread. There is no documentation on websockets in the Misskey API docs but the JSON data it gives is in the same structure as doing a normal request to their documented API.
|
|
240
|
+
|
|
241
|
+
#### Notifications
|
|
242
|
+
##### `Misskey.websocket.notifications.onMention`
|
|
243
|
+
Used with a block; runs said block with an argument contianing the message when you recieve a mention notification.
|
|
244
|
+
|
|
245
|
+
Example:
|
|
246
|
+
```ruby
|
|
247
|
+
require "misskey"
|
|
248
|
+
|
|
249
|
+
Misskey.auth.token = "tokenwaaaaaaa"
|
|
250
|
+
Misskey.auth.instanceURI = "sharkey.skydevs.me"
|
|
251
|
+
|
|
252
|
+
Misskey.websocket.connect
|
|
253
|
+
|
|
254
|
+
Misskey.websocket.notifications.onMention do |message|
|
|
255
|
+
puts message
|
|
256
|
+
end
|
|
257
|
+
```
|
|
258
|
+
In this example, `puts message` will print the message JSON data in the terminal when it recieves a mention.
|
|
259
|
+
|
|
260
|
+
##### `Misskey.websocket.notifications.onReaction`
|
|
261
|
+
Used with a block; runs said block with an argument contianing the message when you recieve a reaction notification.
|
|
262
|
+
|
|
263
|
+
Example:
|
|
264
|
+
```ruby
|
|
265
|
+
require "misskey"
|
|
266
|
+
|
|
267
|
+
Misskey.auth.token = "tokenwaaaaaaa"
|
|
268
|
+
Misskey.auth.instanceURI = "sharkey.skydevs.me"
|
|
269
|
+
|
|
270
|
+
Misskey.websocket.connect
|
|
271
|
+
|
|
272
|
+
Misskey.websocket.notifications.onReaction do |message|
|
|
273
|
+
puts message
|
|
274
|
+
end
|
|
275
|
+
```
|
|
276
|
+
In this example, `puts message` will print the message JSON data in the terminal when it recieves a reaction.
|
|
277
|
+
|
|
278
|
+
##### `Misskey.websocket.notifications.onRenote`
|
|
279
|
+
Used with a block; runs said block with an argument contianing the message when you recieve a renote notification.
|
|
280
|
+
|
|
281
|
+
Example:
|
|
282
|
+
```ruby
|
|
283
|
+
require "misskey"
|
|
284
|
+
|
|
285
|
+
Misskey.auth.token = "tokenwaaaaaaa"
|
|
286
|
+
Misskey.auth.instanceURI = "sharkey.skydevs.me"
|
|
287
|
+
|
|
288
|
+
Misskey.websocket.connect
|
|
289
|
+
|
|
290
|
+
Misskey.websocket.notifications.onRenote do |message|
|
|
291
|
+
puts message
|
|
292
|
+
end
|
|
293
|
+
```
|
|
294
|
+
In this example, `puts message` will print the message JSON data in the terminal when it recieves a renote.
|
|
295
|
+
|
|
296
|
+
##### `Misskey.websocket.notifications.onNotification`
|
|
297
|
+
Used with a block; runs said block with an argument contianing the message when you recieve a notification.
|
|
298
|
+
|
|
299
|
+
Example:
|
|
300
|
+
```ruby
|
|
301
|
+
require "misskey"
|
|
302
|
+
|
|
303
|
+
Misskey.auth.token = "tokenwaaaaaaa"
|
|
304
|
+
Misskey.auth.instanceURI = "sharkey.skydevs.me"
|
|
305
|
+
|
|
306
|
+
Misskey.websocket.connect
|
|
307
|
+
|
|
308
|
+
Misskey.websocket.notifications.onNotification do |message|
|
|
309
|
+
puts message
|
|
310
|
+
end
|
|
311
|
+
```
|
|
312
|
+
In this example, `puts message` will print the message JSON data in the terminal when it recieves a notification.
|
|
313
|
+
|
|
314
|
+
##### `Misskey.websocket.notifications.onQuote`
|
|
315
|
+
Used with a block; runs said block with an argument contianing the message when you recieve a quote notification.
|
|
316
|
+
|
|
317
|
+
Example:
|
|
318
|
+
```ruby
|
|
319
|
+
require "misskey"
|
|
320
|
+
|
|
321
|
+
Misskey.auth.token = "tokenwaaaaaaa"
|
|
322
|
+
Misskey.auth.instanceURI = "sharkey.skydevs.me"
|
|
323
|
+
|
|
324
|
+
Misskey.websocket.connect
|
|
325
|
+
|
|
326
|
+
Misskey.websocket.notifications.onQuote do |message|
|
|
327
|
+
puts message
|
|
328
|
+
end
|
|
329
|
+
```
|
|
330
|
+
In this example, `puts message` will print the message JSON data in the terminal when it recieves a quote.
|
|
331
|
+
|
|
332
|
+
## That's all!
|
|
333
|
+
Those are all the features currently implemented, but don't worry, more will be added as time goes on :neofox_heart:
|
data/lib/misskey.rb
CHANGED
|
@@ -11,12 +11,6 @@ include WS
|
|
|
11
11
|
module Misskey
|
|
12
12
|
@@token = nil
|
|
13
13
|
@@instanceURI = nil
|
|
14
|
-
@@onMentionDo = [false, nil]
|
|
15
|
-
@@debugging = false
|
|
16
|
-
@@onReactionDo = [false, nil]
|
|
17
|
-
@@onRenoteDo = [false, nil]
|
|
18
|
-
@@onNotificationDo = [false, nil]
|
|
19
|
-
@@onQuoteDo = [false, nil]
|
|
20
14
|
|
|
21
15
|
def auth
|
|
22
16
|
def token
|
|
@@ -54,6 +48,27 @@ module Misskey
|
|
|
54
48
|
Creates.created.reply replyId, noteContent, visibility = "public", localOnly = false, cw = ""
|
|
55
49
|
end
|
|
56
50
|
end
|
|
51
|
+
|
|
52
|
+
def timeline limit = 10
|
|
53
|
+
instance = "https://#{Misskey.auth.instanceURI}/api/notes/timeline"
|
|
54
|
+
|
|
55
|
+
postJSON = <<EOF
|
|
56
|
+
{
|
|
57
|
+
"limit": #{limit}
|
|
58
|
+
}
|
|
59
|
+
EOF
|
|
60
|
+
|
|
61
|
+
request = HTTParty.post(
|
|
62
|
+
instance,
|
|
63
|
+
body: postJSON,
|
|
64
|
+
headers: {
|
|
65
|
+
"Content-Type" => "application/json",
|
|
66
|
+
"Authorization" => "Bearer #{Misskey.auth.token}"
|
|
67
|
+
}
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
return JSON.parse request.body
|
|
71
|
+
end
|
|
57
72
|
end
|
|
58
73
|
|
|
59
74
|
def getOnlineUsersCount
|
|
@@ -110,27 +125,6 @@ EOF
|
|
|
110
125
|
"Authorization" => "Bearer #{Misskey.auth.token}"
|
|
111
126
|
}
|
|
112
127
|
)
|
|
113
|
-
|
|
114
|
-
def timeline limit = 100
|
|
115
|
-
instance = "https://#{Misskey.auth.instanceURI}/api/notes/timeline"
|
|
116
|
-
|
|
117
|
-
postJSON = <<EOF
|
|
118
|
-
{
|
|
119
|
-
"limit": #{limit}
|
|
120
|
-
}
|
|
121
|
-
EOF
|
|
122
|
-
|
|
123
|
-
request = HTTParty.post(
|
|
124
|
-
instance,
|
|
125
|
-
body: postJSON,
|
|
126
|
-
headers: {
|
|
127
|
-
"Content-Type" => "application/json",
|
|
128
|
-
"Authorization" => "Bearer #{Misskey.auth.token}"
|
|
129
|
-
}
|
|
130
|
-
)
|
|
131
|
-
|
|
132
|
-
return JSON.parse request.body
|
|
133
|
-
end
|
|
134
128
|
|
|
135
129
|
def notifications limit = 10
|
|
136
130
|
instance = "https://#{Misskey.auth.instanceURI}/api/i/notifications"
|
data/lib/websocket.rb
CHANGED