Skip to content

Commit

Permalink
🐛 Source Square: Update _send_request method due to changes in Airbyt…
Browse files Browse the repository at this point in the history
…e CDK (#4645)
  • Loading branch information
TymoshokDmytro committed Jul 13, 2021
1 parent 76a86c3 commit 3add914
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"sourceDefinitionId": "77225a51-cd15-4a13-af02-65816bd0ecf4",
"name": "Square",
"dockerRepository": "airbyte/source-square",
"dockerImageTag": "0.1.0",
"dockerImageTag": "0.1.1",
"documentationUrl": "https://docs.airbyte.io/integrations/sources/square"
}
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@
- sourceDefinitionId: 77225a51-cd15-4a13-af02-65816bd0ecf4
name: Square
dockerRepository: airbyte/source-square
dockerImageTag: 0.1.0
dockerImageTag: 0.1.1
documentationUrl: https://docs.airbyte.io/integrations/sources/square
- sourceDefinitionId: 325e0640-e7b3-4e24-b823-3361008f603f
name: Zendesk Sunshine
Expand Down
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-square/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ RUN pip install .
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.1.0
LABEL io.airbyte.version=0.1.1
LABEL io.airbyte.name=airbyte/source-square
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,13 @@ def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapp
records = json_response.get(self.data_field, []) if self.data_field is not None else json_response
yield from records

def _send_request(self, request: requests.PreparedRequest) -> requests.Response:
def _send_request(self, request: requests.PreparedRequest, request_kwargs: Mapping[str, Any]) -> requests.Response:
try:
return super()._send_request(request)
return super()._send_request(request, request_kwargs)
except requests.exceptions.HTTPError as e:
square_exception = parse_square_error_response(e)
if square_exception:
self.logger.error(str(square_exception))
# Exiting is made for not to have a huge traceback in the airbyte log.
# The explicit square error message already been out with the command above.
exit(1)

raise e


Expand Down Expand Up @@ -310,6 +306,14 @@ def request_params(self, **kwargs) -> MutableMapping[str, Any]:
params_payload["limit"] = self.items_per_page_limit
return params_payload

# This stream is tricky because once in a while it returns 404 error 'Not Found for url'.
# Thus the retry strategy was implemented.
def should_retry(self, response: requests.Response) -> bool:
return response.status_code == 404 or super().should_retry(response)

def backoff_time(self, response: requests.Response) -> Optional[float]:
return 3


class Customers(SquareStreamPageParam):
""" Docs: https://developer.squareup.com/reference/square_2021-06-16/customers-api/list-customers """
Expand Down Expand Up @@ -367,7 +371,7 @@ def stream_slices(self, **kwargs) -> Iterable[Optional[Mapping[str, Any]]]:
"No locations found. Orders cannot be extracted without locations. "
"Check https://developer.squareup.com/explorer/square/locations-api/list-locations"
)
exit(1)
yield from []

separated_locations = separate_items_by_count(location_ids, self.locations_per_requets)
for location in separated_locations:
Expand Down
3 changes: 2 additions & 1 deletion docs/integrations/sources/square.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@ Some Square API endpoints has different page size limitation

| Version | Date | Pull Request | Subject |
| :------ | :-------- | :----- | :------ |
| 0.1.0 | 2021-06-30 | [4439](https://github.com/airbytehq/airbyte/pull/4439) | Initial release supporting the Square API |
| 0.1.1 | 2021-07-09 | [4645](https://github.com/airbytehq/airbyte/pull/4645) | Update _send_request method due to Airbyte CDK changes |
| 0.1.0 | 2021-06-30 | [4439](https://github.com/airbytehq/airbyte/pull/4439) | Initial release supporting the Square API |

0 comments on commit 3add914

Please sign in to comment.