This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkibela.rb
64 lines (58 loc) · 1.56 KB
/
kibela.rb
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
# frozen_string_literal: true
require 'graphql/client'
require 'graphql/client/http'
require 'json'
require 'base64'
require_relative 'config'
class KibelaClient
HTTP = GraphQL::Client::HTTP.new("https://#{Config::KIBELA_TEAM_NAME}.kibe.la/api/v1") do
def headers(context)
{ "Authorization": "Bearer #{Config::KIBELA_ACCESS_TOKEN}",
"Accept": "application/json" }
end
end
Schema = GraphQL::Client.load_schema(HTTP)
Client = GraphQL::Client.new(schema: Schema, execute: HTTP)
NoteQuery = Client.parse <<-'GRAPHQL'
query($path: String!) {
note: noteFromPath(path: $path) {
author {
id
account
avatarImage {
url
}
url
}
id
title
url
publishedAt
summary: contentSummaryHtml
}
}
GRAPHQL
CommentQuery = Client.parse <<-'GRAPHQL'
query($id: ID!) {
comment: comment(id: $id) {
author {
id
account
avatarImage {
url
}
url
}
id
publishedAt
summary: contentSummaryHtml
}
}
GRAPHQL
def self.get_note path
Client.query(NoteQuery, variables: { path: path })&.data&.note
end
def self.get_comment id
Client.query(CommentQuery, variables: { id: Base64.strict_encode64("Comment/#{id}") })&.data&.comment
end
end