Module: Misskey

Defined in:
lib/misskey.rb

Constant Summary collapse

@@token =
nil
@@instanceURI =
nil

Instance Method Summary collapse

Instance Method Details

#authObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/misskey.rb', line 37

def auth
  def token
    return @@token
  end

  def token=(tkn)
    @@token = tkn
  end

  def instanceURI
    return @@instanceURI
  end

  def instanceURI=(uri)
    @@instanceURI = uri
  end
end

#connectObject



197
198
199
# File 'lib/misskey.rb', line 197

def connect
  WS.c
end

#create(noteContent, visibility = "public", localOnly = false, cw = "") ⇒ Object



66
67
68
# File 'lib/misskey.rb', line 66

def create noteContent, visibility = "public", localOnly = false, cw = ""
  Creates.created noteContent, visibility = "public", localOnly = false, cw = ""
end

#debugObject



55
56
57
58
59
60
61
62
63
# File 'lib/misskey.rb', line 55

def debug
  def debugging
    return @@debugging
  end

  def debugging=(bool)
    @@debugging = bool
  end
end

#debuggingObject



56
57
58
# File 'lib/misskey.rb', line 56

def debugging
  return @@debugging
end

#debugging=(bool) ⇒ Object



60
61
62
# File 'lib/misskey.rb', line 60

def debugging=(bool)
  @@debugging = bool
end

#getOnlineUsersCountObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/misskey.rb', line 117

def getOnlineUsersCount
  instance = "https://#{Misskey.auth.instanceURI}/api/get-online-users-count"
  postJSON = <<EOF
{
"Bah": "bahbooey"
}
EOF

  request = HTTParty.post(
    instance,
    body: postJSON,
    headers: {
      "Content-Type" => "application/json"
    }
  )

  return JSON.parse request.body
end

#iObject



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/misskey.rb', line 155

def i 
  instance = "https://#{Misskey.auth.instanceURI}/api/i"
  postJSON = <<EOF
{
"Bah": "bahbooey"
}
EOF

  request = HTTParty.post(
    instance,
    body: postJSON,
    headers: {
      "Content-Type" => "application/json",
      "Authorization" => "Bearer #{Misskey.auth.token}"
    }
  )
  
  def notifications limit = 10
    instance = "https://#{Misskey.auth.instanceURI}/api/i/notifications"

    postJSON = <<EOF
{
"limit": #{limit}
}
EOF

    request = HTTParty.post(
      instance,
      body: postJSON,
      headers: { 
        "Content-Type" => "application/json",
        "Authorization" => "Bearer #{Misskey.auth.token}"
      }
    )

    return JSON.parse request.body
  end

  return JSON.parse request.body
end

#instanceURIObject



46
47
48
# File 'lib/misskey.rb', line 46

def instanceURI
  return @@instanceURI
end

#instanceURI=(uri) ⇒ Object



50
51
52
# File 'lib/misskey.rb', line 50

def instanceURI=(uri)
  @@instanceURI = uri
end

#notesObject



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
# File 'lib/misskey.rb', line 65

def notes
  def create noteContent, visibility = "public", localOnly = false, cw = ""
    Creates.created noteContent, visibility = "public", localOnly = false, cw = ""
  end

  def reply replyId, noteContent, visibility = "public", localOnly = false, cw = ""
    Creates.replied replyId, noteContent, visibility = "public", localOnly = false, cw = ""
  end

  def timeline limit = 10
    instance = "https://#{Misskey.auth.instanceURI}/api/notes/timeline"

    postJSON = <<EOF
{
"limit": #{limit}
}
EOF

    request = HTTParty.post(
      instance,
      body: postJSON,
      headers: { 
        "Content-Type" => "application/json",
        "Authorization" => "Bearer #{Misskey.auth.token}"
      }
    )

    return JSON.parse request.body
  end

  def show id 
    instance = "https://#{Misskey.auth.instanceURI}/api/notes/show"

    postJSON = <<EOF
{
"noteId": "#{id}"
}
EOF

    request = HTTParty.post(
      instance,
      body: postJSON,
      headers: { 
        "Content-Type" => "application/json",
        "Authorization" => "Bearer #{Misskey.auth.token}"
      }
    )

    return JSON.parse request.body
  end
end

#notificationsObject



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/misskey.rb', line 172

def notifications limit = 10
  instance = "https://#{Misskey.auth.instanceURI}/api/i/notifications"

  postJSON = <<EOF
{
  "limit": #{limit}
}
EOF

  request = HTTParty.post(
    instance,
    body: postJSON,
    headers: { 
      "Content-Type" => "application/json",
      "Authorization" => "Bearer #{Misskey.auth.token}"
    }
  )

  return JSON.parse request.body
end

#onMention(&block) ⇒ Object



202
203
204
# File 'lib/misskey.rb', line 202

def onMention &block
  WS.n.oM block
end

#onMentionOrReply(&block) ⇒ Object



226
227
228
# File 'lib/misskey.rb', line 226

def onMentionOrReply &block
  WS.n.oMOR block
end

#onNotification(&block) ⇒ Object



214
215
216
# File 'lib/misskey.rb', line 214

def onNotification &block
  WS.n.oN block
end

#onQuote(&block) ⇒ Object



218
219
220
# File 'lib/misskey.rb', line 218

def onQuote &block
  WS.n.oQ block
end

#onReaction(&block) ⇒ Object



206
207
208
# File 'lib/misskey.rb', line 206

def onReaction &block
  WS.n.oR block
end

#onRenote(&block) ⇒ Object



210
211
212
# File 'lib/misskey.rb', line 210

def onRenote &block
  WS.n.oRe block
end

#onReply(&block) ⇒ Object



222
223
224
# File 'lib/misskey.rb', line 222

def onReply &block
  WS.n.oRep block
end

#reply(replyId, noteContent, visibility = "public", localOnly = false, cw = "") ⇒ Object



70
71
72
# File 'lib/misskey.rb', line 70

def reply replyId, noteContent, visibility = "public", localOnly = false, cw = ""
  Creates.replied replyId, noteContent, visibility = "public", localOnly = false, cw = ""
end

#serverInfoObject



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/misskey.rb', line 136

def serverInfo
  instance = "https://#{Misskey.auth.instanceURI}/api/server-info"
  postJSON = <<EOF
{
"Bah": "bahbooey"
}
EOF

  request = HTTParty.post(
    instance,
    body: postJSON,
    headers: {
      "Content-Type" => "application/json"
    }
  )

  return JSON.parse request.body
end

#show(id) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/misskey.rb', line 16

def show userId
  instance = "https://#{Misskey.auth.instanceURI}/api/users/show"

  postJSON = <<EOF
{
  "userId": "#{userId}"
}
EOF
  
  request = HTTParty.post(
    instance,
    body: postJSON,
    headers: { 
      "Content-Type" => "application/json"
    }
  )

  return JSON.parse request.body
end

#timeline(limit = 10) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/misskey.rb', line 74

def timeline limit = 10
  instance = "https://#{Misskey.auth.instanceURI}/api/notes/timeline"

  postJSON = <<EOF
{
  "limit": #{limit}
}
EOF
  
  request = HTTParty.post(
    instance,
    body: postJSON,
    headers: { 
      "Content-Type" => "application/json",
      "Authorization" => "Bearer #{Misskey.auth.token}"
    }
  )

  return JSON.parse request.body
end

#tokenObject



38
39
40
# File 'lib/misskey.rb', line 38

def token
  return @@token
end

#token=(tkn) ⇒ Object



42
43
44
# File 'lib/misskey.rb', line 42

def token=(tkn)
  @@token = tkn
end

#usersObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/misskey.rb', line 15

def users 
  def show userId
    instance = "https://#{Misskey.auth.instanceURI}/api/users/show"

    postJSON = <<EOF
{
"userId": "#{userId}"
}
EOF

    request = HTTParty.post(
      instance,
      body: postJSON,
      headers: { 
        "Content-Type" => "application/json"
      }
    )

    return JSON.parse request.body
  end
end

#websocketObject



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/misskey.rb', line 196

def websocket
  def connect
    WS.c
  end

  def notifications
    def onMention &block
      WS.n.oM block
    end

    def onReaction &block
      WS.n.oR block
    end

    def onRenote &block
      WS.n.oRe block
    end

    def onNotification &block
      WS.n.oN block
    end

    def onQuote &block
      WS.n.oQ block
    end

    def onReply &block
      WS.n.oRep block
    end

    def onMentionOrReply &block
      WS.n.oMOR block
    end
  end
end