Class: Qiita::Team::Services::Hooks::Webhook
Constant Summary
Concerns::HttpClient::DEFAULT_ADAPTER, Concerns::HttpClient::DEFAULT_HEADERS, Concerns::HttpClient::TIMEOUT
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
human_attribute_name, render_form
#name
#marked_for_destruction?, #to_hash
#handle
Constructor Details
#initialize(hash) ⇒ Webhook
Returns a new instance of Webhook.
31
32
33
34
35
36
|
# File 'lib/qiita/team/services/hooks/webhook.rb', line 31
def initialize(hash)
unless hash.key?("token")
hash = hash.dup.merge("token" => self.class.generate_token)
end
super(hash)
end
|
Class Method Details
.generate_token ⇒ String
26
27
28
|
# File 'lib/qiita/team/services/hooks/webhook.rb', line 26
def self.generate_token
SecureRandom.base64(20)
end
|
.service_name ⇒ Object
Note:
Override Base.service_name.
21
22
23
|
# File 'lib/qiita/team/services/hooks/webhook.rb', line 21
def self.service_name
"Webhook"
end
|
Instance Method Details
77
78
79
80
81
82
83
84
|
# File 'lib/qiita/team/services/hooks/webhook.rb', line 77
def (event)
send_hook(
action: "created",
model: "comment",
comment: event.resource,
item: event.item,
)
end
|
97
98
99
100
101
102
103
104
|
# File 'lib/qiita/team/services/hooks/webhook.rb', line 97
def (event)
send_hook(
action: "destroyed",
model: "comment",
comment: event.resource,
item: event.item,
)
end
|
87
88
89
90
91
92
93
94
|
# File 'lib/qiita/team/services/hooks/webhook.rb', line 87
def (event)
send_hook(
action: "updated",
model: "comment",
comment: event.resource,
item: event.item,
)
end
|
#item_created(event) ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'lib/qiita/team/services/hooks/webhook.rb', line 47
def item_created(event)
send_hook(
action: "created",
model: "item",
item: event.resource,
user: event.user,
)
end
|
#item_destroyed(event) ⇒ Object
68
69
70
71
72
73
74
|
# File 'lib/qiita/team/services/hooks/webhook.rb', line 68
def item_destroyed(event)
send_hook(
action: "destroyed",
model: "item",
item: event.resource,
)
end
|
#item_updated(event) ⇒ Object
57
58
59
60
61
62
63
64
65
|
# File 'lib/qiita/team/services/hooks/webhook.rb', line 57
def item_updated(event)
send_hook(
action: "updated",
model: "item",
message: event.resource.message,
item: event.resource,
user: event.user,
)
end
|
#ping ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/qiita/team/services/hooks/webhook.rb', line 38
def ping
send_hook(
action: "requested",
message: "ping",
model: "ping",
)
end
|
107
108
109
110
111
112
113
114
|
# File 'lib/qiita/team/services/hooks/webhook.rb', line 107
def (event)
send_hook(
action: "created",
model: "comment",
comment: event.resource,
item: event.project,
)
end
|
127
128
129
130
131
132
133
134
|
# File 'lib/qiita/team/services/hooks/webhook.rb', line 127
def (event)
send_hook(
action: "destroyed",
model: "comment",
comment: event.resource,
item: event.project,
)
end
|
117
118
119
120
121
122
123
124
|
# File 'lib/qiita/team/services/hooks/webhook.rb', line 117
def (event)
send_hook(
action: "updated",
model: "comment",
comment: event.resource,
item: event.project,
)
end
|
#project_created(event) ⇒ Object
155
156
157
158
159
160
161
162
|
# File 'lib/qiita/team/services/hooks/webhook.rb', line 155
def project_created(event)
send_hook(
action: "created",
model: "project",
project: event.resource,
user: event.user,
)
end
|
#project_destroyed(event) ⇒ Object
176
177
178
179
180
181
182
|
# File 'lib/qiita/team/services/hooks/webhook.rb', line 176
def project_destroyed(event)
send_hook(
action: "destroyed",
model: "project",
project: event.resource,
)
end
|
#project_updated(event) ⇒ Object
165
166
167
168
169
170
171
172
173
|
# File 'lib/qiita/team/services/hooks/webhook.rb', line 165
def project_updated(event)
send_hook(
action: "updated",
model: "project",
message: event.resource.message,
project: event.resource,
user: event.user,
)
end
|
#team_member_added(event) ⇒ Object
137
138
139
140
141
142
143
|
# File 'lib/qiita/team/services/hooks/webhook.rb', line 137
def team_member_added(event)
send_hook(
action: "added",
model: "member",
user: event.resource,
)
end
|
#team_member_removed(event) ⇒ Object
146
147
148
149
150
151
152
|
# File 'lib/qiita/team/services/hooks/webhook.rb', line 146
def team_member_removed(event)
send_hook(
action: "removed",
model: "member",
user: event.resource,
)
end
|