File tree Expand file tree Collapse file tree 9 files changed +336
-16
lines changed Expand file tree Collapse file tree 9 files changed +336
-16
lines changed Original file line number Diff line number Diff line change 1+ import asters from "../../asters.app.mjs" ;
2+
3+ export default {
4+ key : "asters-list-labels" ,
5+ name : "List Labels" ,
6+ description : "Retrieve the list of all labels of a specific workspace. [See the documentation](https://docs.asters.ai/api/endpoints/labels)" ,
7+ type : "action" ,
8+ version : "0.0.1" ,
9+ props : {
10+ asters,
11+ workspaceId : {
12+ propDefinition : [
13+ asters ,
14+ "workspaceId" ,
15+ ] ,
16+ } ,
17+ } ,
18+ async run ( { $ } ) {
19+ const { data } = await this . asters . listLabels ( {
20+ workspaceId : this . workspaceId ,
21+ } ) ;
22+ $ . export ( "$summary" , `Successfully retrieved ${ data . length } label${ data . length === 1
23+ ? ""
24+ : "s" } `) ;
25+ return data ;
26+ } ,
27+ } ;
Original file line number Diff line number Diff line change 1+ import asters from "../../asters.app.mjs" ;
2+
3+ export default {
4+ key : "asters-list-posts-analytics" ,
5+ name : "List Posts Analytics" ,
6+ description : "Retrieve the list of posts' analytics of a social account. [See the documentation](https://docs.asters.ai/api/endpoints/analytics)" ,
7+ type : "action" ,
8+ version : "0.0.1" ,
9+ props : {
10+ asters,
11+ workspaceId : {
12+ propDefinition : [
13+ asters ,
14+ "workspaceId" ,
15+ ] ,
16+ } ,
17+ socialAccountId : {
18+ propDefinition : [
19+ asters ,
20+ "socialAccountId" ,
21+ ( c ) => ( {
22+ workspaceId : c . workspaceId ,
23+ } ) ,
24+ ] ,
25+ } ,
26+ fromDate : {
27+ propDefinition : [
28+ asters ,
29+ "fromDate" ,
30+ ] ,
31+ } ,
32+ toDate : {
33+ propDefinition : [
34+ asters ,
35+ "toDate" ,
36+ ] ,
37+ } ,
38+ } ,
39+ async run ( { $ } ) {
40+ const posts = await this . asters . getPaginatedResources ( {
41+ fn : this . asters . listPostAnalytics ,
42+ args : {
43+ data : {
44+ socialAccountId : this . socialAccountId ,
45+ filters : {
46+ date : {
47+ from : this . fromDate ,
48+ to : this . toDate ,
49+ } ,
50+ } ,
51+ } ,
52+ } ,
53+ } ) ;
54+ $ . export ( "$summary" , `Successfully retrieved ${ posts . length } post${ posts . length === 1
55+ ? ""
56+ : "s" } `) ;
57+ return posts ;
58+ } ,
59+ } ;
Original file line number Diff line number Diff line change 1+ import asters from "../../asters.app.mjs" ;
2+
3+ export default {
4+ key : "asters-list-posts" ,
5+ name : "List Posts" ,
6+ description : "Retrieve a list of posts of a social profile. [See the documentation](https://docs.asters.ai/api/endpoints/posts)" ,
7+ type : "action" ,
8+ version : "0.0.1" ,
9+ props : {
10+ asters,
11+ workspaceId : {
12+ propDefinition : [
13+ asters ,
14+ "workspaceId" ,
15+ ] ,
16+ } ,
17+ socialAccountId : {
18+ propDefinition : [
19+ asters ,
20+ "socialAccountId" ,
21+ ( c ) => ( {
22+ workspaceId : c . workspaceId ,
23+ } ) ,
24+ ] ,
25+ } ,
26+ fromDate : {
27+ propDefinition : [
28+ asters ,
29+ "fromDate" ,
30+ ] ,
31+ } ,
32+ toDate : {
33+ propDefinition : [
34+ asters ,
35+ "toDate" ,
36+ ] ,
37+ } ,
38+ } ,
39+ async run ( { $ } ) {
40+ const posts = await this . asters . getPaginatedResources ( {
41+ fn : this . asters . listPosts ,
42+ args : {
43+ data : {
44+ socialAccountId : this . socialAccountId ,
45+ filters : {
46+ date : {
47+ from : this . fromDate ,
48+ to : this . toDate ,
49+ } ,
50+ } ,
51+ } ,
52+ } ,
53+ } ) ;
54+ $ . export ( "$summary" , `Successfully retrieved ${ posts . length } post${ posts . length === 1
55+ ? ""
56+ : "s" } `) ;
57+ return posts ;
58+ } ,
59+ } ;
Original file line number Diff line number Diff line change 1+ import asters from "../../asters.app.mjs" ;
2+
3+ export default {
4+ key : "asters-list-social-accounts" ,
5+ name : "List Social Accounts" ,
6+ description : "Retrieve the list of all social accounts of a specific workspace. [See the documentation](https://docs.asters.ai/api/endpoints/social-accounts)" ,
7+ type : "action" ,
8+ version : "0.0.1" ,
9+ props : {
10+ asters,
11+ workspaceId : {
12+ propDefinition : [
13+ asters ,
14+ "workspaceId" ,
15+ ] ,
16+ } ,
17+ } ,
18+ async run ( { $ } ) {
19+ const { data } = await this . asters . listSocialAccounts ( {
20+ workspaceId : this . workspaceId ,
21+ } ) ;
22+ $ . export ( "$summary" , `Successfully retrieved ${ data . length } social account${ data . length === 1
23+ ? ""
24+ : "s" } `) ;
25+ return data ;
26+ } ,
27+ } ;
Original file line number Diff line number Diff line change @@ -30,6 +30,16 @@ export default {
3030 } ) ) ;
3131 } ,
3232 } ,
33+ fromDate : {
34+ type : "string" ,
35+ label : "From Date" ,
36+ description : "The date to start the search from (YYYY-MM-DD)" ,
37+ } ,
38+ toDate : {
39+ type : "string" ,
40+ label : "To Date" ,
41+ description : "The date to end the search (YYYY-MM-DD)" ,
42+ } ,
3343 } ,
3444 methods : {
3545 _baseUrl ( ) {
@@ -43,6 +53,7 @@ export default {
4353 headers : {
4454 "x-api-key" : `${ this . $auth . api_key } ` ,
4555 } ,
56+ debug : true ,
4657 ...opts ,
4758 } ) ;
4859 } ,
@@ -60,12 +71,62 @@ export default {
6071 ...opts ,
6172 } ) ;
6273 } ,
74+ listLabels ( {
75+ workspaceId, ...opts
76+ } ) {
77+ return this . _makeRequest ( {
78+ path : `/workspaces/${ workspaceId } /labels` ,
79+ ...opts ,
80+ } ) ;
81+ } ,
6382 listPosts ( opts = { } ) {
6483 return this . _makeRequest ( {
6584 method : "POST" ,
6685 path : "/data/posts" ,
6786 ...opts ,
6887 } ) ;
6988 } ,
89+ listPostAnalytics ( opts = { } ) {
90+ return this . _makeRequest ( {
91+ method : "POST" ,
92+ path : "/analytics/posts" ,
93+ ...opts ,
94+ } ) ;
95+ } ,
96+ async * paginate ( {
97+ fn, args, max,
98+ } ) {
99+ args = {
100+ ...args ,
101+ data : {
102+ ...args ?. data ,
103+ page : 1 ,
104+ } ,
105+ } ;
106+ let hasMore , count = 0 ;
107+ do {
108+ const {
109+ data, pagination,
110+ } = await fn ( args ) ;
111+ if ( ! data ?. length ) {
112+ return ;
113+ }
114+ for ( const item of data ) {
115+ yield item ;
116+ if ( max && ++ count >= max ) {
117+ return ;
118+ }
119+ }
120+ hasMore = pagination ?. totalPages > args . data . page ;
121+ args . data . page ++ ;
122+ } while ( hasMore ) ;
123+ } ,
124+ async getPaginatedResources ( opts ) {
125+ const results = [ ] ;
126+ for await ( const item of this . paginate ( opts ) ) {
127+ results . push ( item ) ;
128+ }
129+ return results ;
130+ } ,
70131 } ,
71132} ;
Original file line number Diff line number Diff line change 11import asters from "../../asters.app.mjs" ;
2- import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform" ;
2+ import {
3+ DEFAULT_POLLING_SOURCE_TIMER_INTERVAL , ConfigurationError ,
4+ } from "@pipedream/platform" ;
35
46export default {
57 props : {
@@ -14,4 +16,28 @@ export default {
1416 } ,
1517 } ,
1618 } ,
19+ methods : {
20+ getResourceFn ( ) {
21+ throw new ConfigurationError ( "getResourceFn must be implemented" ) ;
22+ } ,
23+ getArgs ( ) {
24+ throw new ConfigurationError ( "getArgs must be implemented" ) ;
25+ } ,
26+ generateMeta ( ) {
27+ throw new ConfigurationError ( "generateMeta must be implemented" ) ;
28+ } ,
29+ processResource ( ) {
30+ throw new ConfigurationError ( "processResource must be implemented" ) ;
31+ } ,
32+ } ,
33+ async run ( ) {
34+ const resources = await this . asters . getPaginatedResources ( {
35+ fn : this . getResourceFn ( ) ,
36+ args : this . getArgs ( ) ,
37+ } ) ;
38+
39+ for ( const resource of resources ) {
40+ await this . processResource ( resource ) ;
41+ }
42+ } ,
1743} ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11import common from "../common/base.mjs" ;
2+ import sampleEmit from "./test-event.mjs" ;
23
34export default {
45 ...common ,
56 key : "asters-new-label-added" ,
67 name : "New Label Added" ,
78 description : "Emit new event when a label is added to a post." ,
89 type : "source" ,
9- version : "0.0.{{ts}} " ,
10+ version : "0.0.1 " ,
1011 dedupe : "unique" ,
11- async run ( ) {
12+ props : {
13+ ...common . props ,
14+ workspaceId : {
15+ propDefinition : [
16+ common . props . asters ,
17+ "workspaceId" ,
18+ ] ,
19+ } ,
20+ socialAccountId : {
21+ propDefinition : [
22+ common . props . asters ,
23+ "socialAccountId" ,
24+ ( c ) => ( {
25+ workspaceId : c . workspaceId ,
26+ } ) ,
27+ ] ,
28+ } ,
1229 } ,
30+ methods : {
31+ ...common . methods ,
32+ getResourceFn ( ) {
33+ return this . asters . listPosts ;
34+ } ,
35+ getArgs ( ) {
36+ return {
37+ data : {
38+ socialAccountId : this . socialAccountId ,
39+ filters : {
40+ date : {
41+ from : "1979-01-01" ,
42+ to : new Date ( ) . toISOString ( ) ,
43+ } ,
44+ } ,
45+ } ,
46+ } ;
47+ } ,
48+ async processResource ( post ) {
49+ const { labels = [ ] } = post ;
50+ for ( const label of labels ) {
51+ const meta = this . generateMeta ( post , label ) ;
52+ this . $emit ( post , meta ) ;
53+ }
54+ } ,
55+ generateMeta ( post , label ) {
56+ return {
57+ id : `${ post . _id } -${ label . _id } ` ,
58+ summary : `New Label ${ label . _id } added to post ${ post . _id } ` ,
59+ ts : Date . now ( ) ,
60+ } ;
61+ } ,
62+ } ,
63+ sampleEmit,
1364} ;
You can’t perform that action at this time.
0 commit comments