Skip to content

Commit

Permalink
Fix replication key timestamp issue (#8)
Browse files Browse the repository at this point in the history
* Update poetry requirements

* Change authentication to use APIKeyAuthenticator

* Change schema type of started_at
  • Loading branch information
stkbailey authored Dec 9, 2021
1 parent ce77ce3 commit 843b14b
Show file tree
Hide file tree
Showing 8 changed files with 390 additions and 276 deletions.
485 changes: 290 additions & 195 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tap-clockify"
version = "1.0.6"
version = "1.0.7"
description = "Singer tap for Clockify, built with the Meltano SDK for Singer Taps."
authors = ["Stephen Bailey <[email protected]>"]
license = "MIT"
Expand All @@ -18,9 +18,9 @@ classifiers=[
]

[tool.poetry.dependencies]
python = "<3.9,>=3.6.2"
python = "<3.10,>=3.6.2"
requests = "^2.25.1"
singer-sdk = "^0.3.3"
singer-sdk = "^>0.3.14"
black = "^21.7-beta.0"

[tool.poetry.dev-dependencies]
Expand Down
18 changes: 6 additions & 12 deletions tap_clockify/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
from typing import Any, Dict, Optional, Union, List, Iterable

from singer_sdk.authenticators import APIKeyAuthenticator
from singer_sdk.helpers.jsonpath import extract_jsonpath
from singer_sdk.streams import RESTStream

Expand All @@ -22,15 +23,10 @@ def url_base(self):
return f'https://api.clockify.me/api/v1/workspaces/{self.config["workspace"]}'

@property
def http_headers(self) -> dict:
"""Return the http headers needed."""
headers = {
"Content-Type": "application/json",
"x-api-key": self.config["api_key"],
}
if "user_agent" in self.config:
headers["User-Agent"] = self.config.get("user_agent")
return headers
def authenticator(self) -> APIKeyAuthenticator:
return APIKeyAuthenticator.create_for_stream(
self, key="x-api-key", value=self.config["api_key"], location="header"
)

def get_next_page_token(
self, response: requests.Response, previous_token: Optional[Any]
Expand All @@ -56,8 +52,6 @@ def get_url_params(
params["page"] = next_page_token
if self.replication_key:
start_time = self.get_starting_timestamp(context)
start_time_fmt = (
start_time.strftime("%Y-%m-%dT%H:%M:%SZ") if start_time else None
)
start_time_fmt = start_time.strftime("%Y-%m-%dT%H:%M:%SZ") if start_time else None
params["start"] = start_time_fmt
return params
22 changes: 14 additions & 8 deletions tap_clockify/schemas/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@
th.Property("template", th.BooleanType),
th.Property("public", th.BooleanType),
th.Property("color", th.StringType),
th.Property("estimate", th.ObjectType(
th.Property("estimate", th.StringType),
th.Property("type", th.StringType),
)),
th.Property("hourlyRate", th.ObjectType(
th.Property("amount", th.NumberType),
th.Property("currency", th.StringType),
)),
th.Property(
"estimate",
th.ObjectType(
th.Property("estimate", th.StringType),
th.Property("type", th.StringType),
),
),
th.Property(
"hourlyRate",
th.ObjectType(
th.Property("amount", th.NumberType),
th.Property("currency", th.StringType),
),
),
).to_dict()
15 changes: 9 additions & 6 deletions tap_clockify/schemas/time_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

schema = th.PropertiesList(
th.Property("id", th.StringType),
th.Property("started_at", th.StringType),
th.Property("started_at", th.DateTimeType),
th.Property("userId", th.StringType),
th.Property("projectId", th.StringType),
th.Property("taskId", th.StringType),
Expand All @@ -12,9 +12,12 @@
th.Property("isLocked", th.BooleanType),
th.Property("customFieldValues", th.ArrayType(th.StringType)),
th.Property("tagIds", th.ArrayType(th.StringType)),
th.Property("timeInterval", th.ObjectType(
th.Property("duration", th.StringType),
th.Property("end", th.StringType),
th.Property("start", th.StringType),
)),
th.Property(
"timeInterval",
th.ObjectType(
th.Property("duration", th.StringType),
th.Property("end", th.StringType),
th.Property("start", th.StringType),
),
),
).to_dict()
28 changes: 17 additions & 11 deletions tap_clockify/schemas/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@
th.Property("activeWorkspace", th.StringType),
th.Property("defaultWorkspace", th.StringType),
th.Property("status", th.StringType),
th.Property("memberships", th.ArrayType(
th.ObjectType(
th.Property("userId", th.StringType),
th.Property("hourlyRate", th.ObjectType(
th.Property("amount", th.NumberType),
th.Property("currency", th.StringType),
)),
th.Property("targetId", th.StringType),
th.Property("membershipType", th.StringType),
th.Property("membershipStatus", th.StringType),
)),
th.Property(
"memberships",
th.ArrayType(
th.ObjectType(
th.Property("userId", th.StringType),
th.Property(
"hourlyRate",
th.ObjectType(
th.Property("amount", th.NumberType),
th.Property("currency", th.StringType),
),
),
th.Property("targetId", th.StringType),
th.Property("membershipType", th.StringType),
th.Property("membershipStatus", th.StringType),
)
),
),
).to_dict()
88 changes: 50 additions & 38 deletions tap_clockify/schemas/workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,54 @@
th.Property("id", th.StringType),
th.Property("name", th.StringType),
th.Property("imageUrl", th.StringType),
th.Property("hourlyRate", th.ObjectType(
th.Property("amount", th.IntegerType),
th.Property("currency", th.StringType),
)),
th.Property("workspaceSettings", th.ObjectType(
th.Property("adminOnlyPages", th.ArrayType(th.StringType)),
th.Property("automaticLock", th.ObjectType(
th.Property("changeDay", th.StringType),
th.Property("dayOfMonth", th.IntegerType),
th.Property("firstDay", th.StringType),
th.Property("olderThanPeriod", th.StringType),
th.Property("olderThanValue", th.IntegerType),
th.Property("type", th.StringType),
)),
th.Property("canSeeTimeSheet", th.BooleanType),
th.Property("canSeeTimeTracker", th.BooleanType),
th.Property("defaultBillableProjects", th.BooleanType),
th.Property("forceDescription", th.BooleanType),
th.Property("forceProjects", th.BooleanType),
th.Property("forceTags", th.BooleanType),
th.Property("forceTasks", th.BooleanType),
th.Property("lockTimeEntries", th.StringType),
th.Property("onlyAdminsCreateProject", th.BooleanType),
th.Property("onlyAdminsCreateTag", th.BooleanType),
th.Property("onlyAdminsSeeAllTimeEntries", th.BooleanType),
th.Property("onlyAdminsSeeBillableRates", th.BooleanType),
th.Property("onlyAdminsSeeDashboard", th.BooleanType),
th.Property("onlyAdminsSeePublicProjectsEntries", th.BooleanType),
th.Property("projectFavorites", th.BooleanType),
th.Property("projectGroupingLabel", th.StringType),
th.Property("projectPickerSpecialFilter", th.BooleanType),
th.Property("round", th.ObjectType(
th.Property("minutes", th.StringType),
th.Property("round", th.StringType),
)),
th.Property("timeRoundingInReports", th.BooleanType),
th.Property("trackTimeDownToSecond", th.BooleanType),
)),
th.Property(
"hourlyRate",
th.ObjectType(
th.Property("amount", th.IntegerType),
th.Property("currency", th.StringType),
),
),
th.Property(
"workspaceSettings",
th.ObjectType(
th.Property("adminOnlyPages", th.ArrayType(th.StringType)),
th.Property(
"automaticLock",
th.ObjectType(
th.Property("changeDay", th.StringType),
th.Property("dayOfMonth", th.IntegerType),
th.Property("firstDay", th.StringType),
th.Property("olderThanPeriod", th.StringType),
th.Property("olderThanValue", th.IntegerType),
th.Property("type", th.StringType),
),
),
th.Property("canSeeTimeSheet", th.BooleanType),
th.Property("canSeeTimeTracker", th.BooleanType),
th.Property("defaultBillableProjects", th.BooleanType),
th.Property("forceDescription", th.BooleanType),
th.Property("forceProjects", th.BooleanType),
th.Property("forceTags", th.BooleanType),
th.Property("forceTasks", th.BooleanType),
th.Property("lockTimeEntries", th.StringType),
th.Property("onlyAdminsCreateProject", th.BooleanType),
th.Property("onlyAdminsCreateTag", th.BooleanType),
th.Property("onlyAdminsSeeAllTimeEntries", th.BooleanType),
th.Property("onlyAdminsSeeBillableRates", th.BooleanType),
th.Property("onlyAdminsSeeDashboard", th.BooleanType),
th.Property("onlyAdminsSeePublicProjectsEntries", th.BooleanType),
th.Property("projectFavorites", th.BooleanType),
th.Property("projectGroupingLabel", th.StringType),
th.Property("projectPickerSpecialFilter", th.BooleanType),
th.Property(
"round",
th.ObjectType(
th.Property("minutes", th.StringType),
th.Property("round", th.StringType),
),
),
th.Property("timeRoundingInReports", th.BooleanType),
th.Property("trackTimeDownToSecond", th.BooleanType),
),
),
).to_dict()
4 changes: 1 addition & 3 deletions tap_clockify/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
from tap_clockify.tap import TapClockify

SAMPLE_CONFIG = {
"start_date": datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%dT%H:%M:%SZ"
),
"start_date": datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
"api_key": os.environ["TAP_CLOCKIFY_API_KEY"],
"workspace": os.environ["TAP_CLOCKIFY_WORKSPACE"],
}
Expand Down

0 comments on commit 843b14b

Please sign in to comment.