diff --git a/airbyte-config/init/src/main/resources/seed/source_definitions.yaml b/airbyte-config/init/src/main/resources/seed/source_definitions.yaml index 389041f1e03c..3a4f2ddc80b0 100644 --- a/airbyte-config/init/src/main/resources/seed/source_definitions.yaml +++ b/airbyte-config/init/src/main/resources/seed/source_definitions.yaml @@ -370,6 +370,13 @@ documentationUrl: https://docs.airbyte.com/integrations/sources/faker sourceType: api releaseStage: alpha +- name: Fastbill + sourceDefinitionId: eb3e9c1c-0467-4eb7-a172-5265e04ccd0a + dockerRepository: airbyte/source-fastbill + dockerImageTag: 0.1.0 + documentationUrl: https://docs.airbyte.com/integrations/sources/fastbill + sourceType: api + releaseStage: alpha - name: Fauna sourceDefinitionId: 3825db3e-c94b-42ac-bd53-b5a9507ace2b dockerRepository: airbyte/source-fauna diff --git a/airbyte-config/init/src/main/resources/seed/source_specs.yaml b/airbyte-config/init/src/main/resources/seed/source_specs.yaml index 154739a97ff9..eb58ccdec4e2 100644 --- a/airbyte-config/init/src/main/resources/seed/source_specs.yaml +++ b/airbyte-config/init/src/main/resources/seed/source_specs.yaml @@ -3429,6 +3429,29 @@ supportsNormalization: false supportsDBT: false supported_destination_sync_modes: [] +- dockerImage: "airbyte/source-fastbill:0.1.0" + spec: + documentationUrl: "https://docs.airbyte.com/integrations/sources/fastbill" + connectionSpecification: + $schema: "http://json-schema.org/draft-07/schema#" + title: "Fastbill Spec" + type: "object" + required: + - "username" + - "api_key" + properties: + username: + title: "Username" + type: "string" + description: "Username for Fastbill account" + api_key: + title: "API Key" + type: "string" + description: "Fastbill API key" + airbyte_secret: true + supportsNormalization: false + supportsDBT: false + supported_destination_sync_modes: [] - dockerImage: "airbyte/source-fauna:dev" spec: documentationUrl: "https://github.com/fauna/airbyte/blob/source-fauna/docs/integrations/sources/fauna.md" diff --git a/airbyte-integrations/builds.md b/airbyte-integrations/builds.md index 156a969dbc2e..15ffc8576ec5 100644 --- a/airbyte-integrations/builds.md +++ b/airbyte-integrations/builds.md @@ -34,6 +34,7 @@ | End-to-End Testing | [![source-e2e-test](https://img.shields.io/endpoint?url=https%3A%2F%2Fdnsgjos7lj2fu.cloudfront.net%2Ftests%2Fsummary%2Fsource-e2e-test%2Fbadge.json)](https://dnsgjos7lj2fu.cloudfront.net/tests/summary/source-e2e-test) | | Exchange Rates API | [![source-exchange-rates](https://img.shields.io/endpoint?url=https%3A%2F%2Fdnsgjos7lj2fu.cloudfront.net%2Ftests%2Fsummary%2Fsource-exchange-rates%2Fbadge.json)](https://dnsgjos7lj2fu.cloudfront.net/tests/summary/source-exchange-rates) | | Facebook Marketing | [![source-facebook-marketing](https://img.shields.io/endpoint?url=https%3A%2F%2Fdnsgjos7lj2fu.cloudfront.net%2Ftests%2Fsummary%2Fsource-facebook-marketing%2Fbadge.json)](https://dnsgjos7lj2fu.cloudfront.net/tests/summary/source-facebook-marketing) | +| Fastbill | [![source-fastbill](https://img.shields.io/endpoint?url=https%3A%2F%2Fdnsgjos7lj2fu.cloudfront.net%2Ftests%2Fsummary%2Fsource-fastbill%2Fbadge.json)](https://dnsgjos7lj2fu.cloudfront.net/tests/summary/source-fastbill) | | Fauna | [![source-fauna](https://img.shields.io/endpoint?url=https%3A%2F%2Fdnsgjos7lj2fu.cloudfront.net%2Ftests%2Fsummary%2Fsource-fauna%2Fbadge.json)](https://dnsgjos7lj2fu.cloudfront.net/tests/summary/source-fauna) | | Files | [![source-file](https://img.shields.io/endpoint?url=https%3A%2F%2Fdnsgjos7lj2fu.cloudfront.net%2Ftests%2Fsummary%2Fsource-file%2Fbadge.json)](https://dnsgjos7lj2fu.cloudfront.net/tests/summary/source-file) | | Flexport | [![source-file](https://img.shields.io/endpoint?url=https%3A%2F%2Fdnsgjos7lj2fu.cloudfront.net%2Ftests%2Fsummary%2Fsource-flexport%2Fbadge.json)](https://dnsgjos7lj2fu.cloudfront.net/tests/summary/source-flexport) | diff --git a/airbyte-integrations/connectors/source-fastbill/.dockerignore b/airbyte-integrations/connectors/source-fastbill/.dockerignore new file mode 100644 index 000000000000..501945bc2f71 --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/.dockerignore @@ -0,0 +1,6 @@ +* +!Dockerfile +!main.py +!source_fastbill +!setup.py +!secrets diff --git a/airbyte-integrations/connectors/source-fastbill/Dockerfile b/airbyte-integrations/connectors/source-fastbill/Dockerfile new file mode 100644 index 000000000000..796bd1df115e --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/Dockerfile @@ -0,0 +1,38 @@ +FROM python:3.9.13-alpine3.15 as base + +# build and load all requirements +FROM base as builder +WORKDIR /airbyte/integration_code + +# upgrade pip to the latest version +RUN apk --no-cache upgrade \ + && pip install --upgrade pip \ + && apk --no-cache add tzdata build-base + + +COPY setup.py ./ +# install necessary packages to a temporary folder +RUN pip install --prefix=/install . + +# build a clean environment +FROM base +WORKDIR /airbyte/integration_code + +# copy all loaded and built libraries to a pure basic image +COPY --from=builder /install /usr/local +# add default timezone settings +COPY --from=builder /usr/share/zoneinfo/Etc/UTC /etc/localtime +RUN echo "Etc/UTC" > /etc/timezone + +# bash is installed for more convenient debugging. +RUN apk --no-cache add bash + +# copy payload code only +COPY main.py ./ +COPY source_fastbill ./source_fastbill + +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.name=airbyte/source-fastbill diff --git a/airbyte-integrations/connectors/source-fastbill/README.md b/airbyte-integrations/connectors/source-fastbill/README.md new file mode 100644 index 000000000000..6f41c83e8f71 --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/README.md @@ -0,0 +1,132 @@ +# Fastbill Source + +This is the repository for the Fastbill source connector, written in Python. +For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.io/integrations/sources/fastbill). + +## Local development + +### Prerequisites +**To iterate on this connector, make sure to complete this prerequisites section.** + +#### Minimum Python version required `= 3.9.0` + +#### Build & Activate Virtual Environment and install dependencies +From this connector directory, create a virtual environment: +``` +python -m venv .venv +``` + +This will generate a virtualenv for this module in `.venv/`. Make sure this venv is active in your +development environment of choice. To activate it from the terminal, run: +``` +source .venv/bin/activate +pip install -r requirements.txt +pip install '.[tests]' +``` +If you are in an IDE, follow your IDE's instructions to activate the virtualenv. + +Note that while we are installing dependencies from `requirements.txt`, you should only edit `setup.py` for your dependencies. `requirements.txt` is +used for editable installs (`pip install -e`) to pull in Python dependencies from the monorepo and will call `setup.py`. +If this is mumbo jumbo to you, don't worry about it, just put your deps in `setup.py` but install using `pip install -r requirements.txt` and everything +should work as you expect. + +#### Building via Gradle +You can also build the connector in Gradle. This is typically used in CI and not needed for your development workflow. + +To build using Gradle, from the Airbyte repository root, run: +``` +./gradlew :airbyte-integrations:connectors:source-fastbill:build +``` + +#### Create credentials +**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.io/integrations/sources/fastbill) +to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_fastbill/spec.yaml` file. +Note that any directory named `secrets` is gitignored across the entire Airbyte repo, so there is no danger of accidentally checking in sensitive information. +See `integration_tests/sample_config.json` for a sample config file. + +**If you are an Airbyte core member**, copy the credentials in Lastpass under the secret name `source fastbill test creds` +and place them into `secrets/config.json`. + +### Locally running the connector +``` +python main.py spec +python main.py check --config secrets/config.json +python main.py discover --config secrets/config.json +python main.py read --config secrets/config.json --catalog integration_tests/configured_catalog.json +``` + +### Locally running the connector docker image + +#### Build +First, make sure you build the latest Docker image: +``` +docker build . -t airbyte/source-fastbill:dev +``` + +You can also build the connector image via Gradle: +``` +./gradlew :airbyte-integrations:connectors:source-fastbill:airbyteDocker +``` +When building via Gradle, the docker image name and tag, respectively, are the values of the `io.airbyte.name` and `io.airbyte.version` `LABEL`s in +the Dockerfile. + +#### Run +Then run any of the connector commands as follows: +``` +docker run --rm airbyte/source-fastbill:dev spec +docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-fastbill:dev check --config /secrets/config.json +docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-fastbill:dev discover --config /secrets/config.json +docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-fastbill:dev read --config /secrets/config.json --catalog /integration_tests/configured_catalog.json +``` +## Testing +Make sure to familiarize yourself with [pytest test discovery](https://docs.pytest.org/en/latest/goodpractices.html#test-discovery) to know how your test files and methods should be named. +First install test dependencies into your virtual environment: +``` +pip install .[tests] +``` +### Unit Tests +To run unit tests locally, from the connector directory run: +``` +python -m pytest unit_tests +``` + +### Integration Tests +There are two types of integration tests: Acceptance Tests (Airbyte's test suite for all source connectors) and custom integration tests (which are specific to this connector). +#### Custom Integration tests +Place custom tests inside `integration_tests/` folder, then, from the connector root, run +``` +python -m pytest integration_tests +``` +#### Acceptance Tests +Customize `acceptance-test-config.yml` file to configure tests. See [Source Acceptance Tests](https://docs.airbyte.io/connector-development/testing-connectors/source-acceptance-tests-reference) for more information. +If your connector requires to create or destroy resources for use during acceptance tests create fixtures for it and place them inside integration_tests/acceptance.py. +To run your integration tests with acceptance tests, from the connector root, run +``` +python -m pytest integration_tests -p integration_tests.acceptance +``` +To run your integration tests with docker + +### Using gradle to run tests +All commands should be run from airbyte project root. +To run unit tests: +``` +./gradlew :airbyte-integrations:connectors:source-fastbill:unitTest +``` +To run acceptance and custom integration tests: +``` +./gradlew :airbyte-integrations:connectors:source-fastbill:integrationTest +``` + +## Dependency Management +All of your dependencies should go in `setup.py`, NOT `requirements.txt`. The requirements file is only used to connect internal Airbyte dependencies in the monorepo for local development. +We split dependencies between two groups, dependencies that are: +* required for your connector to work need to go to `MAIN_REQUIREMENTS` list. +* required for the testing need to go to `TEST_REQUIREMENTS` list + +### Publishing a new version of the connector +You've checked out the repo, implemented a million dollar feature, and you're ready to share your changes with the world. Now what? +1. Make sure your changes are passing unit and integration tests. +1. Bump the connector version in `Dockerfile` -- just increment the value of the `LABEL io.airbyte.version` appropriately (we use [SemVer](https://semver.org/)). +1. Create a Pull Request. +1. Pat yourself on the back for being an awesome contributor. +1. Someone from Airbyte will take a look at your PR and iterate with you to merge it into master. diff --git a/airbyte-integrations/connectors/source-fastbill/acceptance-test-config.yml b/airbyte-integrations/connectors/source-fastbill/acceptance-test-config.yml new file mode 100644 index 000000000000..f49f10d2c8c5 --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/acceptance-test-config.yml @@ -0,0 +1,20 @@ +# See [Source Acceptance Tests](https://docs.airbyte.io/connector-development/testing-connectors/source-acceptance-tests-reference) +# for more information about how to configure these tests +connector_image: airbyte/source-fastbill:dev +tests: + spec: + - spec_path: "source_fastbill/spec.yaml" + connection: + - config_path: "secrets/config.json" + status: "succeed" + - config_path: "integration_tests/invalid_config.json" + status: "failed" + discovery: + - config_path: "secrets/config.json" + basic_read: + - config_path: "secrets/config.json" + configured_catalog_path: "integration_tests/configured_catalog.json" + empty_streams: ["products","recurring_invoices"] + full_refresh: + - config_path: "secrets/config.json" + configured_catalog_path: "integration_tests/configured_catalog.json" diff --git a/airbyte-integrations/connectors/source-fastbill/acceptance-test-docker.sh b/airbyte-integrations/connectors/source-fastbill/acceptance-test-docker.sh new file mode 100755 index 000000000000..c51577d10690 --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/acceptance-test-docker.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# Build latest connector image +docker build . -t $(cat acceptance-test-config.yml | grep "connector_image" | head -n 1 | cut -d: -f2-) + +# Pull latest acctest image +docker pull airbyte/source-acceptance-test:latest + +# Run +docker run --rm -it \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v /tmp:/tmp \ + -v $(pwd):/test_input \ + airbyte/source-acceptance-test \ + --acceptance-test-config /test_input + diff --git a/airbyte-integrations/connectors/source-fastbill/build.gradle b/airbyte-integrations/connectors/source-fastbill/build.gradle new file mode 100644 index 000000000000..a23711c3afee --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/build.gradle @@ -0,0 +1,9 @@ +plugins { + id 'airbyte-python' + id 'airbyte-docker' + id 'airbyte-source-acceptance-test' +} + +airbytePython { + moduleDirectory 'source_fastbill' +} diff --git a/airbyte-integrations/connectors/source-fastbill/integration_tests/__init__.py b/airbyte-integrations/connectors/source-fastbill/integration_tests/__init__.py new file mode 100644 index 000000000000..1100c1c58cf5 --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/integration_tests/__init__.py @@ -0,0 +1,3 @@ +# +# Copyright (c) 2022 Airbyte, Inc., all rights reserved. +# diff --git a/airbyte-integrations/connectors/source-fastbill/integration_tests/abnormal_state.json b/airbyte-integrations/connectors/source-fastbill/integration_tests/abnormal_state.json new file mode 100644 index 000000000000..8890ca08332d --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/integration_tests/abnormal_state.json @@ -0,0 +1,5 @@ +{ + "customers": { + "CUSTOMER_TYPE": 12 + } +} diff --git a/airbyte-integrations/connectors/source-fastbill/integration_tests/acceptance.py b/airbyte-integrations/connectors/source-fastbill/integration_tests/acceptance.py new file mode 100644 index 000000000000..950b53b59d41 --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/integration_tests/acceptance.py @@ -0,0 +1,14 @@ +# +# Copyright (c) 2022 Airbyte, Inc., all rights reserved. +# + + +import pytest + +pytest_plugins = ("source_acceptance_test.plugin",) + + +@pytest.fixture(scope="session", autouse=True) +def connector_setup(): + """This fixture is a placeholder for external resources that acceptance test might require.""" + yield diff --git a/airbyte-integrations/connectors/source-fastbill/integration_tests/configured_catalog.json b/airbyte-integrations/connectors/source-fastbill/integration_tests/configured_catalog.json new file mode 100644 index 000000000000..3e36914dbc8f --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/integration_tests/configured_catalog.json @@ -0,0 +1,49 @@ +{ + "streams": [ + { + "stream": { + "name": "customers", + "json_schema": {}, + "supported_sync_modes": ["full_refresh"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "overwrite" + }, + { + "stream": { + "name": "recurring_invoices", + "json_schema": {}, + "supported_sync_modes": ["full_refresh"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "overwrite" + }, + { + "stream": { + "name": "invoices", + "json_schema": {}, + "supported_sync_modes": ["full_refresh"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "overwrite" + }, + { + "stream": { + "name": "products", + "json_schema": {}, + "supported_sync_modes": ["full_refresh"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "overwrite" + }, + { + "stream": { + "name": "revenues", + "json_schema": {}, + "supported_sync_modes": ["full_refresh"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "overwrite" + } + ] +} diff --git a/airbyte-integrations/connectors/source-fastbill/integration_tests/invalid_config.json b/airbyte-integrations/connectors/source-fastbill/integration_tests/invalid_config.json new file mode 100644 index 000000000000..27bdf1f2dc26 --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/integration_tests/invalid_config.json @@ -0,0 +1,4 @@ +{ + "api_key": "badkeeeey", + "username": "wrong_username" +} diff --git a/airbyte-integrations/connectors/source-fastbill/integration_tests/sample_config.json b/airbyte-integrations/connectors/source-fastbill/integration_tests/sample_config.json new file mode 100644 index 000000000000..ae6a028d1714 --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/integration_tests/sample_config.json @@ -0,0 +1,4 @@ +{ + "username": "<username>", + "api_key": "<X-Api-key>" +} diff --git a/airbyte-integrations/connectors/source-fastbill/integration_tests/sample_state.json b/airbyte-integrations/connectors/source-fastbill/integration_tests/sample_state.json new file mode 100644 index 000000000000..7a9ca5814ba8 --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/integration_tests/sample_state.json @@ -0,0 +1,5 @@ +{ + "customers": { + "CUSTOMER_TYPE": "strings" + } +} diff --git a/airbyte-integrations/connectors/source-fastbill/main.py b/airbyte-integrations/connectors/source-fastbill/main.py new file mode 100644 index 000000000000..9b1acb2e2026 --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/main.py @@ -0,0 +1,13 @@ +# +# Copyright (c) 2022 Airbyte, Inc., all rights reserved. +# + + +import sys + +from airbyte_cdk.entrypoint import launch +from source_fastbill import SourceFastbill + +if __name__ == "__main__": + source = SourceFastbill() + launch(source, sys.argv[1:]) diff --git a/airbyte-integrations/connectors/source-fastbill/requirements.txt b/airbyte-integrations/connectors/source-fastbill/requirements.txt new file mode 100644 index 000000000000..78140e52009f --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/requirements.txt @@ -0,0 +1,2 @@ +-e ../../bases/source-acceptance-test +-e . \ No newline at end of file diff --git a/airbyte-integrations/connectors/source-fastbill/setup.py b/airbyte-integrations/connectors/source-fastbill/setup.py new file mode 100644 index 000000000000..15c8044979ea --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/setup.py @@ -0,0 +1,25 @@ +# +# Copyright (c) 2022 Airbyte, Inc., all rights reserved. +# + + +from setuptools import find_packages, setup + +MAIN_REQUIREMENTS = [ + "airbyte-cdk~=0.4", +] + +TEST_REQUIREMENTS = ["pytest~=6.1", "pytest-mock~=3.6.1", "source-acceptance-test", "responses~=0.21.0"] + +setup( + name="source_fastbill", + description="Source implementation for Fastbill.", + author="Airbyte", + author_email="contact@airbyte.io", + packages=find_packages(), + install_requires=MAIN_REQUIREMENTS, + package_data={"": ["*.json", "*.yaml", "schemas/*.json", "schemas/shared/*.json"]}, + extras_require={ + "tests": TEST_REQUIREMENTS, + }, +) diff --git a/airbyte-integrations/connectors/source-fastbill/source_fastbill/__init__.py b/airbyte-integrations/connectors/source-fastbill/source_fastbill/__init__.py new file mode 100644 index 000000000000..d1caf1ad3026 --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/source_fastbill/__init__.py @@ -0,0 +1,8 @@ +# +# Copyright (c) 2022 Airbyte, Inc., all rights reserved. +# + + +from .source import SourceFastbill + +__all__ = ["SourceFastbill"] diff --git a/airbyte-integrations/connectors/source-fastbill/source_fastbill/helpers.py b/airbyte-integrations/connectors/source-fastbill/source_fastbill/helpers.py new file mode 100644 index 000000000000..b3527c0e254e --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/source_fastbill/helpers.py @@ -0,0 +1,26 @@ +# +# Copyright (c) 2022 Airbyte, Inc., all rights reserved. +# + + +def req_body(offset, endpoint: str): + return {"SERVICE": f"{endpoint}.get", "FILTER": {}, "OFFSET": offset} + + +def get_next_page_token(response, response_key: str, API_OFFSET_LIMIT: int, endpoint: str): + response = response.json() + offset = response["REQUEST"]["OFFSET"] if response["REQUEST"]["OFFSET"] >= 0 else None + if offset is None: + response_request = response["REQUEST"]["OFFSET"] + raise Exception(f"No valid offset value found:{response_request}") + + if len(response["RESPONSE"][response_key]) == API_OFFSET_LIMIT: + return req_body(offset + API_OFFSET_LIMIT, endpoint) + return None + + +def get_request_body_json(next_page_token, endpoint): + if next_page_token: + return next_page_token + else: + return {"SERVICE": f"{endpoint}.get", "FILTER": {}, "OFFSET": 0} diff --git a/airbyte-integrations/connectors/source-fastbill/source_fastbill/schemas/customers.json b/airbyte-integrations/connectors/source-fastbill/source_fastbill/schemas/customers.json new file mode 100644 index 000000000000..c3c846c5a517 --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/source_fastbill/schemas/customers.json @@ -0,0 +1,160 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "CUSTOMER_ID": { + "type": "string" + }, + "CUSTOMER_NUMBER": { + "type": "string" + }, + "DAYS_FOR_PAYMENT": { + "type": "string", + "empty": true + }, + "CREATED": { + "type": "string", + "format": "date-time" + }, + "PAYMENT_TYPE": { + "type": "string", + "empty": true + }, + "BANK_NAME": { + "type": "string", + "empty": true + }, + "BANK_ACCOUNT_NUMBER": { + "type": "string", + "empty": true + }, + "BANK_CODE": { + "type": "string", + "empty": true + }, + "BANK_ACCOUNT_OWNER": { + "type": "string", + "empty": true + }, + "BANK_IBAN": { + "type": "string", + "empty": true + }, + "BANK_BIC": { + "type": "string", + "empty": true + }, + "BANK_ACCOUNT_MANDATE_REFERENCE": { + "type": "string", + "empty": true + }, + "SHOW_PAYMENT_NOTICE": { + "type": "string", + "empty": true + }, + "CUSTOMER_ACCOUNT": { + "type": "string", + "empty": true + }, + "CUSTOMER_TYPE": { + "type": "string", + "empty": true + }, + "TOP": { + "type": "string", + "empty": true + }, + "NEWSLETTER_OPTIN": { + "type": "string", + "empty": true + }, + "ORGANIZATION": { + "type": "string", + "empty": true + }, + "POSITION": { + "type": "string", + "empty": true + }, + "ACADEMIC_DEGREE": { + "type": "string", + "empty": true + }, + "SALUTATION": { + "type": "string", + "empty": true + }, + "FIRST_NAME": { + "type": "string", + "empty": true + }, + "LAST_NAME": { + "type": "string", + "empty": true + }, + "ADDRESS": { + "type": "string", + "empty": true + }, + "ADDRESS_2": { + "type": "string", + "empty": true + }, + "ZIPCODE": { + "type": "string", + "empty": true + }, + "CITY": { + "type": "string", + "empty": true + }, + "COUNTRY_CODE": { + "type": "string" + }, + "SECONDARY_ADDRESS": { + "type": "string", + "empty": true + }, + "PHONE": { + "type": "string", + "empty": true + }, + "PHONE_2": { + "type": "string", + "empty": true + }, + "FAX": { + "type": "string", + "empty": true + }, + "MOBILE": { + "type": "string", + "empty": true + }, + "EMAIL": { + "type": "string", + "empty": true + }, + "WEBSITE": { + "type": "string", + "empty": true + }, + "VAT_ID": { + "type": "string" + }, + "CURRENCY_CODE": { + "type": "string" + }, + "LASTUPDATE": { + "type": "string" + }, + "TAGS": { + "type": "string", + "empty": true + }, + "DOCUMENT_HISTORY_URL": { + "type": "string", + "empty": true + } + } +} diff --git a/airbyte-integrations/connectors/source-fastbill/source_fastbill/schemas/invoices.json b/airbyte-integrations/connectors/source-fastbill/source_fastbill/schemas/invoices.json new file mode 100644 index 000000000000..4ff47f38dc9e --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/source_fastbill/schemas/invoices.json @@ -0,0 +1,231 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "INVOICE_ID": { + "type": "string" + }, + "TYPE": { + "type": "string" + }, + "CUSTOMER_ID": { + "type": "string" + }, + "CUSTOMER_NUMBER": { + "type": "string" + }, + "CUSTOMER_COSTCENTER_ID": { + "type": "string" + }, + "CONTACT_ID": { + "type": "string" + }, + "PROJECT_ID": { + "type": "string" + }, + "CURRENCY_CODE": { + "type": "string" + }, + "DELIVERY_DATE": { + "type": "string" + }, + "INVOICE_TITLE": { + "type": "string", + "empty": true + }, + "CASH_DISCOUNT_PERCENT": { + "type": "string" + }, + "CASH_DISCOUNT_DAYS": { + "type": "string" + }, + "SUB_TOTAL": { + "type": "number" + }, + "VAT_TOTAL": { + "type": "number" + }, + "VAT_CASE": { + "type": "string" + }, + "VAT_ITEMS": { + "type": ["null", "array"], + "items": { + "type": "object", + "properties": { + "VAT_PERCENT": { + "type": "integer" + }, + "COMPLETE_NET": { + "type": "number" + }, + "VAT_VALUE": { + "type": "number" + } + } + } + }, + "ITEMS": { + "type": ["null", "array"], + "items": { + "type": "object", + "properties": { + "INVOICE_ITEM_ID": { + "type": "integer" + }, + "ARTICLE_NUMBER": { + "type": "string" + }, + "DESCRIPTION": { + "type": "string", + "empty": true + }, + "QUANTITY": { + "type": "integer" + }, + "UNIT_PRICE": { + "type": "number" + }, + "VAT_PERCENT": { + "type": "integer" + }, + "VAT_VALUE": { + "type": "number" + }, + "COMPLETE_NET": { + "type": "number" + }, + "COMPLETE_GROSS": { + "type": "number" + }, + "CATEGORY": { + "type": ["null", "array"], + "items": {} + }, + "CATEGORY_ID": { + "type": ["null", "array"], + "items": {} + }, + "SORT_ORDER": { + "type": "integer" + } + } + } + }, + "TOTAL": { + "type": "number" + }, + "ORGANIZATION": { + "type": "string", + "empty": true + }, + "NOTE": { + "type": "string", + "empty": true + }, + "SALUTATION": { + "type": "string", + "empty": true + }, + "FIRST_NAME": { + "type": "string", + "empty": true + }, + "LAST_NAME": { + "type": "string", + "empty": true + }, + "ADDRESS": { + "type": "string", + "empty": true + }, + "ADDRESS_2": { + "type": "string", + "empty": true + }, + "ZIPCODE": { + "type": "string", + "empty": true + }, + "CITY": { + "type": "string", + "empty": true + }, + "SERVICE_PERIOD_START": { + "type": "string" + }, + "SERVICE_PERIOD_END": { + "type": "string" + }, + "PAYMENT_TYPE": { + "type": "string", + "empty": true + }, + "BANK_NAME": { + "type": "string", + "empty": true + }, + "BANK_ACCOUNT_NUMBER": { + "type": "string", + "empty": true + }, + "BANK_CODE": { + "type": "string", + "empty": true + }, + "BANK_ACCOUNT_OWNER": { + "type": "string", + "empty": true + }, + "BANK_IBAN": { + "type": "string", + "empty": true + }, + "BANK_BIC": { + "type": "string", + "empty": true + }, + "COUNTRY_CODE": { + "type": "string" + }, + "VAT_ID": { + "type": "string" + }, + "TEMPLATE_ID": { + "type": "string", + "empty": true + }, + "INVOICE_NUMBER": { + "type": "string" + }, + "INTROTEXT": { + "type": "string", + "empty": true + }, + "PAID_DATE": { + "type": "string" + }, + "IS_CANCELED": { + "type": "string" + }, + "INVOICE_DATE": { + "type": "string" + }, + "DUE_DATE": { + "type": "string" + }, + "PAYMENT_INFO": { + "type": "string" + }, + "PAYMENTS": { + "type": ["null", "array"], + "items": {} + }, + "LASTUPDATE": { + "type": "string" + }, + "DOCUMENT_URL": { + "type": "string" + } + } +} diff --git a/airbyte-integrations/connectors/source-fastbill/source_fastbill/schemas/products.json b/airbyte-integrations/connectors/source-fastbill/source_fastbill/schemas/products.json new file mode 100644 index 000000000000..41103e22ab2b --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/source_fastbill/schemas/products.json @@ -0,0 +1,38 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "ARTICLE_ID": { + "type": "string" + }, + "ARTICLE_NUMBER": { + "type": "string" + }, + "TITLE": { + "type": "string" + }, + "DESCRIPTION": { + "type": "string", + "empty": true + }, + "UNIT": { + "type": "string" + }, + "UNIT_PRICE": { + "type": "string" + }, + "CURRENCY_CODE": { + "type": "string" + }, + "VAT_PERCENT": { + "type": "string" + }, + "IS_GROSS": { + "type": "number" + }, + "TAGS": { + "type": ["string", "null"], + "empty": true + } + } +} diff --git a/airbyte-integrations/connectors/source-fastbill/source_fastbill/schemas/recurring_invoices.json b/airbyte-integrations/connectors/source-fastbill/source_fastbill/schemas/recurring_invoices.json new file mode 100644 index 000000000000..36bdc11c09e7 --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/source_fastbill/schemas/recurring_invoices.json @@ -0,0 +1,210 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": ["object"], + "properties": { + "INVOICE_ID": { + "type": ["string"] + }, + "TYPE": { + "type": ["null", "string"] + }, + "CUSTOMER_ID": { + "type": ["null", "string"] + }, + "CUSTOMER_NUMBER": { + "type": ["null", "string"] + }, + "CUSTOMER_COSTCENTER_ID": { + "type": ["null", "string"] + }, + "CONTACT_ID": { + "type": ["null", "string"] + }, + "PROJECT_ID": { + "type": ["null", "string"] + }, + "CURRENCY_CODE": { + "type": ["null", "string"] + }, + "DELIVERY_DATE": { + "type": ["null", "string"] + }, + "INVOICE_TITLE": { + "type": ["null", "string"] + }, + "CASH_DISCOUNT_PERCENT": { + "type": ["null", "string"] + }, + "CASH_DISCOUNT_DAYS": { + "type": ["null", "string"] + }, + "SUB_TOTAL": { + "type": ["null", "number"] + }, + "VAT_TOTAL": { + "type": ["null", "number"] + }, + "VAT_CASE": { + "type": ["null", "string"] + }, + "VAT_ITEMS": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "VAT_PERCENT": { + "type": ["null", "number"] + }, + "COMPLETE_NET": { + "type": ["null", "number"] + }, + "VAT_VALUE": { + "type": ["null", "number"] + } + } + } + }, + "ITEMS": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "INVOICE_ITEM_ID": { + "type": ["null", "number"] + }, + "ARTICLE_NUMBER": { + "type": ["null", "string"] + }, + "DESCRIPTION": { + "type": ["null", "string"] + }, + "QUANTITY": { + "type": ["null", "number"] + }, + "UNIT_PRICE": { + "type": ["null", "number"] + }, + "VAT_PERCENT": { + "type": ["null", "number"] + }, + "VAT_VALUE": { + "type": ["null", "number"] + }, + "COMPLETE_NET": { + "type": ["null", "number"] + }, + "COMPLETE_GROSS": { + "type": ["null", "number"] + }, + "CATEGORY": { + "type": ["null", "string", "array"], + "empty": true, + "items": {} + }, + "CATEGORY_ID": { + "type": ["null", "integer", "array"], + "items": {} + }, + "SORT_ORDER": { + "type": ["null", "number"] + } + } + } + }, + "TOTAL": { + "type": ["null", "number"] + }, + "ORGANIZATION": { + "type": ["null", "string"], + "empty": true + }, + "NOTE": { + "type": ["null", "string"], + "empty": true + }, + "SALUTATION": { + "type": ["null", "string"], + "empty": true + }, + "FIRST_NAME": { + "type": ["null", "string"], + "empty": true + }, + "LAST_NAME": { + "type": ["null", "string"], + "empty": true + }, + "ADDRESS": { + "type": ["null", "string"], + "empty": true + }, + "ADDRESS_2": { + "type": ["null", "string"], + "empty": true + }, + "ZIPCODE": { + "type": ["null", "string"], + "empty": true + }, + "CITY": { + "type": ["null", "string"], + "empty": true + }, + "SERVICE_PERIOD_START": { + "type": ["null", "string"] + }, + "SERVICE_PERIOD_END": { + "type": ["null", "string"] + }, + "PAYMENT_TYPE": { + "type": ["null", "string"] + }, + "BANK_NAME": { + "type": ["null", "string"], + "empty": true + }, + "BANK_ACCOUNT_NUMBER": { + "type": ["null", "string"], + "empty": true + }, + "BANK_CODE": { + "type": ["null", "string"], + "empty": true + }, + "BANK_ACCOUNT_OWNER": { + "type": ["null", "string"], + "empty": true + }, + "BANK_IBAN": { + "type": ["null", "string"], + "empty": true + }, + "BANK_BIC": { + "type": ["null", "string"], + "empty": true + }, + "TEMPLATE_ID": { + "type": ["null", "string"], + "empty": true + }, + "OCCURENCES": { + "type": ["null", "string"] + }, + "FREQUENCY": { + "type": ["null", "string"] + }, + "START_DATE": { + "type": ["null", "string"] + }, + "EMAIL_NOTIFY": { + "type": ["null", "string"] + }, + "OUTPUT_TYPE": { + "type": ["null", "string"] + }, + "INTROTEXT": { + "type": ["null", "string"], + "empty": true + } + } +} diff --git a/airbyte-integrations/connectors/source-fastbill/source_fastbill/schemas/revenues.json b/airbyte-integrations/connectors/source-fastbill/source_fastbill/schemas/revenues.json new file mode 100644 index 000000000000..b3c9bbae07f7 --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/source_fastbill/schemas/revenues.json @@ -0,0 +1,251 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "INVOICE_ID": { + "type": ["string"] + }, + "TYPE": { + "type": ["null", "string"] + }, + "CUSTOMER_ID": { + "type": ["null", "string"] + }, + "CUSTOMER_NUMBER": { + "type": ["null", "string"] + }, + "CUSTOMER_COSTCENTER_ID": { + "type": ["null", "string"] + }, + "CONTACT_ID": { + "type": ["null", "string"] + }, + "PROJECT_ID": { + "type": ["null", "string"] + }, + "CURRENCY_CODE": { + "type": ["null", "string"] + }, + "DELIVERY_DATE": { + "type": ["null", "string"] + }, + "INVOICE_TITLE": { + "type": ["null", "string"], + "empty": true + }, + "CASH_DISCOUNT_PERCENT": { + "type": ["null", "string"] + }, + "CASH_DISCOUNT_DAYS": { + "type": ["null", "string"] + }, + "SUB_TOTAL": { + "type": ["null", "integer"] + }, + "VAT_TOTAL": { + "type": ["null", "number"] + }, + "VAT_CASE": { + "type": ["null", "string"] + }, + "VAT_ITEMS": { + "type": ["array", "null"], + "items": { + "type": "object", + "properties": { + "VAT_PERCENT": { + "type": ["null", "integer"] + }, + "COMPLETE_NET": { + "type": ["null", "integer"] + }, + "VAT_VALUE": { + "type": ["null", "number"] + } + } + } + }, + "ITEMS": { + "type": ["array", "null"], + "items": { + "type": "object", + "properties": { + "INVOICE_ITEM_ID": { + "type": ["null", "integer"] + }, + "ARTICLE_NUMBER": { + "type": ["null", "string"] + }, + "DESCRIPTION": { + "type": ["null", "string"] + }, + "QUANTITY": { + "type": ["null", "integer"] + }, + "UNIT_PRICE": { + "type": ["null", "integer"] + }, + "VAT_PERCENT": { + "type": ["null", "integer"] + }, + "VAT_VALUE": { + "type": ["null", "number"] + }, + "COMPLETE_NET": { + "type": ["null", "integer"] + }, + "COMPLETE_GROSS": { + "type": ["null", "number"] + }, + "CATEGORY": { + "type": ["null", "array", "string"], + "empty": true + }, + "CATEGORY_ID": { + "type": ["null", "array", "integer"] + }, + "SORT_ORDER": { + "type": ["null", "integer"] + } + } + } + }, + "TOTAL": { + "type": ["number", "null"] + }, + "ORGANIZATION": { + "type": ["null", "string"], + "empty": true + }, + "NOTE": { + "type": ["null", "string"], + "empty": true + }, + "SALUTATION": { + "type": ["null", "string"], + "empty": true + }, + "FIRST_NAME": { + "type": ["null", "string"], + "empty": true + }, + "LAST_NAME": { + "type": ["null", "string"], + "empty": true + }, + "ADDRESS": { + "type": ["null", "string"], + "empty": true + }, + "ADDRESS_2": { + "type": ["null", "string"], + "empty": true + }, + "ZIPCODE": { + "type": ["null", "string"], + "empty": true + }, + "CITY": { + "type": ["null", "string"], + "empty": true + }, + "SERVICE_PERIOD_START": { + "type": ["null", "string"], + "empty": true + }, + "SERVICE_PERIOD_END": { + "type": ["null", "string"], + "empty": true + }, + "PAYMENT_TYPE": { + "type": ["null", "string"], + "empty": true + }, + "BANK_NAME": { + "type": ["null", "string"], + "empty": true + }, + "BANK_ACCOUNT_NUMBER": { + "type": ["null", "string"], + "empty": true + }, + "BANK_CODE": { + "type": ["null", "string"], + "empty": true + }, + "BANK_ACCOUNT_OWNER": { + "type": ["null", "string"], + "empty": true + }, + "BANK_IBAN": { + "type": ["null", "string"], + "empty": true + }, + "BANK_BIC": { + "type": ["null", "string"], + "empty": true + }, + "COUNTRY_CODE": { + "type": ["null", "string"] + }, + "VAT_ID": { + "type": ["null", "string"] + }, + "TEMPLATE_ID": { + "type": ["null", "string"], + "empty": true + }, + "INVOICE_NUMBER": { + "type": ["null", "string"] + }, + "INTROTEXT": { + "type": ["null", "string"], + "empty": true + }, + "PAID_DATE": { + "type": ["null", "string"] + }, + "IS_CANCELED": { + "type": ["null", "string"] + }, + "INVOICE_DATE": { + "type": ["null", "string"] + }, + "DUE_DATE": { + "type": ["null", "string"] + }, + "PAYMENT_INFO": { + "type": ["null", "string"] + }, + "PAYMENTS": { + "type": ["null", "array"], + "items": { + "PAYMENT_ID": { + "type": ["string", "null"] + }, + "DATE": { + "type": ["string", "null"] + }, + "AMOUNT": { + "type": ["string", "null"] + }, + "CURRENCY_CODE": { + "type": ["string", "null"] + }, + "NOTE": { + "type": ["string", "null"], + "empty": true + }, + "TYPE": { + "type": ["string", "null"] + } + } + }, + "LASTUPDATE": { + "type": ["null", "string"] + }, + "DOCUMENT_URL": { + "type": ["null", "string"] + } + } +} diff --git a/airbyte-integrations/connectors/source-fastbill/source_fastbill/source.py b/airbyte-integrations/connectors/source-fastbill/source_fastbill/source.py new file mode 100644 index 000000000000..d1ca03432506 --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/source_fastbill/source.py @@ -0,0 +1,121 @@ +# +# Copyright (c) 2022 Airbyte, Inc., all rights reserved. +# + + +from abc import ABC +from typing import Any, Iterable, List, Mapping, MutableMapping, Optional, Tuple, Union + +import requests +from airbyte_cdk.models import SyncMode +from airbyte_cdk.sources import AbstractSource +from airbyte_cdk.sources.streams import Stream +from airbyte_cdk.sources.streams.http import HttpStream +from source_fastbill.helpers import get_next_page_token, get_request_body_json + + +class FastbillStream(HttpStream, ABC): + url_base = " https://my.fastbill.com/api/1.0/api.php" + API_OFFSET_LIMIT = 100 + + def __init__(self, *args, username: str = None, api_key: str = None, **kwargs): + super().__init__(*args, **kwargs) + # self.endpoint = None + self._username = username + self._api_key = api_key + # self.data = None + + @property + def http_method(self) -> str: + return "POST" + + def path( + self, + *, + stream_state: Mapping[str, Any] = None, + stream_slice: Mapping[str, Any] = None, + next_page_token: Mapping[str, Any] = None, + ) -> 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 + ) -> MutableMapping[str, Any]: + return None + + def request_headers( + self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None + ) -> Mapping[str, Any]: + return {"Content-type": "application/json"} + + def request_body_json( + self, + stream_state: Mapping[str, Any], + stream_slice: Mapping[str, Any] = None, + next_page_token: Mapping[str, Any] = None, + ) -> Optional[Union[Mapping, str]]: + return get_request_body_json(next_page_token, endpoint=self.endpoint) + + def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, Any]]: + return get_next_page_token( + response=response, response_key=self.data, API_OFFSET_LIMIT=self.API_OFFSET_LIMIT, endpoint=self.endpoint + ) + + def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]: + yield from response.json().get("RESPONSE", {}).get(self.data, []) + + +class Invoices(FastbillStream): + primary_key = "INVOICE_ID" + data = "INVOICES" + endpoint = "invoice" + + +class RecurringInvoices(FastbillStream): + primary_key = "INVOICE_ID" + data = "INVOICES" + endpoint = "recurring" + + +class Products(FastbillStream): + primary_key = "ARTICLE_ID" + data = "ARTICLES" + endpoint = "article" + + +class Revenues(FastbillStream): + primary_key = "INVOICE_ID" + data = "REVENUES" + endpoint = "revenue" + + +class Customers(FastbillStream): + primary_key = "CUSTOMER_ID" + data = "CUSTOMERS" + endpoint = "customer" + + +# Source +class SourceFastbill(AbstractSource): + def get_basic_auth(self, config: Mapping[str, Any]) -> requests.auth.HTTPBasicAuth: + return requests.auth.HTTPBasicAuth(config["username"], config["api_key"]) + + def check_connection(self, logger, config) -> Tuple[bool, any]: + try: + auth = self.get_basic_auth(config) + records = Customers(auth, **config).read_records(sync_mode=SyncMode.full_refresh) + next(records, None) + return True, None + except Exception as error: + return False, f"Unable to connect to Fastbill API with the provided credentials - {repr(error)}" + + def streams(self, config: Mapping[str, Any]) -> List[Stream]: + + auth = self.get_basic_auth(config) + return [ + Customers(auth, **config), + Invoices(auth, **config), + RecurringInvoices(auth, **config), + Products(auth, **config), + Revenues(auth, **config), + ] diff --git a/airbyte-integrations/connectors/source-fastbill/source_fastbill/spec.yaml b/airbyte-integrations/connectors/source-fastbill/source_fastbill/spec.yaml new file mode 100644 index 000000000000..7352591fdcf4 --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/source_fastbill/spec.yaml @@ -0,0 +1,18 @@ +documentationUrl: "https://docs.airbyte.com/integrations/sources/fastbill" +connectionSpecification: + $schema: http://json-schema.org/draft-07/schema# + title: Fastbill Spec + type: object + required: + - username + - api_key + properties: + username: + title: Username + type: string + description: Username for Fastbill account + api_key: + title: API Key + type: string + description: Fastbill API key + airbyte_secret: true diff --git a/airbyte-integrations/connectors/source-fastbill/unit_tests/__init__.py b/airbyte-integrations/connectors/source-fastbill/unit_tests/__init__.py new file mode 100644 index 000000000000..1100c1c58cf5 --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/unit_tests/__init__.py @@ -0,0 +1,3 @@ +# +# Copyright (c) 2022 Airbyte, Inc., all rights reserved. +# diff --git a/airbyte-integrations/connectors/source-fastbill/unit_tests/test_source.py b/airbyte-integrations/connectors/source-fastbill/unit_tests/test_source.py new file mode 100644 index 000000000000..1c71b6b39055 --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/unit_tests/test_source.py @@ -0,0 +1,39 @@ +# +# Copyright (c) 2022 Airbyte, Inc., all rights reserved. +# + +from unittest.mock import MagicMock + +import responses +from source_fastbill.source import SourceFastbill + + +@responses.activate +def test_check_connection(mocker): + url = "https://my.fastbill.com/api/1.0/api.php" + source = SourceFastbill() + logger_mock, config_mock = MagicMock(), MagicMock() + responses.add( + responses.POST, + url, + json={ + "REQUEST": { + "OFFSET": 0, + "FILTER": [], + "LIMIT": 0, + }, + "RESPONSE": { + "CUSTOMERS": "", + }, + }, + ) + assert source.check_connection(logger_mock, config_mock) == (True, None) + + +def test_streams(mocker): + source = SourceFastbill() + config_mock = MagicMock() + streams = source.streams(config_mock) + # TODO: replace this with your streams number + expected_streams_number = 5 + assert len(streams) == expected_streams_number diff --git a/airbyte-integrations/connectors/source-fastbill/unit_tests/test_streams.py b/airbyte-integrations/connectors/source-fastbill/unit_tests/test_streams.py new file mode 100644 index 000000000000..c992d8f11167 --- /dev/null +++ b/airbyte-integrations/connectors/source-fastbill/unit_tests/test_streams.py @@ -0,0 +1,73 @@ +# +# Copyright (c) 2022 Airbyte, Inc., all rights reserved. +# + +from http import HTTPStatus +from unittest.mock import MagicMock + +import pytest +from source_fastbill.source import FastbillStream + + +@pytest.fixture +def patch_base_class(mocker): + # Mock abstract methods to enable instantiating abstract class + mocker.patch.object(FastbillStream, "path", "v0/example_endpoint") + mocker.patch.object(FastbillStream, "primary_key", "test_primary_key") + mocker.patch.object(FastbillStream, "__abstractmethods__", set()) + + +def test_request_params(patch_base_class): + stream = FastbillStream() + # TODO: replace this with your input parameters + inputs = {"stream_slice": None, "stream_state": None, "next_page_token": None} + # TODO: replace this with your expected request parameters + expected_params = None + assert stream.request_params(**inputs) == expected_params + + +def test_next_page_token(patch_base_class): + stream = FastbillStream() + stream.endpoint = "test_endpoint" + stream.data = "test_data" + inputs = {"response": MagicMock()} + + inputs["response"].json.return_value = {"REQUEST": {"OFFSET": 0}, "RESPONSE": {"test_data": []}} + expected_token = None + assert stream.next_page_token(**inputs) == expected_token + + +def test_request_headers(patch_base_class): + stream = FastbillStream() + inputs = {"stream_slice": None, "stream_state": None, "next_page_token": None} + expected_headers = {"Content-type": "application/json"} + assert stream.request_headers(**inputs) == expected_headers + + +def test_http_method(patch_base_class): + stream = FastbillStream() + expected_method = "POST" + assert stream.http_method == expected_method + + +@pytest.mark.parametrize( + ("http_status", "should_retry"), + [ + (HTTPStatus.OK, False), + (HTTPStatus.BAD_REQUEST, False), + (HTTPStatus.TOO_MANY_REQUESTS, True), + (HTTPStatus.INTERNAL_SERVER_ERROR, True), + ], +) +def test_should_retry(patch_base_class, http_status, should_retry): + response_mock = MagicMock() + response_mock.status_code = http_status + stream = FastbillStream() + assert stream.should_retry(response_mock) == should_retry + + +def test_backoff_time(patch_base_class): + response_mock = MagicMock() + stream = FastbillStream() + expected_backoff_time = None + assert stream.backoff_time(response_mock) == expected_backoff_time diff --git a/docs/integrations/sources/fastbill.md b/docs/integrations/sources/fastbill.md new file mode 100644 index 000000000000..6979873f96bf --- /dev/null +++ b/docs/integrations/sources/fastbill.md @@ -0,0 +1,64 @@ +# Fastbill + +This page contains the setup guide and reference information for the [Fastbill](https://www.fastbill.com/) source connector. + +You can find more information about the Fastbill REST API [here](https://apidocs.fastbill.com/). + +## Prerequisites + +You can find your Project ID and find or create an API key within [Fastbill](https://my.fastbill.com/index.php?s=D7GCLx0WuylFq3nl4gAvRQMwS8RDyb3sCe_bEoXoU_w). + +## Setup guide + +## Step 1: Set up the Fastbill connector in Airbyte + +### For Airbyte Cloud: + +1. [Log into your Airbyte Cloud](https://cloud.airbyte.io/workspaces) account. +2. In the left navigation bar, click **Sources**. In the top-right corner, click **+new source**. +3. On the Set up the source page, enter the name for the Fastbill connector and select **Fastbill** from the Source type dropdown. +4. Enter your `username` - Fastbill username/email. +5. Enter your `api_key` - Fastbill API key with read permissions. +6. Click **Set up source**. + +### For Airbyte OSS: + +1. Navigate to the Airbyte Open Source dashboard. +2. Set the name for your source. +3. Enter your `project_id` - Fastbill Project ID. +4. Enter your `api_key` - Fastbill API key with read permissions. +5. Click **Set up source**. + +## Supported sync modes + +The Fastbill source connector supports the following [sync modes](https://docs.airbyte.com/cloud/core-concepts#connection-sync-modes): + +| Feature | Supported? | +| :---------------- |:-----------| +| Full Refresh Sync | Yes | +| Incremental Sync | No | +| SSL connection | No | +| Namespaces | No | + +## Supported Streams + +* [Customers](https://apidocs.fastbill.com/fastbill/de/customer.html#customer.get) +* [Invoices](https://apidocs.fastbill.com/fastbill/de/invoice.html#invoice.get) +* [Products](https://apidocs.fastbill.com/fastbill/de/recurring.html#recurring.get) +* [Recurring_invoices](https://apidocs.fastbill.com/fastbill/de/recurring.html#recurring.get) +* [Revenues](https://apidocs.fastbill.com/fastbill/de/revenue.html#revenue.get) + +## Data type map + +| Integration Type | Airbyte Type | +| :------------------ | :----------- | +| `string` | `string` | +| `integer`, `number` | `number` | +| `array` | `array` | +| `object` | `object` | + +## Changelog + +| Version | Date | Pull Request | Subject | +|:--------|:------------|:---------------------------------------------------------|:--------------------------------------------------| +| 0.1.0 | 2022-10-TBA | [18522](https://github.com/airbytehq/airbyte/pull/18593) | New Source: Fastbill | \ No newline at end of file