@pipedream/unsplash 0.0.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.
- package/LICENSE +41 -0
- package/README.md +11 -0
- package/actions/get-photo/get-photo.mjs +41 -0
- package/actions/search-photos/search-photos.mjs +74 -0
- package/common/constants.mjs +81 -0
- package/common/utils.mjs +34 -0
- package/package.json +18 -0
- package/unsplash.app.mjs +98 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Pipedream Source Available License Version 1.0
|
|
2
|
+
|
|
3
|
+
This Pipedream Source Available License Agreement Version 1.0 (this “Agreement”) sets forth the terms on which Pipedream, Inc., a Delaware corporation (“Pipedream”) makes available certain software (the “Software”). By installing, downloading, accessing, using or distributing the Software, you agree to the terms of this Agreement. If you do not agree to such terms, you must not use the Software. If you are receiving the Software on behalf of a legal entity, you represent and warrant that you have the actual authority to agree to the terms and conditions of this Agreement on behalf of such entity. “Licensee” means you, an individual, or the entity on whose behalf you are receiving the Software.
|
|
4
|
+
|
|
5
|
+
LICENSE GRANT AND CONDITIONS.
|
|
6
|
+
|
|
7
|
+
1.1 License. Subject to the terms and conditions of this Agreement, Pipedream hereby grants to Licensee a non-exclusive, royalty-free, worldwide, non-transferable, non-sublicenseable license during the term of this Agreement to use, prepare modifications and derivative works, distribute (including without limitation in source code or object code form) and reproduce copies of the Software (the “License”). Licensee is not granted the right to, and Licensee shall not, exercise the License for an Excluded Purpose. For purposes of this Agreement, “Excluded Purpose” means any commercial use of the software including, but not limited to, making available any software-as-a-service, platform-as-a-service, infrastructure-as-a-service or other online service that competes with the Software or any other Pipedream products or services.
|
|
8
|
+
|
|
9
|
+
1.2 Conditions. In consideration of the License, Licensee’s distribution of the Software is subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
a. Licensee must cause any Software modified by Licensee to carry prominent notices stating that Licensee modified the Software.
|
|
12
|
+
|
|
13
|
+
b. On each Software copy, Licensee shall reproduce and not remove or alter all Pipedream or third party copyright or other proprietary notices contained in the Software, and Licensee must provide this with each copy: “This software is made available by Pipedream, Inc., under the terms of the Pipedream Source Available License, Version 1.0 located at https://github.com/PipedreamHQ/pipedream/blob/master/LICENSE. By installing, downloading, accessing, using or distributing the Software, you agree to the terms of such License Agreement.”
|
|
14
|
+
|
|
15
|
+
1.3 Modifications. Licensee may add its own copyright notices to modifications made by Licensee and may provide additional or different license terms and conditions for use, reproduction, or distribution of Licensee’s modifications. While redistributing the Software or modifications thereof, Licensee may choose to offer, for a fee or free of charge, support, warranty, indemnity, or other obligations. Licensee, and not Pipedream, will be responsible for any such obligations.
|
|
16
|
+
|
|
17
|
+
1.4 No Sublicensing. The License does not include the right to sublicense the Software; provided, however, that any recipient to which Licensee provides the Software may exercise the License so long as such recipient agrees to the terms and conditions of this Agreement.
|
|
18
|
+
|
|
19
|
+
TERM AND TERMINATION.
|
|
20
|
+
|
|
21
|
+
This Agreement will continue unless and until earlier terminated as set forth herein. If Licensee breaches any of its conditions or obligations under this Agreement, this Agreement will terminate automatically and the License will terminate automatically and permanently.
|
|
22
|
+
|
|
23
|
+
INTELLECTUAL PROPERTY.
|
|
24
|
+
|
|
25
|
+
As between the parties, Pipedream retains all right, title, and interest in the Software, and all intellectual property rights therein. Pipedream hereby reserves all rights not expressly granted to Licensee in this Agreement. Pipedream reserves all rights in its trademarks and service marks, and no licenses thereto are granted by this Agreement.
|
|
26
|
+
|
|
27
|
+
DISCLAIMER.
|
|
28
|
+
|
|
29
|
+
PIPEDREAM HEREBY DISCLAIMS ANY AND ALL WARRANTIES AND CONDITIONS, EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, AND SPECIFICALLY DISCLAIMS ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE SOFTWARE.
|
|
30
|
+
|
|
31
|
+
LIMITATION OF LIABILITY.
|
|
32
|
+
|
|
33
|
+
PIPEDREAM WILL NOT BE LIABLE FOR ANY DAMAGES OF ANY KIND, INCLUDING BUT NOT LIMITED TO, LOST PROFITS OR ANY CONSEQUENTIAL, SPECIAL, INCIDENTAL, INDIRECT, OR DIRECT DAMAGES, HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ARISING OUT OF THIS AGREEMENT. THE FOREGOING SHALL APPLY TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW.
|
|
34
|
+
|
|
35
|
+
GENERAL.
|
|
36
|
+
|
|
37
|
+
6.1 Governing Law. This Agreement will be governed by and interpreted in accordance with the laws of the state of California, without reference to its conflict of laws principles. If Licensee is located outside of the United States, any dispute, controversy or claim arising out of or relating to this Agreement will be referred to and finally determined by arbitration in accordance with the JAMS International Arbitration Rules. The tribunal will consist of one arbitrator. Judgment upon the award rendered by the arbitrator may be entered in any court having jurisdiction thereof. All disputes including arbitrations shall take place in Santa Clara County, California. The language to be used in any such proceedings shall be English.
|
|
38
|
+
|
|
39
|
+
6.2. Assignment. Licensee is not authorized to assign its rights under this Agreement to any third party. Pipedream may freely assign its rights under this Agreement to any third party.
|
|
40
|
+
|
|
41
|
+
6.3. Other. This Agreement is the entire agreement between the parties regarding the subject matter hereof. No amendment or modification of this Agreement will be valid or binding upon the parties unless made in writing and signed by the duly authorized representatives of both parties. In the event that any provision, including without limitation any condition, of this Agreement is held to be unenforceable, this Agreement and all licenses and rights granted hereunder will immediately terminate. Waiver by Pipedream of a breach of any provision of this Agreement or the failure by Pipedream to exercise any right hereunder will not be construed as a waiver of any subsequent breach of that right or as a waiver of any other right.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Overview
|
|
2
|
+
|
|
3
|
+
The Unsplash API provides programmatic access to a vast library of high-quality, royalty-free images. This enables developers to search for and retrieve photos based on keywords, collections, or featured content. With Pipedream's integration, you can automate tasks like updating social media banners, populating website content with dynamic images, or even analyzing photo metadata for insights. By leveraging Unsplash's API within Pipedream, you can create workflows that trigger on various events, process image data, and interact with countless other apps available on the platform, streamlining your digital asset management and content creation processes.
|
|
4
|
+
|
|
5
|
+
# Example Use Cases
|
|
6
|
+
|
|
7
|
+
- **Social Media Content Update:** Automate the updating of your social media profiles with fresh, high-resolution images by setting a Pipedream workflow that periodically queries the Unsplash API for new photos based on specific search criteria, and then posts those images to platforms like Twitter, Facebook, or Instagram using their respective APIs.
|
|
8
|
+
|
|
9
|
+
- **Dynamic Website Imagery:** Enhance your website's visual appeal by creating a Pipedream workflow that pulls a curated set of images from Unsplash based on tags or collections, then pushes these images to your website's CMS (such as WordPress) to keep the visual content fresh and engaging without manual intervention.
|
|
10
|
+
|
|
11
|
+
- **Marketing Asset Management:** Build a Pipedream workflow that listens for new uploads from your company’s designated photographers to Unsplash, downloads the high-quality versions of these images, and then stores them in Google Drive or Dropbox. Integrate with Slack to send notifications to your marketing team so they can easily access and use the latest images in campaigns and collateral.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import app from "../../unsplash.app.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
key: "unsplash-get-photo",
|
|
5
|
+
name: "Get Photo",
|
|
6
|
+
description: "Get a specific photo from Unsplash. [See the documentation](https://unsplash.com/documentation#get-a-photo)",
|
|
7
|
+
version: "0.0.1",
|
|
8
|
+
type: "action",
|
|
9
|
+
props: {
|
|
10
|
+
app,
|
|
11
|
+
photoId: {
|
|
12
|
+
propDefinition: [
|
|
13
|
+
app,
|
|
14
|
+
"photoId",
|
|
15
|
+
],
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
methods: {
|
|
19
|
+
getPhoto({
|
|
20
|
+
photoId, ...args
|
|
21
|
+
} = {}) {
|
|
22
|
+
return this.app._makeRequest({
|
|
23
|
+
path: `/photos/${photoId}`,
|
|
24
|
+
...args,
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
async run({ $ }) {
|
|
29
|
+
const {
|
|
30
|
+
getPhoto,
|
|
31
|
+
photoId,
|
|
32
|
+
} = this;
|
|
33
|
+
const response = await getPhoto({
|
|
34
|
+
$,
|
|
35
|
+
photoId,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
$.export("$summary", `Successfully retrieved photo with ID \`${response.id}\``);
|
|
39
|
+
return response;
|
|
40
|
+
},
|
|
41
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import constants from "../../common/constants.mjs";
|
|
2
|
+
import app from "../../unsplash.app.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
key: "unsplash-search-photos",
|
|
6
|
+
name: "Search Photos",
|
|
7
|
+
description: "Get a single page of photo results for a query. [See the documentation](https://unsplash.com/documentation#search-photos)",
|
|
8
|
+
version: "0.0.1",
|
|
9
|
+
type: "action",
|
|
10
|
+
props: {
|
|
11
|
+
app,
|
|
12
|
+
query: {
|
|
13
|
+
type: "string",
|
|
14
|
+
label: "Query",
|
|
15
|
+
description: "Search terms.",
|
|
16
|
+
},
|
|
17
|
+
contentFilter: {
|
|
18
|
+
type: "string",
|
|
19
|
+
label: "Content Filter",
|
|
20
|
+
description: "Limit results by content safety. Valid values are `low` and `high`.",
|
|
21
|
+
optional: true,
|
|
22
|
+
options: constants.CONTENT_FILTERS,
|
|
23
|
+
},
|
|
24
|
+
color: {
|
|
25
|
+
type: "string",
|
|
26
|
+
label: "Color",
|
|
27
|
+
description: "Filter results by color. Valid values are: `black_and_white`, `black`, `white`, `yellow`, `orange`, `red`, `purple`, `magenta`, `green`, `teal`, and `blue`.",
|
|
28
|
+
optional: true,
|
|
29
|
+
options: constants.COLOR_OPTIONS,
|
|
30
|
+
},
|
|
31
|
+
orientation: {
|
|
32
|
+
type: "string",
|
|
33
|
+
label: "Orientation",
|
|
34
|
+
description: "Filter by photo orientation. Optional. (Valid values: `landscape`, `portrait`, `squarish`)",
|
|
35
|
+
optional: true,
|
|
36
|
+
options: constants.ORIENTATION_OPTIONS,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
methods: {
|
|
40
|
+
searchPhotos(args = {}) {
|
|
41
|
+
return this.app._makeRequest({
|
|
42
|
+
path: "/search/photos",
|
|
43
|
+
...args,
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
async run({ $ }) {
|
|
48
|
+
const {
|
|
49
|
+
app,
|
|
50
|
+
searchPhotos,
|
|
51
|
+
query,
|
|
52
|
+
contentFilter,
|
|
53
|
+
color,
|
|
54
|
+
orientation,
|
|
55
|
+
} = this;
|
|
56
|
+
|
|
57
|
+
const photos = await app.paginate({
|
|
58
|
+
resourcesFn: searchPhotos,
|
|
59
|
+
resourcesFnArgs: {
|
|
60
|
+
$,
|
|
61
|
+
params: {
|
|
62
|
+
query,
|
|
63
|
+
content_filter: contentFilter,
|
|
64
|
+
color,
|
|
65
|
+
orientation,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
resourceName: "results",
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
$.export("$summary", `Successfully retrieved \`${photos.length}\` photo(s).`);
|
|
72
|
+
return photos;
|
|
73
|
+
},
|
|
74
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const BASE_URL = "https://api.unsplash.com";
|
|
2
|
+
const API_VERSION = "v1";
|
|
3
|
+
const DEFAULT_MAX = 100;
|
|
4
|
+
const DEFAULT_LIMIT = 100;
|
|
5
|
+
|
|
6
|
+
const CONTENT_FILTERS = [
|
|
7
|
+
"low",
|
|
8
|
+
"high",
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
const COLOR_OPTIONS = [
|
|
12
|
+
{
|
|
13
|
+
label: "Black and White",
|
|
14
|
+
value: "black_and_white",
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
label: "Black",
|
|
18
|
+
value: "black",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
label: "White",
|
|
22
|
+
value: "white",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
label: "Yellow",
|
|
26
|
+
value: "yellow",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
label: "Orange",
|
|
30
|
+
value: "orange",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
label: "Red",
|
|
34
|
+
value: "red",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
label: "Purple",
|
|
38
|
+
value: "purple",
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
label: "Magenta",
|
|
42
|
+
value: "magenta",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
label: "Green",
|
|
46
|
+
value: "green",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
label: "Teal",
|
|
50
|
+
value: "teal",
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
label: "Blue",
|
|
54
|
+
value: "blue",
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
const ORIENTATION_OPTIONS = [
|
|
59
|
+
{
|
|
60
|
+
label: "Landscape",
|
|
61
|
+
value: "landscape",
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
label: "Portrait",
|
|
65
|
+
value: "portrait",
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
label: "Squarish",
|
|
69
|
+
value: "squarish",
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
export default {
|
|
74
|
+
BASE_URL,
|
|
75
|
+
API_VERSION,
|
|
76
|
+
DEFAULT_LIMIT,
|
|
77
|
+
DEFAULT_MAX,
|
|
78
|
+
CONTENT_FILTERS,
|
|
79
|
+
COLOR_OPTIONS,
|
|
80
|
+
ORIENTATION_OPTIONS,
|
|
81
|
+
};
|
package/common/utils.mjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
function parseLinkHeader(linkHeader) {
|
|
2
|
+
return linkHeader?.split(",")
|
|
3
|
+
.reduce((props, link) => {
|
|
4
|
+
const [
|
|
5
|
+
url,
|
|
6
|
+
rel,
|
|
7
|
+
] = link.split(";");
|
|
8
|
+
const [
|
|
9
|
+
, value,
|
|
10
|
+
] = url.split("<");
|
|
11
|
+
const [
|
|
12
|
+
, key,
|
|
13
|
+
] = rel.split("=");
|
|
14
|
+
const clearKey = key.replace(/"/g, "");
|
|
15
|
+
const clearValue = value.replace(/>/g, "");
|
|
16
|
+
return {
|
|
17
|
+
...props,
|
|
18
|
+
[clearKey]: clearValue,
|
|
19
|
+
};
|
|
20
|
+
}, {});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function iterate(iterations) {
|
|
24
|
+
const items = [];
|
|
25
|
+
for await (const item of iterations) {
|
|
26
|
+
items.push(item);
|
|
27
|
+
}
|
|
28
|
+
return items;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default {
|
|
32
|
+
iterate,
|
|
33
|
+
parseLinkHeader,
|
|
34
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pipedream/unsplash",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Pipedream Unsplash Components",
|
|
5
|
+
"main": "unsplash.app.mjs",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"pipedream",
|
|
8
|
+
"unsplash"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://pipedream.com/apps/unsplash",
|
|
11
|
+
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@pipedream/platform": "^1.6.5"
|
|
17
|
+
}
|
|
18
|
+
}
|
package/unsplash.app.mjs
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { axios } from "@pipedream/platform";
|
|
2
|
+
import utils from "./common/utils.mjs";
|
|
3
|
+
import constants from "./common/constants.mjs";
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
type: "app",
|
|
7
|
+
app: "unsplash",
|
|
8
|
+
propDefinitions: {
|
|
9
|
+
photoId: {
|
|
10
|
+
type: "string",
|
|
11
|
+
label: "Photo ID",
|
|
12
|
+
description: "The ID of the photo to retrieve.",
|
|
13
|
+
async options({ page }) {
|
|
14
|
+
const photos = await this.listPhotos({
|
|
15
|
+
params: {
|
|
16
|
+
page: page + 1,
|
|
17
|
+
per_page: constants.DEFAULT_LIMIT,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
return photos.map(({
|
|
21
|
+
id: value, slug: label,
|
|
22
|
+
}) => ({
|
|
23
|
+
label,
|
|
24
|
+
value,
|
|
25
|
+
}));
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
methods: {
|
|
30
|
+
getUrl(path) {
|
|
31
|
+
return `${constants.BASE_URL}${path}`;
|
|
32
|
+
},
|
|
33
|
+
getHeaders(headers) {
|
|
34
|
+
return {
|
|
35
|
+
...headers,
|
|
36
|
+
"Accept-Version": constants.API_VERSION,
|
|
37
|
+
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
_makeRequest({
|
|
41
|
+
$ = this, path, headers, ...args
|
|
42
|
+
} = {}) {
|
|
43
|
+
return axios($, {
|
|
44
|
+
...args,
|
|
45
|
+
debug: true,
|
|
46
|
+
url: this.getUrl(path),
|
|
47
|
+
headers: this.getHeaders(headers),
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
listPhotos(args = {}) {
|
|
51
|
+
return this._makeRequest({
|
|
52
|
+
path: "/photos",
|
|
53
|
+
...args,
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
async *getIterations({
|
|
57
|
+
resourcesFn, resourcesFnArgs, resourceName,
|
|
58
|
+
max = constants.DEFAULT_MAX,
|
|
59
|
+
}) {
|
|
60
|
+
let page = 1;
|
|
61
|
+
let resourcesCount = 0;
|
|
62
|
+
|
|
63
|
+
while (true) {
|
|
64
|
+
const response =
|
|
65
|
+
await resourcesFn({
|
|
66
|
+
...resourcesFnArgs,
|
|
67
|
+
params: {
|
|
68
|
+
...resourcesFnArgs?.params,
|
|
69
|
+
page,
|
|
70
|
+
per_page: constants.DEFAULT_LIMIT,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const nextResources = resourceName && response[resourceName] || response;
|
|
75
|
+
|
|
76
|
+
if (!nextResources?.length) {
|
|
77
|
+
console.log("No more resources found");
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
for (const resource of nextResources) {
|
|
82
|
+
yield resource;
|
|
83
|
+
resourcesCount += 1;
|
|
84
|
+
|
|
85
|
+
if (resourcesCount >= max) {
|
|
86
|
+
console.log("Reached max resources");
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
page += 1;
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
paginate(args = {}) {
|
|
95
|
+
return utils.iterate(this.getIterations(args));
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
};
|