Skip to content

[Components] modelry #12525 #16350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
72 changes: 72 additions & 0 deletions components/modelry/actions/create-product/create-product.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import app from "../../modelry.app.mjs";

export default {
key: "modelry-create-product",
name: "Create Product",
description: "Create a new product. [See the documentation](https://files.cgtarsenal.com/api/doc/index.html#api-Products-CreateProduct)",
version: "0.0.1",
type: "action",
props: {
app,
sku: {
propDefinition: [
app,
"sku",
],
},
title: {
propDefinition: [
app,
"title",
],
},
batchId: {
propDefinition: [
app,
"batchId",
],
},
description: {
propDefinition: [
app,
"description",
],
},
tags: {
propDefinition: [
app,
"tags",
],
},
dimensions: {
propDefinition: [
app,
"dimensions",
],
},
externalUrl: {
propDefinition: [
app,
"externalUrl",
],
},
},
async run({ $ }) {
const response = await this.app.createProduct({
$,
data: {
product: {
sku: this.sku,
title: this.title,
batch_id: this.batchId,
description: this.description,
tags: this.tags,
dimensions: this.dimensions,
external_url: this.externalUrl,
},
},
});
$.export("$summary", `Successfully created product "${response.data.attributes.title}" with ID: ${response.data.id}`);
return response;
},
};
26 changes: 26 additions & 0 deletions components/modelry/actions/delete-product/delete-product.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import app from "../../modelry.app.mjs";

export default {
key: "modelry-delete-product",
name: "Delete Product",
description: "Delete the product with the specified ID. [See the documentation](https://files.cgtarsenal.com/api/doc/index.html#api-Products-DeleteProduct)",
version: "0.0.1",
type: "action",
props: {
app,
productId: {
propDefinition: [
app,
"productId",
],
},
},
async run({ $ }) {
const response = await this.app.deleteProduct({
$,
productId: this.productId,
});
$.export("$summary", "Successfully deleted the product");
return response;
},
};
26 changes: 26 additions & 0 deletions components/modelry/actions/get-product/get-product.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import app from "../../modelry.app.mjs";

export default {
key: "modelry-get-product",
name: "Get Product",
description: "Get details of the product with the specified ID. [See the documentation](https://files.cgtarsenal.com/api/doc/index.html#api-Products-GetProduct)",
version: "0.0.1",
type: "action",
props: {
app,
productId: {
propDefinition: [
app,
"productId",
],
},
},
async run({ $ }) {
const response = await this.app.getProduct({
$,
productId: this.productId,
});
$.export("$summary", `Successfully retrieved the details for the product "${response.data.attributes.title}" with ID: ${response.data.id}`);
return response;
},
};
112 changes: 108 additions & 4 deletions components/modelry/modelry.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,115 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "modelry",
propDefinitions: {},
propDefinitions: {
sku: {
type: "string",
label: "SKU",
description: "SKU of the product",
},
title: {
type: "string",
label: "Title",
description: "Name or title of the product",
},
batchId: {
type: "string",
label: "Batch ID",
description: "Identifier of the product's batch",
optional: true,
},
description: {
type: "string",
label: "Description",
description: "Description of the product",
optional: true,
},
tags: {
type: "string[]",
label: "Tags",
description: "Keywords associated with the product",
optional: true,
},
dimensions: {
type: "string",
label: "Dimensions",
description: "Dimensions of the product",
optional: true,
},
externalUrl: {
type: "string",
label: "External URL",
description: "External URL of the product",
optional: true,
},
productId: {
type: "string",
label: "Product ID",
description: "Identifier of the product",
async options() {
const response = await this.getProducts();
const products = response.data;
return products.map(({
attributes, id,
}) => ({
label: attributes.title,
value: id,
}));
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.modelry.ai/api/v1";
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
...headers,
"Content-Type": "application/json",
"Authorization": `${this.$auth.api_token}`,
},
});
},
async createProduct(args = {}) {
return this._makeRequest({
path: "/products",
method: "post",
...args,
});
},
async getProduct({
productId, args,
}) {
return this._makeRequest({
path: `/products/${productId}/`,
...args,
});
},
async deleteProduct({
productId, args,
}) {
return this._makeRequest({
path: `/products/${productId}/`,
method: "delete",
...args,
});
},
async getProducts(args = {}) {
return this._makeRequest({
path: "/products",
...args,
});
},
},
};
5 changes: 4 additions & 1 deletion components/modelry/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/modelry",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Modelry Components",
"main": "modelry.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
6 changes: 5 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading