2015-11-27 13:36:42 +01:00
|
|
|
'use strict';
|
|
|
|
|
2016-06-14 16:53:18 +02:00
|
|
|
import request from '../utils/request';
|
2015-11-27 13:36:42 +01:00
|
|
|
|
|
|
|
import WebhookActions from '../actions/webhook_actions';
|
|
|
|
|
|
|
|
|
|
|
|
const WebhookSource = {
|
|
|
|
lookupWebhooks: {
|
|
|
|
remote() {
|
2016-06-14 16:53:18 +02:00
|
|
|
return request('webhooks');
|
2015-11-27 13:36:42 +01:00
|
|
|
},
|
2016-01-15 13:55:58 +01:00
|
|
|
|
2015-11-27 13:36:42 +01:00
|
|
|
local(state) {
|
2016-01-15 13:55:58 +01:00
|
|
|
return !Object.keys(state.webhooks).length ? state : {};
|
2015-11-27 13:36:42 +01:00
|
|
|
},
|
2016-01-15 13:55:58 +01:00
|
|
|
|
2015-11-27 13:36:42 +01:00
|
|
|
success: WebhookActions.successFetchWebhooks,
|
|
|
|
error: WebhookActions.errorWebhooks,
|
2016-01-15 13:55:58 +01:00
|
|
|
|
|
|
|
shouldFetch(state, invalidateCache) {
|
|
|
|
return invalidateCache || !Object.keys(state.webhooks).length;
|
2015-11-27 13:36:42 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
lookupWebhookEvents: {
|
|
|
|
remote() {
|
2016-06-14 16:53:18 +02:00
|
|
|
return request('webhooks_events');
|
2015-11-27 13:36:42 +01:00
|
|
|
},
|
2016-01-15 13:55:58 +01:00
|
|
|
|
2015-11-27 13:36:42 +01:00
|
|
|
local(state) {
|
2016-01-15 13:55:58 +01:00
|
|
|
return !Object.keys(state.webhookEvents).length ? state : {};
|
2015-11-27 13:36:42 +01:00
|
|
|
},
|
2016-01-15 13:55:58 +01:00
|
|
|
|
2015-11-27 13:36:42 +01:00
|
|
|
success: WebhookActions.successFetchWebhookEvents,
|
|
|
|
error: WebhookActions.errorWebhookEvents,
|
2016-01-15 13:55:58 +01:00
|
|
|
|
|
|
|
shouldFetch(state, invalidateCache) {
|
|
|
|
return invalidateCache || !Object.keys(state.webhookEvents).length;
|
2015-11-27 13:36:42 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
performRemoveWebhook: {
|
2016-01-15 13:55:58 +01:00
|
|
|
remote(state, webhookId) {
|
2016-06-14 16:53:18 +02:00
|
|
|
return request('webhook', {
|
|
|
|
method: 'DELETE',
|
|
|
|
urlTemplateSpec: { webhookId }
|
|
|
|
});
|
2015-11-27 13:36:42 +01:00
|
|
|
},
|
2016-01-15 13:55:58 +01:00
|
|
|
|
2015-11-27 13:36:42 +01:00
|
|
|
success: WebhookActions.successRemoveWebhook,
|
|
|
|
error: WebhookActions.errorWebhooks
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-01-15 13:55:58 +01:00
|
|
|
export default WebhookSource;
|