Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "linkedin-create-comment",
name: "Create Comment",
description: "Create a comment on a share or user generated content post. [See the docs here](https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/network-update-social-actions#create-comment)",
version: "0.1.5",
version: "0.1.6",
type: "action",
props: {
linkedin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "linkedin-create-image-post-organization",
name: "Create Image Post (Organization)",
description: "Create an image post on LinkedIn. [See the docs here](https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/images-api?view=li-lms-2023-09&tabs=http#uploading-an-image)",
version: "0.0.2",
version: "0.0.3",
type: "action",
props: {
linkedin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "linkedin-create-image-post-user",
name: "Create Image Post (User)",
description: "Create an image post on LinkedIn. [See the docs here](https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/images-api?view=li-lms-2023-09&tabs=http#uploading-an-image)",
version: "0.0.2",
version: "0.0.3",
type: "action",
props: {
linkedin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "linkedin-create-like-on-share",
name: "Create Like On Share",
description: "Creates a like on a share. [See the docs here](https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/network-update-social-actions#create-a-like-on-a-share)",
version: "0.1.5",
version: "0.1.6",
type: "action",
props: {
linkedin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "linkedin-create-text-post-organization",
name: "Create a Simple Post (Organization)",
description: "Create post on LinkedIn using text, URL or article. [See the docs](https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/posts-api?view=li-lms-2022-11&tabs=http#create-organic-posts) for more information",
version: "0.0.5",
version: "0.0.6",
type: "action",
props: {
linkedin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "linkedin-create-text-post-user",
name: "Create a Simple Post (User)",
description: "Create post on LinkedIn using text, URL or article. [See the docs](https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/posts-api?view=li-lms-2022-11&tabs=http#create-organic-posts) for more information",
version: "0.0.5",
version: "0.0.6",
type: "action",
props: {
linkedin,
Expand Down
2 changes: 1 addition & 1 deletion components/linkedin/actions/delete-post/delete-post.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "linkedin-delete-post",
name: "Delete Post",
description: "Removes a post from user's wall. [See the docs](https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/share-api?tabs=http#delete-shares) for more information",
version: "0.0.5",
version: "0.0.6",
type: "action",
props: {
linkedin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "linkedin-fetch-ad-account",
name: "Fetch Ad Account",
description: "Fetches an individual adAccount given its id. [See the docs here](https://docs.microsoft.com/en-us/linkedin/marketing/integrations/ads/account-structure/create-and-manage-accounts#fetch-ad-account)",
version: "0.1.5",
version: "0.1.6",
type: "action",
props: {
linkedin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "linkedin-get-current-member-profile",
name: "Get Current Member Profile",
description: "Gets the profile of the current authenticated member. [See the docs here](https://docs.microsoft.com/en-us/linkedin/shared/integrations/people/profile-api#retrieve-current-members-profile)",
version: "0.1.5",
version: "0.1.6",
type: "action",
props: {
linkedin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "linkedin-get-member-organization-access-control",
name: "Get Member's Organization Access Control Information",
description: "Gets the organization access control information of the current authenticated member. [See the docs here](https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/organizations/organization-access-control?context=linkedin/compliance/context#find-a-members-organization-access-control-information)",
version: "0.1.5",
version: "0.1.6",
type: "action",
props: {
linkedin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "linkedin-get-member-profile",
name: "Get Member Profile",
description: "Gets another member's profile, given its person id. [See the docs here](https://docs.microsoft.com/en-us/linkedin/shared/integrations/people/profile-api#retrieve-other-members-profile)",
version: "0.1.5",
version: "0.1.6",
type: "action",
props: {
linkedin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "linkedin-get-multiple-member-profiles",
name: "Get Multiple Member Profiles",
description: "Gets multiple member profiles at once. [See the docs here](https://docs.microsoft.com/en-us/linkedin/shared/integrations/people/profile-api#retrieve-other-members-profile)",
version: "0.1.5",
version: "0.1.6",
type: "action",
props: {
linkedin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "linkedin-get-organization-access-control",
name: "Gets Organization Access Control",
description: "Gets an organization's access control information, given the organization urn. [See the docs here](https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/organizations/organization-access-control?context=linkedin/compliance/context#find-access-control-information)",
version: "0.1.5",
version: "0.1.6",
type: "action",
props: {
linkedin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "linkedin-get-organization-administrators",
name: "Get Organization Administrators",
description: "Gets the administator members of an organization, given the organization urn. [See the docs here](https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/organizations/organization-access-control?context=linkedin/compliance/context#find-organization-administrators)",
version: "0.2.5",
version: "0.2.6",
type: "action",
props: {
linkedin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "linkedin-retrieve-comments-on-comments",
name: "Retrieves Comments on Comments",
description: "Retrieves comments on comments, given the parent comment urn. [See the docs here](https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/network-update-social-actions#retrieve-comments-on-comments)",
version: "0.1.5",
version: "0.1.6",
type: "action",
props: {
linkedin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "linkedin-retrieve-comments-shares",
name: "Retrieve Comments On Shares",
description: "Retrieve comments on shares given the share urn. [See the docs here](https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/network-update-social-actions#retrieve-comments-on-shares)",
version: "0.1.5",
version: "0.1.6",
type: "action",
props: {
linkedin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "linkedin-search-organization",
name: "Search Organization",
description: "Searches for an organization by vanity name or email domain. [See the docs here](https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/organizations/organization-lookup-api)",
version: "0.1.5",
version: "0.1.6",
type: "action",
props: {
linkedin,
Expand Down
13 changes: 13 additions & 0 deletions components/linkedin/common/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ const ROLE_STATES = [
"REVOKED",
];

const DEFAULT_LIMIT = 20;
const DEFAULT_MAX = 100;
const IS_FIRST_RUN = "isFirstRun";
const LAST_DATE_AT = "lastDateAt";
const ORG_ID = "orgId";
const PERSON_ID = "personId";

export default {
VERSION_PATH,
BASE_URL,
Expand All @@ -85,4 +92,10 @@ export default {
PIVOT_OPTIONS,
ORGANIZATION_ROLES,
ROLE_STATES,
DEFAULT_LIMIT,
DEFAULT_MAX,
IS_FIRST_RUN,
LAST_DATE_AT,
ORG_ID,
PERSON_ID,
};
38 changes: 38 additions & 0 deletions components/linkedin/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
async function iterate(iterations) {
const items = [];
for await (const item of iterations) {
items.push(item);
}
return items;
}

function getNestedProperty(obj, propertyString) {
const properties = propertyString.split(".");
return properties.reduce((prev, curr) => prev?.[curr], obj);
}

function defaultEncodeFn(key, value) {
return `${key}=${value}`;
}

function encodeFn(key, value) {
return `${key}=${encodeURIComponent(value)}`;
}

function getParamsSerializer(encodeFn = defaultEncodeFn) {
return (params) => {
return Object.entries(params)
.map(([
key,
value,
]) => encodeFn(key, value))
.join("&");
};
}

export default {
iterate,
getNestedProperty,
encodeFn,
getParamsSerializer,
};
61 changes: 61 additions & 0 deletions components/linkedin/linkedin.app.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { axios as axiosPD } from "@pipedream/platform";
import axios from "axios";
import constants from "./common/constants.mjs";
import utils from "./common/utils.mjs";

export default {
type: "app",
Expand Down Expand Up @@ -268,5 +269,65 @@ export default {
...args,
});
},
listPosts(args = {}) {
return this._makeRequest({
path: "/posts",
paramsSerializer: utils.getParamsSerializer(utils.encodeFn),
...args,
});
},
async *getIterations({
resourcesFn, resourcesFnArgs, resourceName,
lastDateAt, dateField,
max = constants.DEFAULT_MAX,
}) {
let page = 0;
let resourcesCount = 0;

while (true) {
const response =
await resourcesFn({
...resourcesFnArgs,
params: {
...resourcesFnArgs?.params,
count: constants.DEFAULT_LIMIT,
start: page * constants.DEFAULT_LIMIT,
},
});

const nextResources = utils.getNestedProperty(response, resourceName);

if (!nextResources?.length) {
console.log("No more resources found");
return;
}

for (const resource of nextResources) {
const isDateGreater =
lastDateAt
&& resource[dateField] > lastDateAt;

if (!lastDateAt || isDateGreater) {
yield resource;
resourcesCount += 1;
}

if (resourcesCount >= max) {
console.log("Reached max resources");
return;
}
}

if (nextResources.length < constants.DEFAULT_LIMIT) {
console.log("No next page found");
return;
}

page += 1;
}
},
Comment on lines +279 to +328
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling to the getIterations method.

While the pagination logic is well-implemented with proper termination conditions, the method lacks error handling for API calls. If the resourcesFn call fails (e.g., network issues, rate limiting), the error will propagate without any specific handling.

    async *getIterations({
      resourcesFn, resourcesFnArgs, resourceName,
      lastDateAt, dateField,
      max = constants.DEFAULT_MAX,
    }) {
      let page = 0;
      let resourcesCount = 0;

      while (true) {
+       try {
          const response =
            await resourcesFn({
              ...resourcesFnArgs,
              params: {
                ...resourcesFnArgs?.params,
                count: constants.DEFAULT_LIMIT,
                start: page * constants.DEFAULT_LIMIT,
              },
            });

          const nextResources = utils.getNestedProperty(response, resourceName);

          if (!nextResources?.length) {
            console.log("No more resources found");
            return;
          }

          for (const resource of nextResources) {
            const isDateGreater =
              lastDateAt
                && resource[dateField] > lastDateAt;

            if (!lastDateAt || isDateGreater) {
              yield resource;
              resourcesCount += 1;
            }

            if (resourcesCount >= max) {
              console.log("Reached max resources");
              return;
            }
          }

          if (nextResources.length < constants.DEFAULT_LIMIT) {
            console.log("No next page found");
            return;
          }

          page += 1;
+       } catch (error) {
+         console.error("Error fetching resources:", error);
+         throw error;
+       }
      }
    },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async *getIterations({
resourcesFn, resourcesFnArgs, resourceName,
lastDateAt, dateField,
max = constants.DEFAULT_MAX,
}) {
let page = 0;
let resourcesCount = 0;
while (true) {
const response =
await resourcesFn({
...resourcesFnArgs,
params: {
...resourcesFnArgs?.params,
count: constants.DEFAULT_LIMIT,
start: page * constants.DEFAULT_LIMIT,
},
});
const nextResources = utils.getNestedProperty(response, resourceName);
if (!nextResources?.length) {
console.log("No more resources found");
return;
}
for (const resource of nextResources) {
const isDateGreater =
lastDateAt
&& resource[dateField] > lastDateAt;
if (!lastDateAt || isDateGreater) {
yield resource;
resourcesCount += 1;
}
if (resourcesCount >= max) {
console.log("Reached max resources");
return;
}
}
if (nextResources.length < constants.DEFAULT_LIMIT) {
console.log("No next page found");
return;
}
page += 1;
}
},
async *getIterations({
resourcesFn, resourcesFnArgs, resourceName,
lastDateAt, dateField,
max = constants.DEFAULT_MAX,
}) {
let page = 0;
let resourcesCount = 0;
while (true) {
try {
const response =
await resourcesFn({
...resourcesFnArgs,
params: {
...resourcesFnArgs?.params,
count: constants.DEFAULT_LIMIT,
start: page * constants.DEFAULT_LIMIT,
},
});
const nextResources = utils.getNestedProperty(response, resourceName);
if (!nextResources?.length) {
console.log("No more resources found");
return;
}
for (const resource of nextResources) {
const isDateGreater =
lastDateAt
&& resource[dateField] > lastDateAt;
if (!lastDateAt || isDateGreater) {
yield resource;
resourcesCount += 1;
}
if (resourcesCount >= max) {
console.log("Reached max resources");
return;
}
}
if (nextResources.length < constants.DEFAULT_LIMIT) {
console.log("No next page found");
return;
}
page += 1;
} catch (error) {
console.error("Error fetching resources:", error);
throw error;
}
}
},

paginate(args = {}) {
return utils.iterate(this.getIterations(args));
},
},
};
4 changes: 2 additions & 2 deletions components/linkedin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/linkedin",
"version": "0.1.1",
"version": "0.2.0",
"description": "Pipedream Linkedin Components",
"main": "linkedin.app.mjs",
"keywords": [
Expand All @@ -13,7 +13,7 @@
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.2.1",
"@pipedream/platform": "^3.0.3",
"axios": "^1.2.3",
"form-data": "^4.0.0"
}
Expand Down
Loading
Loading