generated from Tauffer-Consulting/domino_pieces_repository_template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from Tauffer-Consulting/dev
Dev
- Loading branch information
Showing
37 changed files
with
1,180 additions
and
424 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
[![codecov](https://codecov.io/gh/Tauffer-Consulting/default_domino_pieces/graph/badge.svg?token=DLCDR2S3B6)](https://codecov.io/gh/Tauffer-Consulting/default_domino_pieces) | ||
|
||
# Default Domino Pieces | ||
Default Domino Pieces that comes pre-installed: | ||
Default Domino Pieces that comes pre-installed in every Domino workspace: | ||
|
||
- **SimpleLogPiece** - A simple logging Piece. | ||
- **SleepPiece** - A Piece that executes a Python sleep function for a user-defined duration. | ||
- **GetDateTimePiece** - A Piece that returns the current date and time. | ||
- **CustomPythonPiece** - A Piece that executes a user-defined Python function. | ||
- **GetDateTimePiece** - A Piece that returns the current date and time. | ||
- **GetItemFromArrayPiece** - A Piece that returns an item from an array. | ||
- **HttpRequestPiece** - A Piece that makes an HTTP request to a given URL. | ||
- **LogPiece** - A simple logging Piece. | ||
- **LoremIpsumPiece** - A Piece that returns a random Lorem Ipsum text. | ||
- **PageScrapperPiece** - A Piece that scrapes text from a web page, given a URL and a list of HTML tags. | ||
- **SleepPiece** - A Piece that sleeps for a given number of seconds. | ||
- **ToStringPiece** - A Piece that converts any input to string. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pytz==2023.3 | ||
pandas==2.1.2 | ||
Pillow==10.1.0 | ||
beautifulsoup4==4.12.2 | ||
beautifulsoup4==4.12.2 | ||
python-lorem==1.3.0.post1 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "HttpRequestPiece", | ||
"description": "Makes a HTTP request to a given URL.", | ||
"dependency": { | ||
"requirements_file": "requirements_0.txt" | ||
}, | ||
"tags": [ | ||
"default", | ||
"http", | ||
"request" | ||
], | ||
"style": { | ||
"node_label": "HTTP Request", | ||
"node_style": { | ||
"backgroundColor": "#b3cde8" | ||
}, | ||
"icon_class_name": "material-symbols:send" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from pydantic import BaseModel, Field | ||
from enum import Enum | ||
|
||
|
||
class MethodTypes(str, Enum): | ||
GET = 'GET' | ||
POST = 'POST' | ||
PUT = 'PUT' | ||
DELETE = 'DELETE' | ||
|
||
|
||
class InputModel(BaseModel): | ||
url: str = Field( | ||
description="URL to make a request to." | ||
) | ||
method: MethodTypes = Field( | ||
default=MethodTypes.GET, | ||
description="HTTP method to use." | ||
) | ||
bearer_token: str = Field( | ||
default=None, | ||
description="Bearer token to use for authentication." | ||
) | ||
body_json_data: str = Field( | ||
default="""{ | ||
"key_1": "value_1", | ||
"key_2": "value_2" | ||
} | ||
""", | ||
description="JSON data to send in the request body.", | ||
json_schema_extra={ | ||
'widget': "codeeditor-json", | ||
} | ||
) | ||
|
||
|
||
class OutputModel(BaseModel): | ||
base64_bytes_data: str = Field( | ||
description='Output data as base64 encoded string.' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from domino.base_piece import BasePiece | ||
from .models import InputModel, OutputModel | ||
import requests | ||
import base64 | ||
import json | ||
|
||
|
||
class HttpRequestPiece(BasePiece): | ||
def piece_function(self, input_data: InputModel): | ||
|
||
try: | ||
url = input_data.url | ||
method = input_data.method | ||
|
||
headers = {} | ||
if input_data.bearer_token: | ||
headers['Authorization'] = f'Bearer {input_data.bearer_token}' | ||
|
||
# Prepare the request body if applicable | ||
body_data = None | ||
if method in ["POST", "PUT"]: | ||
try: | ||
body_data = json.loads(input_data.body_json_data) | ||
except json.JSONDecodeError: | ||
raise Exception("Invalid JSON data in the request body.") | ||
|
||
# Send the HTTP request | ||
if method == "GET": | ||
response = requests.get(url, headers=headers) | ||
elif method == "POST": | ||
response = requests.post(url, headers=headers, json=body_data) | ||
elif method == "PUT": | ||
response = requests.put(url, headers=headers, json=body_data) | ||
elif method == "DELETE": | ||
response = requests.delete(url, headers=headers) | ||
else: | ||
raise Exception(f"Unsupported HTTP method: {method}") | ||
|
||
# Check for HTTP errors | ||
response.raise_for_status() | ||
|
||
except requests.RequestException as e: | ||
raise Exception(f"HTTP request error: {e}") | ||
|
||
# convert content to base64 | ||
base64_bytes_data = base64.b64encode(response.content).decode('utf-8') | ||
return OutputModel(base64_bytes_data=base64_bytes_data) |
Oops, something went wrong.