Skip to content

Commit

Permalink
Mailchimp and v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ismaoxolo committed Dec 1, 2023
1 parent c1d6f79 commit be2f9e9
Show file tree
Hide file tree
Showing 9 changed files with 406 additions and 19 deletions.
10 changes: 5 additions & 5 deletions samples/cat-facts/Adaptor.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { http } from "@openfn/language-common";
import { http } from '@openfn/language-common';

const getCatBreeds = (callback) => async (state) => {
try {
const responses = await http.get(`${state.configuration.baseUrl}/breeds`);
const data = responses.data;
const newState = { ...state, data: data, references: [] };
const response = await http.get(`${state.configuration.baseUrl}/breeds`);
const data = response.data;
const newState = { ...state, data: data };
return callback(newState);
} catch (error) {
console.error(error);
return state;
}
};

export default getCatBreeds;
export default getCatBreeds;
11 changes: 11 additions & 0 deletions samples/mailchimp/Adaptor.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Adds a tag to a member of a list.
* Sends a POST request to the /lists/{list_id}/members/{subscriber_hash}/tags endpoint of the Mailchimp API.
* @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.
* @returns A function that updates the state with the response from the Mailchimp API.
*/
declare function addTagToMember(callback: (fn: (inState: State) => State)): (outState: State) => State;
type AddTagToMemberParams = {{ list_id: string; subscriber_hash: string; }};
type AddTagToMemberResponse = any; // Update with the actual response type from the Mailchimp API
type C = {{ baseUrl: string; }};
type State<C = {{}}, D = {{}}> = {{ configuration: C; data: AddTagToMemberResponse; }};
16 changes: 16 additions & 0 deletions samples/mailchimp/Adaptor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { http } from '@openfn/language-common';

const addTagToMember = (callback) => async (outState) => {
const { list_id, subscriber_hash } = outState.configuration;

try {
const response = await http.post(`/lists/${list_id}/members/${subscriber_hash}/tags`);
const newState = { ...outState, data: response.data };
return callback(newState);
} catch (error) {
console.error(error);
return outState;
}
};

export default addTagToMember;
2 changes: 1 addition & 1 deletion samples/mailchimp/instruction.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Create an OpenFn function that accesses the /tagMembers endpoint
Create an OpenFn function that adds a tag to a member via the /lists/{list_id}/members/{subscriber_hash}/tags endpoint
250 changes: 249 additions & 1 deletion samples/mailchimp/spec.json
Original file line number Diff line number Diff line change
@@ -1 +1,249 @@
// Mailchimp api spec goes here
{
"openapi": "3.0.0",
"info": {
"title": "Mailchimp API",
"version": "1.0.0"
},
"paths": {
"/lists/{list_id}/members/{subscriber_hash}/goals": {
"get": {
"summary": "Get Member Goals",
"description": "Get information about recent goal events for a specific list member.",
"operationId": "getListMemberGoals",
"parameters": [
{
"name": "list_id",
"in": "path",
"required": true,
"description": "The ID of the list.",
"schema": {
"type": "string"
}
},
{
"name": "subscriber_hash",
"in": "path",
"required": true,
"description": "The hash of the subscriber.",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"example": {}
}
}
}
}
},
"post": {
"summary": "Create Member Goal",
"description": "Create a new goal event for a specific list member.",
"operationId": "createListMemberGoal",
"parameters": [
{
"name": "list_id",
"in": "path",
"required": true,
"description": "The ID of the list.",
"schema": {
"type": "string"
}
},
{
"name": "subscriber_hash",
"in": "path",
"required": true,
"description": "The hash of the subscriber.",
"schema": {
"type": "string"
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"example": {}
}
}
},
"responses": {
"201": {
"description": "Successful response",
"content": {
"application/json": {
"example": {}
}
}
}
}
}
},
"/lists/{list_id}/members/{subscriber_hash}/tags": {
"get": {
"summary": "Get Member Tags",
"description": "Get all the tags assigned to a contact.",
"operationId": "getListMemberTags",
"parameters": [
{
"name": "list_id",
"in": "path",
"required": true,
"description": "The ID of the list.",
"schema": {
"type": "string"
}
},
{
"name": "subscriber_hash",
"in": "path",
"required": true,
"description": "The hash of the subscriber.",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"example": {}
}
}
}
}
},
"post": {
"summary": "Manage Member Tags",
"description": "Manage the tags assigned to a contact.",
"operationId": "manageListMemberTags",
"parameters": [
{
"name": "list_id",
"in": "path",
"required": true,
"description": "The ID of the list.",
"schema": {
"type": "string"
}
},
{
"name": "subscriber_hash",
"in": "path",
"required": true,
"description": "The hash of the subscriber.",
"schema": {
"type": "string"
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"example": {}
}
}
},
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"example": {}
}
}
}
}
}
},
"/lists/{list_id}/members/{subscriber_hash}/events": {
"get": {
"summary": "Get Member Events",
"description": "Get website or in-app actions for a specific list member.",
"operationId": "getListMemberEvents",
"parameters": [
{
"name": "list_id",
"in": "path",
"required": true,
"description": "The ID of the list.",
"schema": {
"type": "string"
}
},
{
"name": "subscriber_hash",
"in": "path",
"required": true,
"description": "The hash of the subscriber.",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"example": {}
}
}
}
}
},
"post": {
"summary": "Trigger Member Events",
"description": "Trigger targeted automations based on website or in-app actions.",
"operationId": "triggerListMemberEvents",
"parameters": [
{
"name": "list_id",
"in": "path",
"required": true,
"description": "The ID of the list.",
"schema": {
"type": "string"
}
},
{
"name": "subscriber_hash",
"in": "path",
"required": true,
"description": "The hash of the subscriber.",
"schema": {
"type": "string"
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"example": {}
}
}
},
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"example": {}
}
}
}
}
}
}
}
}
5 changes: 4 additions & 1 deletion services/code_generator/code_generator/utils/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ def generate_prompt(prompt_name: str, signature: str, **kwargs) -> str:
prompt_template = prompts.get(prompt_name)
if prompt_template is None:
raise ValueError(f"Prompt '{prompt_name}' not found.")
encoded_kwargs = {k: v.replace("\\n", "\n") for k, v in kwargs.items()}
encoded_kwargs = {k: v.replace("{", "{{") for k, v in kwargs.items()}
encoded_kwargs = {k: v.replace("}", "}}") for k, v in kwargs.items()}
if prompt_name == "code":
print("signature")
print(signature)
prompt_template[1]["content"] = prompt_template[1]["content"].format(
signature=signature
)
Expand Down
18 changes: 7 additions & 11 deletions services/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@
end_point_signature = "http://localhost:8003/generate_signature_v2/"
end_point_code = "http://localhost:8004/generate_code/"

samples = [
'cat-facts',
# TODO - isma to uncomment, add spec, and run demo
# 'mailchimp'
]
samples = ["mailchimp", "cat-facts"]

for i in samples:
base_path = Path(f"../samples/{i}")

# Opening JSON file
spec_path = base_path / "spec.json"

with spec_path.open("r") as file:
full_spec = json.load(file)

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

print(f'\nSignature:\n{signature}')
print(f"\nSignature:\n{signature}")

dts_path = base_path / "Adaptor.d.ts"
f = open(dts_path, 'w')
f = open(dts_path, "w")
f.write(signature)
f.close()

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

print(f'\nImplementation:\n{implementation}')
print(f"\nImplementation:\n{implementation}")

adaptor_path = base_path / "Adaptor.js"
f = open(adaptor_path, 'w')
f = open(adaptor_path, "w")
f.write(implementation)
f.close()
Loading

0 comments on commit be2f9e9

Please sign in to comment.