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 Exchange Rates - Refactor for API Layer #15884

Merged
merged 15 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -256,7 +256,7 @@
- name: Exchange Rates Api
sourceDefinitionId: e2b40e36-aa0e-4bed-b41b-bcea6fa348b1
dockerRepository: airbyte/source-exchange-rates
dockerImageTag: 0.2.6
dockerImageTag: 1.2.6
documentationUrl: https://docs.airbyte.io/integrations/sources/exchangeratesapi
icon: exchangeratesapi.svg
sourceType: api
Expand Down
6 changes: 3 additions & 3 deletions airbyte-config/init/src/main/resources/seed/source_specs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2233,7 +2233,7 @@
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
- dockerImage: "airbyte/source-exchange-rates:0.2.6"
- dockerImage: "airbyte/source-exchange-rates:1.2.6"
spec:
documentationUrl: "https://docs.airbyte.io/integrations/sources/exchangeratesapi"
connectionSpecification:
Expand All @@ -2243,7 +2243,7 @@
required:
- "start_date"
- "access_key"
additionalProperties: false
additionalProperties: true
properties:
start_date:
type: "string"
Expand All @@ -2253,7 +2253,7 @@
- "YYYY-MM-DD"
access_key:
type: "string"
description: "Your API Access Key. See <a href=\"https://exchangeratesapi.io/documentation/\"\
description: "Your API Key. See <a href=\"https://apilayer.com/marketplace/exchangerates_data-api\"\
>here</a>. The key is case sensitive."
airbyte_secret: true
base:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,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.2.6
LABEL io.airbyte.version=1.2.6
LABEL io.airbyte.name=airbyte/source-exchange-rates
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ExchangeRates(HttpStream):
date_field_name = "date"

# HttpStream related fields
url_base = "http://api.exchangeratesapi.io/v1/"
url_base = "https://api.apilayer.com/exchangerates_data/"
cursor_field = date_field_name
primary_key = ""

Expand All @@ -39,13 +39,18 @@ def next_page_token(self, response: requests.Response) -> Optional[Mapping[str,
return None

def request_params(self, **kwargs) -> MutableMapping[str, Any]:
params = {"access_key": self.access_key}
params = {}

if self._base is not None:
params["base"] = self._base

return params

def request_headers(self, **kwargs) -> MutableMapping[str, Any]:
headers = {"apikey": self.access_key}

return headers

def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]:
response_json = response.json()
yield response_json
Expand Down Expand Up @@ -82,12 +87,13 @@ def chunk_date_range(start_date: DateTime, ignore_weekends: bool) -> Iterable[Ma
class SourceExchangeRates(AbstractSource):
def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) -> Tuple[bool, Any]:
try:
params = {"access_key": config["access_key"]}
headers = {"apikey": config["access_key"]}
params = {}
base = config.get("base")
if base is not None:
params["base"] = base

resp = requests.get(f"{ExchangeRates.url_base}{config['start_date']}", params=params)
resp = requests.get(f"{ExchangeRates.url_base}{config['start_date']}", params=params, headers=headers)
status = resp.status_code
logger.info(f"Ping response code: {status}")
if status == 200:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ connectionSpecification:
required:
- start_date
- access_key
additionalProperties: false
additionalProperties: true
properties:
start_date:
type: string
Expand All @@ -17,8 +17,8 @@ connectionSpecification:
access_key:
type: string
description: >-
Your API Access Key. See <a
href="https://exchangeratesapi.io/documentation/">here</a>. The key is
Your API Key. See <a
href="https://apilayer.com/marketplace/exchangerates_data-api">here</a>. The key is
case sensitive.
airbyte_secret: true
base:
Expand Down
1 change: 1 addition & 0 deletions docs/integrations/sources/exchangeratesapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ If you have `free` subscription plan \(you may check it [here](https://manage.ex

| Version | Date | Pull Request | Subject |
|:--------| :--- | :--- | :--- |
| 1.2.6 | 2022-08-23 | [15884](https://github.com/airbytehq/airbyte/pull/15884) | Migrated to new API Layer endpoint |
| 0.2.6 | 2022-04-20 | [12230](https://github.com/airbytehq/airbyte/pull/12230) | Update connector to use a `spec.yaml` |
| 0.2.5 | 2021-11-12 | [7936](https://github.com/airbytehq/airbyte/pull/7936) | Add ignore_weekends boolean option |
| 0.2.4 | 2021-11-08 | [7499](https://github.com/airbytehq/airbyte/pull/7499) | Remove base-python dependencies |
Expand Down