Skip to content

Commit

Permalink
✨ [source-orb] add end date parameter (#36288)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosmarxm committed Mar 22, 2024
1 parent 17a7e46 commit 374771c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 23 deletions.
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-orb/metadata.yaml
Expand Up @@ -4,7 +4,7 @@ data:
connectorSubtype: api
connectorType: source
definitionId: 7f0455fb-4518-4ec0-b7a3-d808bf8081cc
dockerImageTag: 1.1.2
dockerImageTag: 1.2.0
dockerRepository: airbyte/source-orb
githubIssueLabel: source-orb
icon: orb.svg
Expand Down
28 changes: 14 additions & 14 deletions airbyte-integrations/connectors/source-orb/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions airbyte-integrations/connectors/source-orb/pyproject.toml
Expand Up @@ -3,7 +3,7 @@ requires = [ "poetry-core>=1.0.0",]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
version = "1.1.2"
version = "1.2.0"
name = "source-orb"
description = "Source implementation for Orb."
authors = [ "Airbyte <contact@airbyte.io>",]
Expand All @@ -17,7 +17,7 @@ include = "source_orb"

[tool.poetry.dependencies]
python = "^3.9,<3.12"
airbyte-cdk = "==0.68.4"
airbyte-cdk = "==0.72.1"
pendulum = "==2.1.2"

[tool.poetry.scripts]
Expand Down
10 changes: 7 additions & 3 deletions airbyte-integrations/connectors/source-orb/source_orb/source.py
Expand Up @@ -27,9 +27,10 @@ class OrbStream(HttpStream, ABC):
page_size = 50
url_base = ORB_API_BASE_URL

def __init__(self, start_date: Optional[pendulum.DateTime] = None, **kwargs):
def __init__(self, start_date: Optional[pendulum.DateTime] = None, end_date: Optional[pendulum.DateTime] = None, **kwargs):
super().__init__(**kwargs)
self.start_date = start_date
self.end_date = end_date

def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, Any]]:
"""
Expand Down Expand Up @@ -143,6 +144,10 @@ def request_params(self, stream_state: Mapping[str, Any], **kwargs) -> MutableMa
# This may (reasonably) override the existing `created_at[gte]` set based on the start_date
# of the stream, as configured.
params[f"{self.cursor_field}[gte]"] = state_based_start_timestamp

if self.end_date:
params[f"{self.cursor_field}[lte]"] = self.end_date

return params


Expand Down Expand Up @@ -733,14 +738,13 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]:
subscription_usage_grouping_key = config.get("subscription_usage_grouping_key")
plan_id = config.get("plan_id")
start_date = to_datetime(config.get("start_date"))
# this field is not exposed to spec, used only for testing purposes
end_date = to_datetime(config.get("end_date"))

if not self.input_keys_mutually_exclusive(string_event_properties_keys, numeric_event_properties_keys):
raise ValueError("Supplied property keys for string and numeric valued property values must be mutually exclusive.")

return [
Customers(authenticator=authenticator, lookback_window_days=lookback_window, start_date=start_date),
Customers(authenticator=authenticator, lookback_window_days=lookback_window, start_date=start_date, end_date=end_date),
Subscriptions(authenticator=authenticator, lookback_window_days=lookback_window, start_date=start_date),
Plans(authenticator=authenticator, lookback_window_days=lookback_window, start_date=start_date),
Invoices(authenticator=authenticator, lookback_window_days=lookback_window),
Expand Down
14 changes: 11 additions & 3 deletions airbyte-integrations/connectors/source-orb/source_orb/spec.json
Expand Up @@ -22,13 +22,21 @@
"examples": ["2022-03-01T00:00:00Z"],
"order": 2
},
"end_date": {
"type": "string",
"title": "End Date",
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$",
"description": "UTC date and time in the format 2022-03-01T00:00:00Z. Any data with created_at after this data will not be synced. For Subscription Usage, this becomes the `timeframe_start` API parameter.",
"examples": ["2024-03-01T00:00:00Z"],
"order": 3
},
"lookback_window_days": {
"type": "integer",
"title": "Lookback Window (in days)",
"default": 0,
"minimum": 0,
"description": "When set to N, the connector will always refresh resources created within the past N days. By default, updated objects that are not newly created are not incrementally synced.",
"order": 3
"order": 4
},
"string_event_properties_keys": {
"type": "array",
Expand All @@ -37,7 +45,7 @@
},
"title": "Event properties keys (string values)",
"description": "Property key names to extract from all events, in order to enrich ledger entries corresponding to an event deduction.",
"order": 4
"order": 5
},
"numeric_event_properties_keys": {
"type": "array",
Expand All @@ -46,7 +54,7 @@
},
"title": "Event properties keys (numeric values)",
"description": "Property key names to extract from all events, in order to enrich ledger entries corresponding to an event deduction.",
"order": 5
"order": 6
},
"subscription_usage_grouping_key": {
"type": "string",
Expand Down
5 changes: 5 additions & 0 deletions docs/integrations/sources/orb.md
Expand Up @@ -42,6 +42,10 @@ The Orb connector should not run into Orb API limitations under normal usage. Pl
The `credit_ledger_entries` stream will now include `events` data. This upgrade uses the `created_at` timestamps from the `credits` to establish a 30-day timeframe, with the earliest `created_at` as the starting point. This restriction is set by the Orb API.
:::

:::info
If you are using the `start_date` and `end_date` parameter with the `credit_ledger_entries` stream it will sync all customers created during the that time window. It isn't possible to query data directly to `credit_ledger_entries`. The connector need to retrieve data from customers first to ingest the credit data.
:::

## Getting started

### Requirements
Expand All @@ -58,6 +62,7 @@ an Orb Account and API Key.

| Version | Date | Pull Request | Subject |
| --- |------------|----------------------------------------------------------| --- |
| 1.2.0 | 2024-03-19 | [x](https://github.com/airbytehq/airbyte/pull/x) | Expose `end_date`parameter |
| 1.1.2 | 2024-03-13 | [x](https://github.com/airbytehq/airbyte/pull/x) | Fix window to 30 days for events query timesframe start and query |
| 1.1.1 | 2024-02-07 | [35005](https://github.com/airbytehq/airbyte/pull/35005) | Pass timeframe_start, timeframe_end to events query |
| 1.1.0 | 2023-03-03 | [24567](https://github.com/airbytehq/airbyte/pull/24567) | Add Invoices incremental stream merged from [#24737](https://github.com/airbytehq/airbyte/pull/24737) |
Expand Down

0 comments on commit 374771c

Please sign in to comment.