File tree Expand file tree Collapse file tree 10 files changed +398
-7
lines changed
add-subscriber-to-segmentation-lists
remove-subscriber-from-segmentation-list Expand file tree Collapse file tree 10 files changed +398
-7
lines changed Original file line number Diff line number Diff line change 1+ import { parseObject } from "../../common/utils.mjs" ;
2+ import pingback from "../../pingback.app.mjs" ;
3+
4+ export default {
5+ name : "Add Subscriber To Segmentation Lists" ,
6+ description : "Add a subscriber to segmentation lists by email [See the documentation](https://developer.pingback.com/docs/api/add-subscriber-to-segment)" ,
7+ key : "pingback-add-subscriber-to-segmentation-lists" ,
8+ version : "0.0.1" ,
9+ type : "action" ,
10+ props : {
11+ pingback,
12+ email : {
13+ propDefinition : [
14+ pingback ,
15+ "email" ,
16+ ] ,
17+ } ,
18+ segmentationLists : {
19+ propDefinition : [
20+ pingback ,
21+ "segmentationLists" ,
22+ ] ,
23+ } ,
24+ } ,
25+ async run ( { $ } ) {
26+ const response = await this . pingback . addSubscriberToSegmentationLists ( {
27+ $,
28+ email : this . email ,
29+ data : {
30+ segmentationLists : parseObject ( this . segmentationLists ) ,
31+ } ,
32+ } ) ;
33+
34+ $ . export ( "$summary" , `Subscriber ${ this . email } added to segmentation list(s) successfully` ) ;
35+ return response ;
36+ } ,
37+ } ;
Original file line number Diff line number Diff line change 1+ import {
2+ parseCustomFields ,
3+ parseObject ,
4+ } from "../../common/utils.mjs" ;
5+ import pingback from "../../pingback.app.mjs" ;
6+
7+ export default {
8+ name : "Create Subscriber" ,
9+ description : "Create a new subscriber [See the documentation](https://developer.pingback.com/docs/api/create-subscriber)" ,
10+ key : "pingback-create-subscriber" ,
11+ version : "0.0.1" ,
12+ type : "action" ,
13+ props : {
14+ pingback,
15+ email : {
16+ propDefinition : [
17+ pingback ,
18+ "email" ,
19+ ] ,
20+ } ,
21+ phone : {
22+ propDefinition : [
23+ pingback ,
24+ "phone" ,
25+ ] ,
26+ } ,
27+ name : {
28+ propDefinition : [
29+ pingback ,
30+ "name" ,
31+ ] ,
32+ } ,
33+ status : {
34+ propDefinition : [
35+ pingback ,
36+ "status" ,
37+ ] ,
38+ } ,
39+ customFields : {
40+ propDefinition : [
41+ pingback ,
42+ "customFields" ,
43+ ] ,
44+ } ,
45+ segmentationLists : {
46+ propDefinition : [
47+ pingback ,
48+ "segmentationLists" ,
49+ ] ,
50+ } ,
51+ } ,
52+ async run ( { $ } ) {
53+ const data = {
54+ email : this . email ,
55+ phone : this . phone ,
56+ name : this . name ,
57+ status : this . status ,
58+ segmentationLists : parseObject ( this . segmentationLists ) ,
59+ } ;
60+
61+ data . customFields = parseCustomFields ( this . customFields ) ;
62+
63+ const response = await this . pingback . createSubscriber ( {
64+ $,
65+ data,
66+ } ) ;
67+
68+ $ . export ( "$summary" , `Subscriber created successfully with ID: ${ response . data . data . id } ` ) ;
69+ return response ;
70+ } ,
71+ } ;
Original file line number Diff line number Diff line change 1+ import { ConfigurationError } from "@pipedream/platform" ;
2+ import pingback from "../../pingback.app.mjs" ;
3+
4+ export default {
5+ name : "Get Subscriber" ,
6+ description : "Get a subscriber by email [See the documentation](https://developer.pingback.com/docs/api/get-subscriber)" ,
7+ key : "pingback-get-subscriber" ,
8+ version : "0.0.1" ,
9+ type : "action" ,
10+ props : {
11+ pingback,
12+ email : {
13+ propDefinition : [
14+ pingback ,
15+ "email" ,
16+ ] ,
17+ } ,
18+ } ,
19+ async run ( { $ } ) {
20+ try {
21+ const response = await this . pingback . getSubscriber ( {
22+ $,
23+ email : this . email ,
24+ } ) ;
25+
26+ $ . export ( "$summary" , `Subscriber retrieved successfully with email: ${ response . data . data . email } ` ) ;
27+ return response ;
28+ } catch ( { response } ) {
29+ throw new ConfigurationError ( response . data . error ) ;
30+ }
31+ } ,
32+ } ;
Original file line number Diff line number Diff line change 1+ import pingback from "../../pingback.app.mjs" ;
2+
3+ export default {
4+ name : "Remove Subscriber From Segmentation List" ,
5+ description : "Remove a subscriber from a segmentation list by email [See the documentation](https://developer.pingback.com/docs/api/remove-subscriber-from-segment)" ,
6+ key : "pingback-remove-subscriber-from-segmentation-list" ,
7+ version : "0.0.1" ,
8+ type : "action" ,
9+ props : {
10+ pingback,
11+ email : {
12+ propDefinition : [
13+ pingback ,
14+ "email" ,
15+ ] ,
16+ } ,
17+ segmentationListId : {
18+ propDefinition : [
19+ pingback ,
20+ "segmentationLists" ,
21+ ] ,
22+ type : "string[]" ,
23+ label : "Segmentation Lists" ,
24+ description : "Segmentation list ID to remove the subscriber from. You can get the ID by clicking audience and lists at Pingback dashboard." ,
25+ } ,
26+ } ,
27+ async run ( { $ } ) {
28+ const response = await this . pingback . removeSubscriberFromSegmentationList ( {
29+ $,
30+ email : this . email ,
31+ segmentationListId : this . segmentationListId ,
32+ } ) ;
33+
34+ $ . export ( "$summary" , `Subscriber ${ this . email } removed from segmentation list ${ this . segmentationListId } successfully` ) ;
35+ return response ;
36+ } ,
37+ } ;
Original file line number Diff line number Diff line change 1+ import { parseCustomFields } from "../../common/utils.mjs" ;
2+ import pingback from "../../pingback.app.mjs" ;
3+
4+ export default {
5+ name : "Update Subscriber" ,
6+ description : "Update a specific subscriber by email [See the documentation](https://developer.pingback.com/docs/api/update-subscriber)" ,
7+ key : "pingback-update-subscriber" ,
8+ version : "0.0.1" ,
9+ type : "action" ,
10+ props : {
11+ pingback,
12+ email : {
13+ propDefinition : [
14+ pingback ,
15+ "email" ,
16+ ] ,
17+ } ,
18+ phone : {
19+ propDefinition : [
20+ pingback ,
21+ "phone" ,
22+ ] ,
23+ } ,
24+ name : {
25+ propDefinition : [
26+ pingback ,
27+ "name" ,
28+ ] ,
29+ } ,
30+ status : {
31+ propDefinition : [
32+ pingback ,
33+ "status" ,
34+ ] ,
35+ } ,
36+ customFields : {
37+ propDefinition : [
38+ pingback ,
39+ "customFields" ,
40+ ] ,
41+ } ,
42+ } ,
43+ async run ( { $ } ) {
44+ const data = {
45+ phone : this . phone ,
46+ name : this . name ,
47+ status : this . status ,
48+ } ;
49+
50+ data . customFields = parseCustomFields ( this . customFields ) ;
51+
52+ const response = await this . pingback . updateSubscriber ( {
53+ $,
54+ email : this . email ,
55+ data,
56+ } ) ;
57+
58+ $ . export ( "$summary" , `Subscriber updated successfully with ID: ${ response . data . data . id } ` ) ;
59+ return response ;
60+ } ,
61+ } ;
Original file line number Diff line number Diff line change 1+ export const STATUS_OPTIONS = [
2+ {
3+ label : "Free Subscriber" ,
4+ value : "free_subscriber" ,
5+ } ,
6+ {
7+ label : "Paid Subscriber" ,
8+ value : "paid_subscriber" ,
9+ } ,
10+ {
11+ label : "Unsubscribed Subscriber" ,
12+ value : "unsubscribed_subscriber" ,
13+ } ,
14+ ] ;
Original file line number Diff line number Diff line change 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+ } ;
25+
26+ export const parseCustomFields = ( customFields ) => {
27+ const parsedCustomFields = Object . entries ( parseObject ( customFields ) || { } ) ;
28+ if ( parsedCustomFields . length ) {
29+ return parsedCustomFields . map ( ( [
30+ key ,
31+ value ,
32+ ] ) => ( {
33+ label : key ,
34+ value,
35+ } ) ) ;
36+ }
37+ } ;
Original file line number Diff line number Diff line change 11{
22 "name" : " @pipedream/pingback" ,
3- "version" : " 0.0.1 " ,
3+ "version" : " 0.1.0 " ,
44 "description" : " Pipedream Pingback Components" ,
55 "main" : " pingback.app.mjs" ,
66 "keywords" : [
1111 "author" : " Pipedream <support@pipedream.com> (https://pipedream.com/)" ,
1212 "publishConfig" : {
1313 "access" : " public"
14+ },
15+ "dependencies" : {
16+ "@pipedream/platform" : " ^3.1.0"
1417 }
15- }
18+ }
You can’t perform that action at this time.
0 commit comments