Skip to content
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

Feature to add a filtering options on the API call #145

Open
wants to merge 4 commits into
base: main
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
32 changes: 31 additions & 1 deletion tap_clickup/streams.py
Copy link
Contributor

@visch visch Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All changes from line 0 to line 50 need to go away

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Stream type classes for tap-clickup."""
from pathlib import Path
from typing import Optional, Any, Dict
from typing import Optional, Any, Dict, Iterable
import requests
from singer_sdk.helpers.jsonpath import extract_jsonpath
from tap_clickup.client import ClickUpStream
Expand All @@ -24,6 +24,15 @@ def get_child_context(self, record: dict, context: Optional[dict]) -> dict:
"team_id": record["id"],
}

def get_records(self, context: Optional[dict]) -> Iterable[dict]:
"""Return a generator of row-type dictionary objects."""
# If workspace_ids is empty, null, or nonexistant, default to using the API to
# determine all workspaces/teams.
if "workspace_ids" in self.config and self.config.get("workspace_ids"):
return [{"id": id} for id in self.config.get("workspace_ids")]
else:
return super().get_records(context=context)


class TimeEntries(ClickUpStream):
"""Time Entries"""
Expand Down Expand Up @@ -249,6 +258,27 @@ def get_url_params(
params["order_by"] = "updated"
params["reverse"] = "true"
params["date_updated_gt"] = self.get_starting_replication_key_value(context)

# If list_ids is empty, null, or nonexistant, default to using the API to
if "list_ids" in self.config and self.config.get("list_ids"):
params["list_ids"] = [item for item in self.config.get("list_ids")]

# If space_ids is empty, null, or nonexistant, default to using the API to
if "space_ids" in self.config and self.config.get("space_ids"):
params["space_ids"] = [item for item in self.config.get("space_ids")]

if "list_ids" in params and len(params["list_ids"]) == 1:
# To work around the ClickUp API bug that returns an error message stating
# "List ids must be an array" (ECODE: OAUTH_042), we should duplicate the list_id
# when there is only one, as the API requires an array format for list IDs.
params["list_ids"].append(params["list_ids"][0])

if "space_ids" in params and len(params["space_ids"]) == 1:
# To work around the ClickUp API bug that returns an error message stating
# "Space ids must be an array" (ECODE: OAUTH_042), we should duplicate the space_id
# when there is only one, as the API requires an array format for space IDs.
params["space_ids"].append(params["space_ids"][0])

return params

def get_next_page_token(
Expand Down
9 changes: 9 additions & 0 deletions tap_clickup/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ class TapClickUp(Tap):
th.Property(
"api_token", th.StringType, required=True, description="Example: 'pk_12345"
),
th.Property(
"workspace_ids", th.ArrayType(th.IntegerType), required=False, description="Example: '[20214542]'" # fetches the data for workspace_id
),
th.Property(
"space_ids", th.ArrayType(th.IntegerType), required=False, description="Example: '[45215477, 4547547]'" # fetches the data for workspace_id
),
th.Property(
"list_ids", th.ArrayType(th.IntegerType), required=False, description="Example: '[454455478, 784552187]'" # fetches the data for workspace_id
),
# Removing "official" start_date support re https://github.com/AutoIDM/tap-clickup/issues/118
# th.Property(
# "start_date",
Expand Down