@pipedream/hootsuite 0.1.0 → 0.2.1

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
+ };
package/hootsuite.app.mjs CHANGED
@@ -3,29 +3,66 @@ import { axios } from "@pipedream/platform";
3
3
  export default {
4
4
  type: "app",
5
5
  app: "hootsuite",
6
- propDefinitions: {},
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
+ },
7
22
  methods: {
8
- _oauthAccessToken() {
9
- return this.$auth.oauth_access_token;
23
+ _baseUrl() {
24
+ return "https://platform.hootsuite.com/v1";
10
25
  },
11
- _apiUrl() {
12
- return "https://platform.hootsuite.com";
26
+ _headers() {
27
+ return {
28
+ Authorization: `Bearer ${this.$auth.oauth_access_token}`,
29
+ };
13
30
  },
14
- async _makeRequest({
15
- $ = this, path, ...args
31
+ _makeRequest({
32
+ $ = this, path, noHeaders = false, ...opts
16
33
  }) {
17
34
  return axios($, {
18
- url: `${this._apiUrl()}${path}`,
19
- headers: {
20
- Authorization: `Bearer ${this._oauthAccessToken()}`,
21
- },
22
- ...args,
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,
23
60
  });
24
61
  },
25
- async getPosts({ ...args } = {}) {
62
+ getPosts(opts = {}) {
26
63
  return this._makeRequest({
27
- path: "/v1/messages",
28
- ...args,
64
+ path: "/messages",
65
+ ...opts,
29
66
  });
30
67
  },
31
68
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/hootsuite",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Pipedream Hootsuite Components",
5
5
  "main": "hootsuite.app.mjs",
6
6
  "keywords": [
@@ -13,7 +13,7 @@
13
13
  "access": "public"
14
14
  },
15
15
  "dependencies": {
16
- "@pipedream/platform": "^1.5.1",
16
+ "@pipedream/platform": "^3.1.1",
17
17
  "dayjs": "^1.11.7"
18
18
  }
19
19
  }
@@ -1,11 +1,11 @@
1
+ import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
1
2
  import dayjs from "dayjs";
2
3
  import hootsuite from "../../hootsuite.app.mjs";
3
4
  import constants from "../common/constants.mjs";
4
- import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
5
5
 
6
6
  export default {
7
7
  name: "New Post Created",
8
- version: "0.0.1",
8
+ version: "0.0.2",
9
9
  key: "hootsuite-new-post-created",
10
10
  description: "Emit new event on each new created post. [See docs here](https://platform.hootsuite.com/docs/api/index.html#operation/retrieveMessages).",
11
11
  type: "source",
@@ -72,12 +72,6 @@ export default {
72
72
  },
73
73
  });
74
74
 
75
- console.log({
76
- startTime: dayjs(lastSyncTimestamp).subtract(24, "hour")
77
- .toISOString(),
78
- endTime: dayjs().toISOString(),
79
- });
80
-
81
75
  posts.forEach(this.emitEvent);
82
76
  },
83
77
  };