Skip to content

Add Zapier integration #450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1426,3 +1426,5 @@ option(BUILD_EXAMPLES "Build Hyperscan example code (default TRUE)" TRUE)
if(NOT WIN32 AND BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

add_subdirectory(zapier)
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,35 @@ sending email to the list, or by creating an issue on Github.
If you wish to contact the Hyperscan team at Intel directly, without posting
publicly to the mailing list, send email to
[hyperscan@intel.com](mailto:hyperscan@intel.com).

# Zapier Integration

To integrate Hyperscan with the Zapier platform, follow these steps:

1. Ensure you have the `requests` library installed. You can install it using pip:
```
pip install requests
```

2. Use the functions provided in the `zapier/zapier_integration.py` file to handle triggers and actions for Zapier. For example:
```python
from zapier.zapier_integration import trigger_event, action_create_item, action_update_item, action_delete_item

# Trigger an event
response = trigger_event("event_name", {"key": "value"})
print(response)

# Create an item
response = action_create_item("item_name", {"key": "value"})
print(response)

# Update an item
response = action_update_item("item_id", {"key": "value"})
print(response)

# Delete an item
response = action_delete_item("item_id")
print(response)
```

3. Refer to the `zapier/zapier_integration.py` file for more details on the available functions and their usage.
68 changes: 68 additions & 0 deletions unit/zapier_integration_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <zapier/zapier_integration.py>

using namespace testing;

class ZapierIntegrationTest : public Test {
protected:
void SetUp() override {
// Set up any necessary preconditions for the tests
}

void TearDown() override {
// Clean up any resources used by the tests
}
};

TEST_F(ZapierIntegrationTest, TriggerEvent) {
// Mock the requests.post function
MockFunction<requests::post> mock_post;
EXPECT_CALL(mock_post, Call(_, _))
.WillOnce(Return(MockResponse(200, R"({"status": "success"})")));

// Call the trigger_event function
auto response = trigger_event("test_event", {{"key", "value"}});

// Verify the response
EXPECT_EQ(response["status"], "success");
}

TEST_F(ZapierIntegrationTest, ActionCreateItem) {
// Mock the requests.post function
MockFunction<requests::post> mock_post;
EXPECT_CALL(mock_post, Call(_, _))
.WillOnce(Return(MockResponse(200, R"({"status": "success"})")));

// Call the action_create_item function
auto response = action_create_item("test_item", {{"key", "value"}});

// Verify the response
EXPECT_EQ(response["status"], "success");
}

TEST_F(ZapierIntegrationTest, ActionUpdateItem) {
// Mock the requests.post function
MockFunction<requests::post> mock_post;
EXPECT_CALL(mock_post, Call(_, _))
.WillOnce(Return(MockResponse(200, R"({"status": "success"})")));

// Call the action_update_item function
auto response = action_update_item("test_item_id", {{"key", "value"}});

// Verify the response
EXPECT_EQ(response["status"], "success");
}

TEST_F(ZapierIntegrationTest, ActionDeleteItem) {
// Mock the requests.post function
MockFunction<requests::post> mock_post;
EXPECT_CALL(mock_post, Call(_, _))
.WillOnce(Return(MockResponse(200, R"({"status": "success"})")));

// Call the action_delete_item function
auto response = action_delete_item("test_item_id");

// Verify the response
EXPECT_EQ(response["status"], "success");
}
41 changes: 41 additions & 0 deletions zapier/zapier_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import requests

ZAPIER_WEBHOOK_URL = "https://hooks.zapier.com/hooks/catch/123456/abcdef/"

def trigger_event(event_name, data):
payload = {
"event": event_name,
"data": data
}
response = requests.post(ZAPIER_WEBHOOK_URL, json=payload)
response.raise_for_status()
return response.json()

def action_create_item(item_name, item_data):
payload = {
"action": "create_item",
"item_name": item_name,
"item_data": item_data
}
response = requests.post(ZAPIER_WEBHOOK_URL, json=payload)
response.raise_for_status()
return response.json()

def action_update_item(item_id, item_data):
payload = {
"action": "update_item",
"item_id": item_id,
"item_data": item_data
}
response = requests.post(ZAPIER_WEBHOOK_URL, json=payload)
response.raise_for_status()
return response.json()

def action_delete_item(item_id):
payload = {
"action": "delete_item",
"item_id": item_id
}
response = requests.post(ZAPIER_WEBHOOK_URL, json=payload)
response.raise_for_status()
return response.json()