Skip to content

Commit be2f9e9

Browse files
committed
Mailchimp and v0.3.0
1 parent c1d6f79 commit be2f9e9

File tree

9 files changed

+406
-19
lines changed

9 files changed

+406
-19
lines changed

samples/cat-facts/Adaptor.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { http } from "@openfn/language-common";
1+
import { http } from '@openfn/language-common';
22

33
const getCatBreeds = (callback) => async (state) => {
44
try {
5-
const responses = await http.get(`${state.configuration.baseUrl}/breeds`);
6-
const data = responses.data;
7-
const newState = { ...state, data: data, references: [] };
5+
const response = await http.get(`${state.configuration.baseUrl}/breeds`);
6+
const data = response.data;
7+
const newState = { ...state, data: data };
88
return callback(newState);
99
} catch (error) {
1010
console.error(error);
1111
return state;
1212
}
1313
};
1414

15-
export default getCatBreeds;
15+
export default getCatBreeds;

samples/mailchimp/Adaptor.d.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Adds a tag to a member of a list.
3+
* Sends a POST request to the /lists/{list_id}/members/{subscriber_hash}/tags endpoint of the Mailchimp API.
4+
* @parameter callback {{Function}} - a callback which is invoked with the resulting state at the end of this operation. Allows users to customise the resulting state. State.data includes the response from the Mailchimp API.
5+
* @returns A function that updates the state with the response from the Mailchimp API.
6+
*/
7+
declare function addTagToMember(callback: (fn: (inState: State) => State)): (outState: State) => State;
8+
type AddTagToMemberParams = {{ list_id: string; subscriber_hash: string; }};
9+
type AddTagToMemberResponse = any; // Update with the actual response type from the Mailchimp API
10+
type C = {{ baseUrl: string; }};
11+
type State<C = {{}}, D = {{}}> = {{ configuration: C; data: AddTagToMemberResponse; }};

samples/mailchimp/Adaptor.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { http } from '@openfn/language-common';
2+
3+
const addTagToMember = (callback) => async (outState) => {
4+
const { list_id, subscriber_hash } = outState.configuration;
5+
6+
try {
7+
const response = await http.post(`/lists/${list_id}/members/${subscriber_hash}/tags`);
8+
const newState = { ...outState, data: response.data };
9+
return callback(newState);
10+
} catch (error) {
11+
console.error(error);
12+
return outState;
13+
}
14+
};
15+
16+
export default addTagToMember;

samples/mailchimp/instruction.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Create an OpenFn function that accesses the /tagMembers endpoint
1+
Create an OpenFn function that adds a tag to a member via the /lists/{list_id}/members/{subscriber_hash}/tags endpoint

samples/mailchimp/spec.json

+249-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,249 @@
1-
// Mailchimp api spec goes here
1+
{
2+
"openapi": "3.0.0",
3+
"info": {
4+
"title": "Mailchimp API",
5+
"version": "1.0.0"
6+
},
7+
"paths": {
8+
"/lists/{list_id}/members/{subscriber_hash}/goals": {
9+
"get": {
10+
"summary": "Get Member Goals",
11+
"description": "Get information about recent goal events for a specific list member.",
12+
"operationId": "getListMemberGoals",
13+
"parameters": [
14+
{
15+
"name": "list_id",
16+
"in": "path",
17+
"required": true,
18+
"description": "The ID of the list.",
19+
"schema": {
20+
"type": "string"
21+
}
22+
},
23+
{
24+
"name": "subscriber_hash",
25+
"in": "path",
26+
"required": true,
27+
"description": "The hash of the subscriber.",
28+
"schema": {
29+
"type": "string"
30+
}
31+
}
32+
],
33+
"responses": {
34+
"200": {
35+
"description": "Successful response",
36+
"content": {
37+
"application/json": {
38+
"example": {}
39+
}
40+
}
41+
}
42+
}
43+
},
44+
"post": {
45+
"summary": "Create Member Goal",
46+
"description": "Create a new goal event for a specific list member.",
47+
"operationId": "createListMemberGoal",
48+
"parameters": [
49+
{
50+
"name": "list_id",
51+
"in": "path",
52+
"required": true,
53+
"description": "The ID of the list.",
54+
"schema": {
55+
"type": "string"
56+
}
57+
},
58+
{
59+
"name": "subscriber_hash",
60+
"in": "path",
61+
"required": true,
62+
"description": "The hash of the subscriber.",
63+
"schema": {
64+
"type": "string"
65+
}
66+
}
67+
],
68+
"requestBody": {
69+
"required": true,
70+
"content": {
71+
"application/json": {
72+
"example": {}
73+
}
74+
}
75+
},
76+
"responses": {
77+
"201": {
78+
"description": "Successful response",
79+
"content": {
80+
"application/json": {
81+
"example": {}
82+
}
83+
}
84+
}
85+
}
86+
}
87+
},
88+
"/lists/{list_id}/members/{subscriber_hash}/tags": {
89+
"get": {
90+
"summary": "Get Member Tags",
91+
"description": "Get all the tags assigned to a contact.",
92+
"operationId": "getListMemberTags",
93+
"parameters": [
94+
{
95+
"name": "list_id",
96+
"in": "path",
97+
"required": true,
98+
"description": "The ID of the list.",
99+
"schema": {
100+
"type": "string"
101+
}
102+
},
103+
{
104+
"name": "subscriber_hash",
105+
"in": "path",
106+
"required": true,
107+
"description": "The hash of the subscriber.",
108+
"schema": {
109+
"type": "string"
110+
}
111+
}
112+
],
113+
"responses": {
114+
"200": {
115+
"description": "Successful response",
116+
"content": {
117+
"application/json": {
118+
"example": {}
119+
}
120+
}
121+
}
122+
}
123+
},
124+
"post": {
125+
"summary": "Manage Member Tags",
126+
"description": "Manage the tags assigned to a contact.",
127+
"operationId": "manageListMemberTags",
128+
"parameters": [
129+
{
130+
"name": "list_id",
131+
"in": "path",
132+
"required": true,
133+
"description": "The ID of the list.",
134+
"schema": {
135+
"type": "string"
136+
}
137+
},
138+
{
139+
"name": "subscriber_hash",
140+
"in": "path",
141+
"required": true,
142+
"description": "The hash of the subscriber.",
143+
"schema": {
144+
"type": "string"
145+
}
146+
}
147+
],
148+
"requestBody": {
149+
"required": true,
150+
"content": {
151+
"application/json": {
152+
"example": {}
153+
}
154+
}
155+
},
156+
"responses": {
157+
"200": {
158+
"description": "Successful response",
159+
"content": {
160+
"application/json": {
161+
"example": {}
162+
}
163+
}
164+
}
165+
}
166+
}
167+
},
168+
"/lists/{list_id}/members/{subscriber_hash}/events": {
169+
"get": {
170+
"summary": "Get Member Events",
171+
"description": "Get website or in-app actions for a specific list member.",
172+
"operationId": "getListMemberEvents",
173+
"parameters": [
174+
{
175+
"name": "list_id",
176+
"in": "path",
177+
"required": true,
178+
"description": "The ID of the list.",
179+
"schema": {
180+
"type": "string"
181+
}
182+
},
183+
{
184+
"name": "subscriber_hash",
185+
"in": "path",
186+
"required": true,
187+
"description": "The hash of the subscriber.",
188+
"schema": {
189+
"type": "string"
190+
}
191+
}
192+
],
193+
"responses": {
194+
"200": {
195+
"description": "Successful response",
196+
"content": {
197+
"application/json": {
198+
"example": {}
199+
}
200+
}
201+
}
202+
}
203+
},
204+
"post": {
205+
"summary": "Trigger Member Events",
206+
"description": "Trigger targeted automations based on website or in-app actions.",
207+
"operationId": "triggerListMemberEvents",
208+
"parameters": [
209+
{
210+
"name": "list_id",
211+
"in": "path",
212+
"required": true,
213+
"description": "The ID of the list.",
214+
"schema": {
215+
"type": "string"
216+
}
217+
},
218+
{
219+
"name": "subscriber_hash",
220+
"in": "path",
221+
"required": true,
222+
"description": "The hash of the subscriber.",
223+
"schema": {
224+
"type": "string"
225+
}
226+
}
227+
],
228+
"requestBody": {
229+
"required": true,
230+
"content": {
231+
"application/json": {
232+
"example": {}
233+
}
234+
}
235+
},
236+
"responses": {
237+
"200": {
238+
"description": "Successful response",
239+
"content": {
240+
"application/json": {
241+
"example": {}
242+
}
243+
}
244+
}
245+
}
246+
}
247+
}
248+
}
249+
}

services/code_generator/code_generator/utils/prompts.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ def generate_prompt(prompt_name: str, signature: str, **kwargs) -> str:
22
prompt_template = prompts.get(prompt_name)
33
if prompt_template is None:
44
raise ValueError(f"Prompt '{prompt_name}' not found.")
5-
encoded_kwargs = {k: v.replace("\\n", "\n") for k, v in kwargs.items()}
5+
encoded_kwargs = {k: v.replace("{", "{{") for k, v in kwargs.items()}
6+
encoded_kwargs = {k: v.replace("}", "}}") for k, v in kwargs.items()}
67
if prompt_name == "code":
8+
print("signature")
9+
print(signature)
710
prompt_template[1]["content"] = prompt_template[1]["content"].format(
811
signature=signature
912
)

services/demo.py

+7-11
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,14 @@
88
end_point_signature = "http://localhost:8003/generate_signature_v2/"
99
end_point_code = "http://localhost:8004/generate_code/"
1010

11-
samples = [
12-
'cat-facts',
13-
# TODO - isma to uncomment, add spec, and run demo
14-
# 'mailchimp'
15-
]
11+
samples = ["mailchimp", "cat-facts"]
1612

1713
for i in samples:
1814
base_path = Path(f"../samples/{i}")
19-
15+
2016
# Opening JSON file
2117
spec_path = base_path / "spec.json"
22-
18+
2319
with spec_path.open("r") as file:
2420
full_spec = json.load(file)
2521

@@ -38,10 +34,10 @@
3834
response = requests.post(end_point_signature, json=data_full)
3935
signature = response.json()["signature"]
4036

41-
print(f'\nSignature:\n{signature}')
37+
print(f"\nSignature:\n{signature}")
4238

4339
dts_path = base_path / "Adaptor.d.ts"
44-
f = open(dts_path, 'w')
40+
f = open(dts_path, "w")
4541
f.write(signature)
4642
f.close()
4743

@@ -50,9 +46,9 @@
5046
response2 = requests.post(end_point_code, json=data)
5147
implementation = response2.json()["implementation"]
5248

53-
print(f'\nImplementation:\n{implementation}')
49+
print(f"\nImplementation:\n{implementation}")
5450

5551
adaptor_path = base_path / "Adaptor.js"
56-
f = open(adaptor_path, 'w')
52+
f = open(adaptor_path, "w")
5753
f.write(implementation)
5854
f.close()

0 commit comments

Comments
 (0)