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 Chargebee: add "custom fields" to the relevant data streams #17056

Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ RUN pip install .

ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.1.13
LABEL io.airbyte.version=0.1.14
LABEL io.airbyte.name=airbyte/source-chargebee
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@
}
}
}
},
"custom_fields": {
"type": ["null", "array"],
"items" : {
"type" : ["null", "object"],
"properties": {
"name" : {
"type" : ["null", "string"]
},
"value": {
"type": ["null", "string"]
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,19 @@
"object": {
"type": ["string", "null"]
}
},
"custom_fields": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties" : {
"name" : {
"type" : ["null", "string"]
},
"value" : {
"type" : ["null", "string"]
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@
}
}
}
},
"custom_fields": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"name": {
"type": ["null", "string"]
},
"value": {
"type": ["null", "string"]
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,20 @@
}
}
}
},
"custom_fields": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"name": {
"type": ["null", "string"]
},
"value": {
"type": ["null", "string"]
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,20 @@
"meta_data": {
"type": ["object", "null"],
"properties": {}
},
"custom_fields": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"name": {
"type": ["null", "string"]
},
"value": {
"type": ["null", "string"]
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@
}
}
}
},
"custom_fields": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"name": {
"type": ["null", "string"]
},
"value": {
"type": ["null", "string"]
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,20 @@
"enum": ["not_validated", "valid", "partially_valid", "invalid"]
}
}
},
"custom_fields": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"name": {
"type": ["null", "string"]
},
"value": {
"type": ["null", "string"]
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@
},
"object": {
"type": ["string", "null"]
},
"custom_fields": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"name": {
"type": ["null", "string"]
},
"value": {
"type": ["null", "string"]
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,20 @@
},
"object": {
"type": ["string", "null"]
},
"custom_fields": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"name": {
"type": ["null", "string"]
},
"value": {
"type": ["null", "string"]
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,20 @@
}
}
}
},
"custom_fields": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"name": {
"type": ["null", "string"]
},
"value": {
"type": ["null", "string"]
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,20 @@
}
}
}
},
"custom_fields": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"name": {
"type": ["null", "string"]
},
"value": {
"type": ["null", "string"]
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,20 @@
}
}
}
},
"custom_fields": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"name": {
"type": ["null", "string"]
},
"value": {
"type": ["null", "string"]
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,20 @@
}
}
}
},
"custom_fields": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"name": {
"type": ["null", "string"]
},
"value": {
"type": ["null", "string"]
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from chargebee.models import Transaction as TransactionModel

from .rate_limiting import default_backoff_handler
from .utils import transform_custom_fields

# Backoff params below according to Chargebee's guidance on rate limit.
# https://apidocs.chargebee.com/docs/api?prod_cat_ver=2#api_rate_limits
Expand Down Expand Up @@ -59,7 +60,7 @@ def request_params(

def parse_response(self, list_result: ListResult, **kwargs) -> Iterable[Mapping]:
for message in list_result:
yield message._response[self.name]
yield from transform_custom_fields(message._response[self.name])

@default_backoff_handler(max_tries=MAX_TRIES, factor=MAX_TIME)
def _send_request(self, **kwargs) -> ListResult:
Expand Down Expand Up @@ -133,7 +134,7 @@ def parse_response(
for message in list_result:
record = message._response[self.name]
if record[self.cursor_field] > starting_point:
yield record
yield from transform_custom_fields(record)

def get_updated_state(self, current_stream_state: MutableMapping[str, Any], latest_record: Mapping[str, Any]):
"""
Expand Down Expand Up @@ -179,7 +180,7 @@ def request_params(

def parse_response(self, list_result: ListResult, **kwargs) -> Iterable[Mapping]:
for message in list_result:
yield message._response[self.name]
yield from transform_custom_fields(message._response[self.name])

def get_updated_state(self, current_stream_state: MutableMapping[str, Any], latest_record: Mapping[str, Any]):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from typing import Any, Dict


def transform_custom_fields(record: Dict[str, Any]) -> Dict[str, Any]:
"""
Method to detect custom fields that start with 'cf_' from chargbee models.
Args:
record:
{
...
'cf_custom_fields': 'some_value',
...
}

Returns:
record:
{
...
'custom_fields': [{
'name': 'cf_custom_fields',
'value': some_value'
}],
...
}
"""
custom_fields = []

for key, value in record.items():
if key.startswith('cf_'):
custom_fields.append({"name": key, "value": value})

record['custom_fields'] = custom_fields

yield record
33 changes: 17 additions & 16 deletions docs/integrations/sources/chargebee.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,21 @@ regardless of how many AttachedItems were actually changed or synced in a partic

## Changelog

| Version | Date | Pull Request | Subject |
| :--- | :--- | :--- | :--- |
| 0.1.13 | 2022-08-18 | [15743](https://github.com/airbytehq/airbyte/pull/15743) | Fix transaction `exchange_rate` field type |
| 0.1.12 | 2022-07-13 | [14672](https://github.com/airbytehq/airbyte/pull/14672) | Fix transaction sort by |
| 0.1.11 | 2022-03-03 | [10827](https://github.com/airbytehq/airbyte/pull/10827) | Fix Credit Note stream |
| 0.1.10 | 2022-03-02 | [10795](https://github.com/airbytehq/airbyte/pull/10795) | Add support for Credit Note stream |
| 0.1.9 | 2022-0224 | [10312](https://github.com/airbytehq/airbyte/pull/10312) | Add support for Transaction Stream |
| 0.1.8 | 2022-02-22 | [10366](https://github.com/airbytehq/airbyte/pull/10366) | Fix broken `coupon` stream + add unit tests |
| 0.1.7 | 2022-02-14 | [10269](https://github.com/airbytehq/airbyte/pull/10269) | Add support for Coupon stream |
| 0.1.6 | 2022-02-10 | [10143](https://github.com/airbytehq/airbyte/pull/10143) | Add support for Event stream |
| 0.1.5 | 2021-12-23 | [8434](https://github.com/airbytehq/airbyte/pull/8434) | Update fields in source-connectors specifications |
| 0.1.4 | 2021-09-27 | [6454](https://github.com/airbytehq/airbyte/pull/6454) | Fix examples in spec file |
| 0.1.3 | 2021-08-17 | [5421](https://github.com/airbytehq/airbyte/pull/5421) | Add support for "Product Catalog 2.0" specific streams: `Items`, `Item prices` and `Attached Items` |
| 0.1.2 | 2021-07-30 | [5067](https://github.com/airbytehq/airbyte/pull/5067) | Prepare connector for publishing |
| 0.1.1 | 2021-07-07 | [4539](https://github.com/airbytehq/airbyte/pull/4539) | Add entrypoint and bump version for connector |
| 0.1.0 | 2021-06-30 | [3410](https://github.com/airbytehq/airbyte/pull/3410) | New Source: Chargebee |
| Version | Date | Pull Request | Subject |
|:--------|:-----------| :--- |:----------------------------------------------------------------------------------------------------|
| 0.1.14 | 2022-09-23 | [17056](https://github.com/airbytehq/airbyte/pull/17056) | Add "custom fields" to the relevant Chargebee source data streams |
| 0.1.13 | 2022-08-18 | [15743](https://github.com/airbytehq/airbyte/pull/15743) | Fix transaction `exchange_rate` field type |
| 0.1.12 | 2022-07-13 | [14672](https://github.com/airbytehq/airbyte/pull/14672) | Fix transaction sort by |
| 0.1.11 | 2022-03-03 | [10827](https://github.com/airbytehq/airbyte/pull/10827) | Fix Credit Note stream |
| 0.1.10 | 2022-03-02 | [10795](https://github.com/airbytehq/airbyte/pull/10795) | Add support for Credit Note stream |
| 0.1.9 | 2022-0224 | [10312](https://github.com/airbytehq/airbyte/pull/10312) | Add support for Transaction Stream |
| 0.1.8 | 2022-02-22 | [10366](https://github.com/airbytehq/airbyte/pull/10366) | Fix broken `coupon` stream + add unit tests |
| 0.1.7 | 2022-02-14 | [10269](https://github.com/airbytehq/airbyte/pull/10269) | Add support for Coupon stream |
| 0.1.6 | 2022-02-10 | [10143](https://github.com/airbytehq/airbyte/pull/10143) | Add support for Event stream |
| 0.1.5 | 2021-12-23 | [8434](https://github.com/airbytehq/airbyte/pull/8434) | Update fields in source-connectors specifications |
| 0.1.4 | 2021-09-27 | [6454](https://github.com/airbytehq/airbyte/pull/6454) | Fix examples in spec file |
| 0.1.3 | 2021-08-17 | [5421](https://github.com/airbytehq/airbyte/pull/5421) | Add support for "Product Catalog 2.0" specific streams: `Items`, `Item prices` and `Attached Items` |
| 0.1.2 | 2021-07-30 | [5067](https://github.com/airbytehq/airbyte/pull/5067) | Prepare connector for publishing |
| 0.1.1 | 2021-07-07 | [4539](https://github.com/airbytehq/airbyte/pull/4539) | Add entrypoint and bump version for connector |
| 0.1.0 | 2021-06-30 | [3410](https://github.com/airbytehq/airbyte/pull/3410) | New Source: Chargebee |