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

🎉 Source Freshdesk: providing the updated_since parameter on the initial sync for Tickets stream #6442

Merged
merged 10 commits into from
Oct 13, 2021
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"sourceDefinitionId": "ec4b9503-13cb-48ab-a4ab-6ade4be46567",
"name": "Freshdesk",
"dockerRepository": "airbyte/source-freshdesk",
"dockerImageTag": "0.2.6",
"dockerImageTag": "0.2.7",
"documentationUrl": "https://docs.airbyte.io/integrations/sources/freshdesk",
"icon": "freshdesk.svg"
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
- sourceDefinitionId: ec4b9503-13cb-48ab-a4ab-6ade4be46567
name: Freshdesk
dockerRepository: airbyte/source-freshdesk
dockerImageTag: 0.2.6
dockerImageTag: 0.2.7
documentationUrl: https://docs.airbyte.io/integrations/sources/freshdesk
icon: freshdesk.svg
sourceType: api
Expand Down
3 changes: 3 additions & 0 deletions airbyte-integrations/connectors/source-freshdesk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.2.7
Add start_date parameter to specification from which to start pulling data.

## 0.2.6
Fix `unique_external_id` type in `contacts` schema. Should be a string
instead of an integer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ RUN pip install .

ENV AIRBYTE_ENTRYPOINT "/airbyte/base.sh"

LABEL io.airbyte.version=0.2.6
LABEL io.airbyte.version=0.2.7
LABEL io.airbyte.name=airbyte/source-freshdesk
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(
requests_per_minute: int = None,
verify: bool = True,
proxies: MutableMapping[str, Any] = None,
start_date: str = None,
):
"""Basic HTTP interface to read from endpoints"""
self._api_prefix = f"https://{domain.rstrip('/')}/api/v2/"
Expand All @@ -45,6 +46,12 @@ def __init__(

self._call_credit = CallCredit(balance=requests_per_minute) if requests_per_minute else None

# By default, only tickets that have been created within the past 30 days will be returned.
# Since this logic rely not on updated tickets, it can break tickets dependant streams - conversations.
# So updated_since parameter will be always used in tickets streams. And start_date will be used too
# with default value 30 days look back.
self._start_date = pendulum.parse(start_date) if start_date else pendulum.now() - pendulum.duration(days=30)

if domain.find("freshdesk.com") < 0:
raise AttributeError("Freshdesk v2 API works only via Freshdesk domains and not via custom CNAMEs")

Expand Down Expand Up @@ -166,7 +173,7 @@ def _state_params(self) -> Mapping[str, Any]:
"""Build query parameters responsible for current state"""
if self._state:
return {self.state_filter: self._state}
return {}
return {self.state_filter: self._api._start_date}

@property
def name(self):
Expand Down Expand Up @@ -340,9 +347,11 @@ def list(self, fields: Sequence[str] = None) -> Iterator[dict]:
yield from self.read(partial(self._api_get, url=url))


class SatisfactionRatingsAPI(ClientIncrementalStreamAPI):
class SatisfactionRatingsAPI(IncrementalStreamAPI):
"""Surveys satisfaction replies"""

state_filter = "created_since"

def list(self, fields: Sequence[str] = None) -> Iterator[dict]:
"""Iterate over entities"""
yield from self.read(partial(self._api_get, url="surveys/satisfaction_ratings"))
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@


class Client(BaseClient):
def __init__(self, domain, api_key, requests_per_minute: int = None):
self._api = API(domain=domain, api_key=api_key, requests_per_minute=requests_per_minute)
def __init__(self, domain, api_key, requests_per_minute: int = None, start_date: str = None):
self._api = API(domain=domain, api_key=api_key, requests_per_minute=requests_per_minute, start_date=start_date)
self._apis = {
"agents": AgentsAPI(self._api),
"companies": CompaniesAPI(self._api),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
"title": "Requests per minute",
"type": "integer",
"description": "Number of requests per minute that this source allowed to use."
},
keu marked this conversation as resolved.
Show resolved Hide resolved
"start_date": {
"title": "Start date",
"description": "Date from which to start pulling data.",
"format": "date-time",
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$",
Copy link
Contributor

Choose a reason for hiding this comment

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

why not just "format": "date-time"?

"examples": ["2020-12-01T00:00:00Z"]
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions docs/integrations/sources/freshdesk.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ The Freshdesk connector should not run into Freshdesk API limitations under norm

Please read [How to find your API key](https://support.freshdesk.com/support/solutions/articles/215517).

## Changelog

| Version | Date | Pull Request | Subject |
| :--- | :--- | :--- | :--- |
| 0.2.7 | 2021-10-13 | [6442](https://github.com/airbytehq/airbyte/pull/6442) | Add start_date parameter to specification from which to start pulling data. |