@pipedream/hootsuite 0.0.1 → 0.2.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,24 @@
1
+ export const parseObject = (obj) => {
2
+ if (!obj) return undefined;
3
+
4
+ if (Array.isArray(obj)) {
5
+ return obj.map((item) => {
6
+ if (typeof item === "string") {
7
+ try {
8
+ return JSON.parse(item);
9
+ } catch (e) {
10
+ return item;
11
+ }
12
+ }
13
+ return item;
14
+ });
15
+ }
16
+ if (typeof obj === "string") {
17
+ try {
18
+ return JSON.parse(obj);
19
+ } catch (e) {
20
+ return obj;
21
+ }
22
+ }
23
+ return obj;
24
+ };
@@ -0,0 +1,69 @@
1
+ import { axios } from "@pipedream/platform";
2
+
3
+ export default {
4
+ type: "app",
5
+ app: "hootsuite",
6
+ propDefinitions: {
7
+ socialProfileIds: {
8
+ type: "string[]",
9
+ label: "Social Profile IDs",
10
+ description: "The social profiles that the message will be posted to.",
11
+ async options() {
12
+ const { data } = await this.listSocialProfiles();
13
+ return data.map(({
14
+ id: value, socialNetworkUsername: label,
15
+ }) => ({
16
+ label,
17
+ value,
18
+ }));
19
+ },
20
+ },
21
+ },
22
+ methods: {
23
+ _baseUrl() {
24
+ return "https://platform.hootsuite.com/v1";
25
+ },
26
+ _headers() {
27
+ return {
28
+ Authorization: `Bearer ${this.$auth.oauth_access_token}`,
29
+ };
30
+ },
31
+ _makeRequest({
32
+ $ = this, path, noHeaders = false, ...opts
33
+ }) {
34
+ return axios($, {
35
+ url: this._baseUrl() + path,
36
+ headers: noHeaders
37
+ ? {}
38
+ : this._headers(),
39
+ ...opts,
40
+ });
41
+ },
42
+ listSocialProfiles() {
43
+ return this._makeRequest({
44
+ path: "/socialProfiles",
45
+ });
46
+ },
47
+ getMediaUploadStatus({
48
+ fileId, ...opts
49
+ }) {
50
+ return this._makeRequest({
51
+ path: `/media/${fileId}`,
52
+ ...opts,
53
+ });
54
+ },
55
+ scheduleMessage(opts = {}) {
56
+ return this._makeRequest({
57
+ method: "POST",
58
+ path: "/messages",
59
+ ...opts,
60
+ });
61
+ },
62
+ getPosts(opts = {}) {
63
+ return this._makeRequest({
64
+ path: "/messages",
65
+ ...opts,
66
+ });
67
+ },
68
+ },
69
+ };
package/package.json CHANGED
@@ -1,18 +1,19 @@
1
1
  {
2
2
  "name": "@pipedream/hootsuite",
3
- "version": "0.0.1",
3
+ "version": "0.2.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": "^3.1.0",
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,77 @@
1
+ import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
2
+ import dayjs from "dayjs";
3
+ import hootsuite from "../../hootsuite.app.mjs";
4
+ import constants from "../common/constants.mjs";
5
+
6
+ export default {
7
+ name: "New Post Created",
8
+ version: "0.0.2",
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
+ posts.forEach(this.emitEvent);
76
+ },
77
+ };