-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (57 loc) · 1.94 KB
/
index.js
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
"use strict"
const CamayakContentAPI = require('camayak-contentapi');
const CamayakMedium = require('./lib/camayak_medium');
const api_key = process.env.CAMAYAK_API_KEY;
const shared_secret = process.env.CAMAYAK_SHARED_SECRET;
const medium_key = process.env.MEDIUM_API_KEY;
const port = process.env.PORT || 5000;
// Proposed usage of a Camayak-contentapi sdk
let camayak = new CamayakContentAPI({
port: port,
api_key: api_key,
shared_secret: shared_secret,
publish: function(webhook, content) {
let handler = new CamayakMedium(medium_key);
handler.publish(content, function(error, response){
if (error) {
return webhook.fail(error);
};
return webhook.succeed({
published_id: response.published_id,
published_url: response.published_url
});
});
},
update: function(webhook, content) {
let handler = new CamayakMedium(medium_key);
handler.update(content, function(error, response){
if (error) {
return webhook.fail(error);
};
return webhook.succeed({
published_id: response.published_id,
published_url: response.published_url
});
});
},
retract: function(webhook, content) {
// Retract Post using content.published_id
//
let handler = new CamayakMedium(medium_key);
handler.retract(content, function(error, response){
if (error) {
return webhook.fail(error);
};
return webhook.succeed({
published_id: response.published_id,
published_url: response.published_url
});
})
},
error: function(error, webhook) {
// Handle unexpected errors in the Camayak service
webhook.fail(error);
}
});
// Start listening for webhooks
camayak.start();