@pipedream/hootsuite 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,32 @@
1
+ import { axios } from "@pipedream/platform";
2
+
3
+ export default {
4
+ type: "app",
5
+ app: "hootsuite",
6
+ propDefinitions: {},
7
+ methods: {
8
+ _oauthAccessToken() {
9
+ return this.$auth.oauth_access_token;
10
+ },
11
+ _apiUrl() {
12
+ return "https://platform.hootsuite.com";
13
+ },
14
+ async _makeRequest({
15
+ $ = this, path, ...args
16
+ }) {
17
+ return axios($, {
18
+ url: `${this._apiUrl()}${path}`,
19
+ headers: {
20
+ Authorization: `Bearer ${this._oauthAccessToken()}`,
21
+ },
22
+ ...args,
23
+ });
24
+ },
25
+ async getPosts({ ...args } = {}) {
26
+ return this._makeRequest({
27
+ path: "/v1/messages",
28
+ ...args,
29
+ });
30
+ },
31
+ },
32
+ };
package/package.json CHANGED
@@ -1,18 +1,19 @@
1
1
  {
2
2
  "name": "@pipedream/hootsuite",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "Pipedream Hootsuite Components",
5
- "main": "dist/app/hootsuite.app.mjs",
5
+ "main": "hootsuite.app.mjs",
6
6
  "keywords": [
7
7
  "pipedream",
8
8
  "hootsuite"
9
9
  ],
10
- "files": [
11
- "dist"
12
- ],
13
10
  "homepage": "https://pipedream.com/apps/hootsuite",
14
11
  "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
15
12
  "publishConfig": {
16
13
  "access": "public"
14
+ },
15
+ "dependencies": {
16
+ "@pipedream/platform": "^1.5.1",
17
+ "dayjs": "^1.11.7"
17
18
  }
18
19
  }
@@ -0,0 +1,28 @@
1
+ export default {
2
+ STATES: [
3
+ {
4
+ label: "Scheduled",
5
+ value: "SCHEDULED",
6
+ },
7
+ {
8
+ label: "Submitted",
9
+ value: "SUBMITTED",
10
+ },
11
+ {
12
+ label: "Pending Approval",
13
+ value: "PENDING_APPROVAL",
14
+ },
15
+ {
16
+ label: "Sent",
17
+ value: "SENT",
18
+ },
19
+ {
20
+ label: "Send Failed Permanently",
21
+ value: "SEND_FAILED_PERMANENTLY",
22
+ },
23
+ {
24
+ label: "Rejected",
25
+ value: "REJECTED",
26
+ },
27
+ ],
28
+ };
@@ -0,0 +1,83 @@
1
+ import dayjs from "dayjs";
2
+ import hootsuite from "../../hootsuite.app.mjs";
3
+ import constants from "../common/constants.mjs";
4
+ import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
5
+
6
+ export default {
7
+ name: "New Post Created",
8
+ version: "0.0.1",
9
+ key: "hootsuite-new-post-created",
10
+ description: "Emit new event on each new created post. [See docs here](https://platform.hootsuite.com/docs/api/index.html#operation/retrieveMessages).",
11
+ type: "source",
12
+ dedupe: "unique",
13
+ props: {
14
+ hootsuite,
15
+ db: "$.service.db",
16
+ timer: {
17
+ type: "$.interface.timer",
18
+ static: {
19
+ intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
20
+ },
21
+ },
22
+ states: {
23
+ label: "States",
24
+ description: "Selected the states to filter",
25
+ options: constants.STATES,
26
+ type: "string[]",
27
+ },
28
+ },
29
+ methods: {
30
+ emitEvent(data) {
31
+ if (!this.states.includes(data.state)) {
32
+ return;
33
+ }
34
+
35
+ this.$emit(data, {
36
+ id: data.id,
37
+ summary: `New post created with ID ${data.id}`,
38
+ ts: new Date(),
39
+ });
40
+ },
41
+ _setLastSyncTimestamp() {
42
+ this.db.set("lastSyncTimestamp", dayjs().toISOString());
43
+ },
44
+ _getLastSyncTimestamp() {
45
+ return this.db.get("lastSyncTimestamp");
46
+ },
47
+ },
48
+ hooks: {
49
+ async deploy() {
50
+ this._setLastSyncTimestamp();
51
+
52
+ const { data: posts } = await this.hootsuite.getPosts({
53
+ params: {
54
+ startTime: new Date(new Date().setDate(new Date().getDate() - 7)).toISOString(),
55
+ endTime: new Date().toISOString(),
56
+ },
57
+ });
58
+
59
+ posts.forEach(this.emitEvent);
60
+ },
61
+ },
62
+ async run() {
63
+ const lastSyncTimestamp = this._getLastSyncTimestamp();
64
+ this._setLastSyncTimestamp();
65
+
66
+ const { data: posts } = await this.hootsuite.getPosts({
67
+ params: {
68
+ startTime: dayjs(lastSyncTimestamp).subtract(24, "hour")
69
+ .toISOString(),
70
+ endTime: dayjs().add(24, "hour")
71
+ .toISOString(),
72
+ },
73
+ });
74
+
75
+ console.log({
76
+ startTime: dayjs(lastSyncTimestamp).subtract(24, "hour")
77
+ .toISOString(),
78
+ endTime: dayjs().toISOString(),
79
+ });
80
+
81
+ posts.forEach(this.emitEvent);
82
+ },
83
+ };