@@ -7,52 +7,10 @@ const Promise = require('bluebird'),
7
7
localUtils = require ( './utils' ) ,
8
8
models = require ( '../../models' ) ,
9
9
common = require ( '../../lib/common' ) ,
10
- request = require ( '../../lib/request' ) ,
11
10
docName = 'webhooks' ;
12
11
13
12
let webhooks ;
14
13
15
- function makeRequest ( webhook , payload , options ) {
16
- let event = webhook . get ( 'event' ) ,
17
- targetUrl = webhook . get ( 'target_url' ) ,
18
- webhookId = webhook . get ( 'id' ) ,
19
- reqPayload = JSON . stringify ( payload ) ;
20
-
21
- common . logging . info ( 'webhook.trigger' , event , targetUrl ) ;
22
-
23
- request ( targetUrl , {
24
- body : reqPayload ,
25
- headers : {
26
- 'Content-Length' : Buffer . byteLength ( reqPayload ) ,
27
- 'Content-Type' : 'application/json'
28
- } ,
29
- timeout : 2 * 1000 ,
30
- retries : 5
31
- } ) . catch ( ( err ) => {
32
- // when a webhook responds with a 410 Gone response we should remove the hook
33
- if ( err . statusCode === 410 ) {
34
- common . logging . info ( 'webhook.destroy (410 response)' , event , targetUrl ) ;
35
- return models . Webhook . destroy ( { id : webhookId } , options ) ;
36
- }
37
-
38
- common . logging . error ( new common . errors . GhostError ( {
39
- err : err ,
40
- context : {
41
- id : webhookId ,
42
- event : event ,
43
- target_url : targetUrl ,
44
- payload : payload
45
- }
46
- } ) ) ;
47
- } ) ;
48
- }
49
-
50
- function makeRequests ( webhooksCollection , payload , options ) {
51
- _ . each ( webhooksCollection . models , ( webhook ) => {
52
- makeRequest ( webhook , payload , options ) ;
53
- } ) ;
54
- }
55
-
56
14
/**
57
15
* ## Webhook API Methods
58
16
*
@@ -130,21 +88,6 @@ webhooks = {
130
88
] ;
131
89
132
90
// Pipeline calls each task passing the result of one to be the arguments for the next
133
- return pipeline ( tasks , options ) ;
134
- } ,
135
-
136
- trigger ( event , payload , options ) {
137
- let tasks ;
138
-
139
- function doQuery ( options ) {
140
- return models . Webhook . findAllByEvent ( event , options ) ;
141
- }
142
-
143
- tasks = [
144
- doQuery ,
145
- _ . partialRight ( makeRequests , payload , options )
146
- ] ;
147
-
148
91
return pipeline ( tasks , options ) ;
149
92
}
150
93
} ;
0 commit comments