Skip to content

Commit

Permalink
add younium to source def
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosmarxm committed Nov 9, 2022
1 parent 229b831 commit be0c9a0
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,13 @@
documentationUrl: https://docs.airbyte.com/integrations/sources/yandex-metrica
sourceType: api
releaseStage: alpha
- name: Younium
sourceDefinitionId: 9c74c2d7-531a-4ebf-b6d8-6181f805ecdc
dockerRepository: airbyte/source-younium
dockerImageTag: 0.1.0
documentationUrl: https://docs.airbyte.com/integrations/sources/younium
sourceType: api
releaseStage: alpha
- name: Zoom
sourceDefinitionId: cbfd9856-1322-44fb-bcf1-0b39b7a8e92e
dockerRepository: airbyte/source-zoom
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ def connector_setup():
"""This fixture is a placeholder for external resources that acceptance test might require."""
# TODO: setup test dependencies if needed. otherwise remove the TODO comments
yield
# TODO: clean up test dependencies
# TODO: clean up test dependencies
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-younium/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

if __name__ == "__main__":
source = SourceYounium()
launch(source, sys.argv[1:])
launch(source, sys.argv[1:])
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-younium/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
extras_require={
"tests": TEST_REQUIREMENTS,
},
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from airbyte_cdk.sources.streams.http import HttpStream
from airbyte_cdk.sources.streams.http.auth import TokenAuthenticator


# Basic full refresh stream
class YouniumStream(HttpStream, ABC):
# url_base = "https://apisandbox.younium.com"
Expand Down Expand Up @@ -44,20 +45,20 @@ def next_page_token(self, response: requests.Response) -> Optional[Mapping[str,
return None

def request_params(
self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, any] = None, next_page_token: Mapping[str, Any] = None
self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, any] = None, next_page_token: Mapping[str, Any] = None
) -> MutableMapping[str, Any]:
if next_page_token:
return {"pageNumber": next_page_token["pageNumber"], "PageSize": self.page_size}
else:
return {"PageSize": self.page_size}

def parse_response(
self,
response: requests.Response,
*,
stream_state: Mapping[str, Any],
stream_slice: Mapping[str, Any] = None,
next_page_token: Mapping[str, Any] = None,
self,
response: requests.Response,
*,
stream_state: Mapping[str, Any],
stream_slice: Mapping[str, Any] = None,
next_page_token: Mapping[str, Any] = None,
) -> Iterable[Mapping]:
response_results = response.json()
yield from response_results.get("data", [])
Expand All @@ -67,15 +68,16 @@ class Invoice(YouniumStream):
primary_key = "id"

def path(
self, stream_state: Mapping[str, Any] = None, stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None
self, stream_state: Mapping[str, Any] = None, stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None
) -> str:
return "Invoices"


class Product(YouniumStream):
primary_key = "id"

def path(
self, stream_state: Mapping[str, Any] = None, stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None
self, stream_state: Mapping[str, Any] = None, stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None
) -> str:
return "Products"

Expand All @@ -84,13 +86,12 @@ class Subscription(YouniumStream):
primary_key = "id"

def path(
self, stream_state: Mapping[str, Any] = None, stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None
self, stream_state: Mapping[str, Any] = None, stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None
) -> str:
return "Subscriptions"


class SourceYounium(AbstractSource):

def get_auth(self, config):
scope = "openid youniumapi profile"

Expand All @@ -100,12 +101,10 @@ def get_auth(self, config):
url = "https://younium-identity-server.azurewebsites.net/connect/token"

payload = f"grant_type=password&client_id=apiclient&username={config['username']}&password={config['password']}&scope={scope}"
headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
headers = {"Content-Type": "application/x-www-form-urlencoded"}
response = requests.request("POST", url, headers=headers, data=payload)
response.raise_for_status()
access_token = response.json()['access_token']
access_token = response.json()["access_token"]

auth = TokenAuthenticator(token=access_token)
return auth
Expand All @@ -129,8 +128,4 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]:
:param config: A Mapping of the user input configuration as defined in the connector spec.
"""
auth = self.get_auth(config)
return [
Invoice(authenticator=auth, **config),
Product(authenticator=auth, **config),
Subscription(authenticator=auth, **config)
]
return [Invoice(authenticator=auth, **config), Product(authenticator=auth, **config), Subscription(authenticator=auth, **config)]
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#

from http import HTTPStatus
from unittest.mock import MagicMock

import responses
from source_younium.source import SourceYounium

Expand All @@ -21,9 +23,14 @@ def test_check_connection(mocker):
mock_url1 = "https://younium-identity-server.azurewebsites.net/connect/token"
mock_url2 = "https://api.younium.com/Invoices?PageSize=1"
# Mock the POST to get the access token
responses.add(responses.POST, mock_url1, json={
"access_token": "dummy_token",
}, status=HTTPStatus.OK, )
responses.add(
responses.POST,
mock_url1,
json={
"access_token": "dummy_token",
},
status=HTTPStatus.OK,
)

# Mock the GET to get the first page of the stream
responses.add(responses.GET, mock_url2, json={}, status=HTTPStatus.OK)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#

from http import HTTPStatus
Expand All @@ -23,9 +23,10 @@ def test_request_params(patch_base_class):
expected_params = {"PageSize": 100}
assert stream.request_params(**inputs) == expected_params


def test_request_params_with_next_page_token(patch_base_class):
stream = YouniumStream(authenticator=None)
inputs = {"stream_slice": None, "stream_state": None, "next_page_token": {"pageNumber":2}}
inputs = {"stream_slice": None, "stream_state": None, "next_page_token": {"pageNumber": 2}}
expected_params = {"PageSize": 100, "pageNumber": 2}
assert stream.request_params(**inputs) == expected_params

Expand All @@ -34,6 +35,8 @@ def test_playground_url_base(patch_base_class):
stream = YouniumStream(authenticator=None, playground=True)
expected_url_base = "https://apisandbox.younium.com"
assert stream.url_base == expected_url_base


def test_use_playground_url_base(patch_base_class):
stream = YouniumStream(authenticator=None, playground=True)
expected_url_base = "https://apisandbox.younium.com"
Expand Down

0 comments on commit be0c9a0

Please sign in to comment.