diff --git a/airbyte-config/init/src/main/resources/icons/zenefits.svg b/airbyte-config/init/src/main/resources/icons/zenefits.svg new file mode 100644 index 0000000000000..366b3f4757ec2 --- /dev/null +++ b/airbyte-config/init/src/main/resources/icons/zenefits.svg @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file 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 0be765b535b5b..e1d6fa7689352 100644 --- a/airbyte-config/init/src/main/resources/seed/source_definitions.yaml +++ b/airbyte-config/init/src/main/resources/seed/source_definitions.yaml @@ -1153,6 +1153,14 @@ icon: zendesk.svg sourceType: api releaseStage: beta +- name: Zenefits + sourceDefinitionId: 8baba53d-2fe3-4e33-bc85-210d0eb62884 + dockerRepository: airbyte/source-zenefits + dockerImageTag: 0.1.0 + documentationUrl: https://docs.airbyte.io/integrations/sources/zenefits + icon: zenefits.svg + sourceType: api + releaseStage: alpha - name: Zenloop sourceDefinitionId: f1e4c7f6-db5c-4035-981f-d35ab4998794 dockerRepository: airbyte/source-zenloop 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 967c0eaf3f898..ab41e71344256 100644 --- a/airbyte-config/init/src/main/resources/seed/source_specs.yaml +++ b/airbyte-config/init/src/main/resources/seed/source_specs.yaml @@ -11834,6 +11834,25 @@ path_in_connector_config: - "credentials" - "client_secret" +- dockerImage: "airbyte/source-zenefits:0.1.0" + spec: + documentationUrl: "https://docsurl.com" + connectionSpecification: + $schema: "http://json-schema.org/draft-07/schema#" + title: "Zenefits Integration Spec" + type: "object" + required: + - "token" + additionalProperties: false + properties: + token: + title: "token" + type: "string" + description: "Use Sync with Zenefits button on the link given on the readme\ + \ file, and get the token to access the api" + supportsNormalization: false + supportsDBT: false + supported_destination_sync_modes: [] - dockerImage: "airbyte/source-zenloop:0.1.2" spec: documentationUrl: "https://docs.airbyte.io/integrations/sources/zenloop" diff --git a/airbyte-integrations/connectors/source-zenefits/.dockerignore b/airbyte-integrations/connectors/source-zenefits/.dockerignore new file mode 100644 index 0000000000000..f443406889f61 --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/.dockerignore @@ -0,0 +1,6 @@ +* +!Dockerfile +!main.py +!source_zenefits +!setup.py +!secrets diff --git a/airbyte-integrations/connectors/source-zenefits/Dockerfile b/airbyte-integrations/connectors/source-zenefits/Dockerfile new file mode 100644 index 0000000000000..428b41031501a --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/Dockerfile @@ -0,0 +1,38 @@ +FROM python:3.9.11-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_zenefits ./source_zenefits + +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-zenefits diff --git a/airbyte-integrations/connectors/source-zenefits/README.md b/airbyte-integrations/connectors/source-zenefits/README.md new file mode 100644 index 0000000000000..2cc0dce4de01f --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/README.md @@ -0,0 +1,139 @@ +# *How to access the token from Zenefits* + +Login into the Zenefits portal.
+Follow the steps in the given link [Here](https://developers.zenefits.com/docs/sync-with-zenefits-button), This will generate and Bearer token for the user which can be used to interact with the API using the source-zenefits connector. + + + +# Zenefits Source + +This is the repository for the Zenefits source connector, written in Python. +For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.io/integrations/sources/zenefits). + +## Local development + +### Prerequisites +**To iterate on this connector, make sure to complete this prerequisites section.** + +#### Minimum Python version required `= 3.7.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-zenefits:build +``` + +#### Create credentials +**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.io/integrations/sources/zenefits) +to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_zenefits/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 zenefits 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-zenefits:dev +``` + +You can also build the connector image via Gradle: +``` +./gradlew :airbyte-integrations:connectors:source-zenefits: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-zenefits:dev spec +docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-zenefits:dev check --config /secrets/config.json +docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-zenefits:dev discover --config /secrets/config.json +docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-zenefits: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-zenefits:unitTest +``` +To run acceptance and custom integration tests: +``` +./gradlew :airbyte-integrations:connectors:source-zenefits: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-zenefits/acceptance-test-config.yml b/airbyte-integrations/connectors/source-zenefits/acceptance-test-config.yml new file mode 100644 index 0000000000000..97f1a19bae908 --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/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-zenefits:dev +tests: + spec: + - spec_path: "secrets/spec.json" + 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: [] + full_refresh: + - config_path: "secrets/config.json" + configured_catalog_path: "integration_tests/configured_catalog.json" diff --git a/airbyte-integrations/connectors/source-zenefits/acceptance-test-docker.sh b/airbyte-integrations/connectors/source-zenefits/acceptance-test-docker.sh new file mode 100644 index 0000000000000..c51577d10690c --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/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-zenefits/build.gradle b/airbyte-integrations/connectors/source-zenefits/build.gradle new file mode 100644 index 0000000000000..4d1cc2783d2e0 --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/build.gradle @@ -0,0 +1,9 @@ +plugins { + id 'airbyte-python' + id 'airbyte-docker' + id 'airbyte-source-acceptance-test' +} + +airbytePython { + moduleDirectory 'source_zenefits' +} diff --git a/airbyte-integrations/connectors/source-zenefits/integration_tests/__init__.py b/airbyte-integrations/connectors/source-zenefits/integration_tests/__init__.py new file mode 100644 index 0000000000000..cb65d40dabd20 --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/integration_tests/__init__.py @@ -0,0 +1,3 @@ +# +# Copyright (c) 2022s Airbyte, Inc., all rights reserved. +# diff --git a/airbyte-integrations/connectors/source-zenefits/integration_tests/acceptance.py b/airbyte-integrations/connectors/source-zenefits/integration_tests/acceptance.py new file mode 100644 index 0000000000000..59bc2f04e375b --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/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(): + + yield diff --git a/airbyte-integrations/connectors/source-zenefits/integration_tests/catalog.json b/airbyte-integrations/connectors/source-zenefits/integration_tests/catalog.json new file mode 100644 index 0000000000000..7cd5a20bafb57 --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/integration_tests/catalog.json @@ -0,0 +1,202 @@ +{ + "streams": [ + { + "stream": { + "name": "people", + "json_schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties":{ + "token":{ + "type":"string" + } + } + }, + "supported_sync_modes": ["full_refresh"], + "supported_destination_sync_modes": ["overwrite", "append"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append" + }, + { + "stream": { + "name": "employments", + "json_schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties":{ + "token":{ + "type":"string" + } + } + }, + "supported_sync_modes": ["full_refresh"], + "supported_destination_sync_modes": ["overwrite", "append"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append" + }, + { + "stream": { + "name": "vacation_requests", + "json_schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties":{ + "token":{ + "type":"string" + } + } + }, + "supported_sync_modes": ["full_refresh"], + "supported_destination_sync_modes": ["overwrite", "append"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append" + }, + { + "stream": { + "name": "vacation_types", + "json_schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties":{ + "token":{ + "type":"string" + } + } + }, + "supported_sync_modes": ["full_refresh"], + "supported_destination_sync_modes": ["overwrite", "append"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append" + }, + { + "stream": { + "name": "time_durations", + "json_schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties":{ + "token":{ + "type":"string" + } + } + }, + "supported_sync_modes": ["full_refresh"], + "supported_destination_sync_modes": ["overwrite", "append"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append" + }, + { + "stream": { + "name": "departments", + "json_schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties":{ + "token":{ + "type":"string" + } + } + }, + "supported_sync_modes": ["full_refresh"], + "supported_destination_sync_modes": ["overwrite", "append"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append" + }, + { + "stream": { + "name": "locations", + "json_schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties":{ + "token":{ + "type":"string" + } + } + }, + "supported_sync_modes": ["full_refresh"], + "supported_destination_sync_modes": ["overwrite", "append"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append" + }, + { + "stream": { + "name": "labor_group_types", + "json_schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties":{ + "token":{ + "type":"string" + } + } + }, + "supported_sync_modes": ["full_refresh"], + "supported_destination_sync_modes": ["overwrite", "append"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append" + }, + { + "stream": { + "name": "custom_fields", + "json_schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties":{ + "token":{ + "type":"string" + } + } + }, + "supported_sync_modes": ["full_refresh"], + "supported_destination_sync_modes": ["overwrite", "append"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append" + }, + { + "stream": { + "name": "custom_field_values", + "json_schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties":{ + "token":{ + "type":"string" + } + } + }, + "supported_sync_modes": ["full_refresh"], + "supported_destination_sync_modes": ["overwrite", "append"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append" + }, + { + "stream": { + "name": "labor_groups", + "json_schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties":{ + "token":{ + "type":"string" + } + } + }, + "supported_sync_modes": ["full_refresh"], + "supported_destination_sync_modes": ["overwrite", "append"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append" + } + ] +} \ No newline at end of file diff --git a/airbyte-integrations/connectors/source-zenefits/integration_tests/configured_catalog.json b/airbyte-integrations/connectors/source-zenefits/integration_tests/configured_catalog.json new file mode 100644 index 0000000000000..76c940bf00c0f --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/integration_tests/configured_catalog.json @@ -0,0 +1,202 @@ +{ + "streams": [ + { + "stream": { + "name": "people", + "json_schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties":{ + "token":{ + "type":"string" + } + } + }, + "supported_sync_modes": ["full_refresh"], + "supported_destination_sync_modes": ["overwrite", "append"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append" + }, + { + "stream": { + "name": "employments", + "json_schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties":{ + "token":{ + "type":"string" + } + } + }, + "supported_sync_modes": ["full_refresh"], + "supported_destination_sync_modes": ["overwrite", "append"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append" + }, + { + "stream": { + "name": "vacation_requests", + "json_schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties":{ + "token":{ + "type":"string" + } + } + }, + "supported_sync_modes": ["full_refresh"], + "supported_destination_sync_modes": ["overwrite", "append"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append" + }, + { + "stream": { + "name": "vacation_types", + "json_schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties":{ + "token":{ + "type":"string" + } + } + }, + "supported_sync_modes": ["full_refresh"], + "supported_destination_sync_modes": ["overwrite", "append"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append" + }, + { + "stream": { + "name": "time_durations", + "json_schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties":{ + "token":{ + "type":"string" + } + } + }, + "supported_sync_modes": ["full_refresh"], + "supported_destination_sync_modes": ["overwrite", "append"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append" + }, + { + "stream": { + "name": "departments", + "json_schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties":{ + "token":{ + "type":"string" + } + } + }, + "supported_sync_modes": ["full_refresh"], + "supported_destination_sync_modes": ["overwrite", "append"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append" + }, + { + "stream": { + "name": "locations", + "json_schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties":{ + "token":{ + "type":"string" + } + } + }, + "supported_sync_modes": ["full_refresh"], + "supported_destination_sync_modes": ["overwrite", "append"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append" + }, + { + "stream": { + "name": "labor_group_types", + "json_schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties":{ + "token":{ + "type":"string" + } + } + }, + "supported_sync_modes": ["full_refresh"], + "supported_destination_sync_modes": ["overwrite", "append"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append" + }, + { + "stream": { + "name": "custom_fields", + "json_schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties":{ + "token":{ + "type":"string" + } + } + }, + "supported_sync_modes": ["full_refresh"], + "supported_destination_sync_modes": ["overwrite", "append"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append" + }, + { + "stream": { + "name": "custom_field_values", + "json_schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties":{ + "token":{ + "type":"string" + } + } + }, + "supported_sync_modes": ["full_refresh"], + "supported_destination_sync_modes": ["overwrite", "append"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append" + }, + { + "stream": { + "name": "labor_groups", + "json_schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties":{ + "token":{ + "type":"string" + } + } + }, + "supported_sync_modes": ["full_refresh"], + "supported_destination_sync_modes": ["overwrite", "append"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append" + } + ] + } \ No newline at end of file diff --git a/airbyte-integrations/connectors/source-zenefits/integration_tests/invalid_config.json b/airbyte-integrations/connectors/source-zenefits/integration_tests/invalid_config.json new file mode 100644 index 0000000000000..5bb9d52efb481 --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/integration_tests/invalid_config.json @@ -0,0 +1,3 @@ +{ + "token": "sasdsas" +} diff --git a/airbyte-integrations/connectors/source-zenefits/main.py b/airbyte-integrations/connectors/source-zenefits/main.py new file mode 100644 index 0000000000000..3e008bc628eac --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/main.py @@ -0,0 +1,13 @@ +# +# Copyright (c) 2022 Airbyte, Inc., all rights reserved. +# + + +import sys + +from airbyte_cdk.entrypoint import launch +from source_zenefits import SourceZenefits + +if __name__ == "__main__": + source = SourceZenefits() + launch(source, sys.argv[1:]) diff --git a/airbyte-integrations/connectors/source-zenefits/requirements.txt b/airbyte-integrations/connectors/source-zenefits/requirements.txt new file mode 100644 index 0000000000000..0411042aa0911 --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/requirements.txt @@ -0,0 +1,2 @@ +-e ../../bases/source-acceptance-test +-e . diff --git a/airbyte-integrations/connectors/source-zenefits/setup.py b/airbyte-integrations/connectors/source-zenefits/setup.py new file mode 100644 index 0000000000000..007645df8529d --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/setup.py @@ -0,0 +1,29 @@ +# +# Copyright (c) 2022 Airbyte, Inc., all rights reserved. +# + + +from setuptools import find_packages, setup + +MAIN_REQUIREMENTS = [ + "airbyte-cdk~=0.1", +] + +TEST_REQUIREMENTS = [ + "pytest~=6.1", + "pytest-mock~=3.6.1", + "source-acceptance-test", +] + +setup( + name="source_zenefits", + description="Source implementation for Zenefits.", + 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-zenefits/source_zenefits/__init__.py b/airbyte-integrations/connectors/source-zenefits/source_zenefits/__init__.py new file mode 100644 index 0000000000000..69bcc1a443fd4 --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/source_zenefits/__init__.py @@ -0,0 +1,7 @@ +# +# Copyright (c) 2021 Airbyte, Inc., all rights reserved. +# + +from .source import SourceZenefits + +__all__ = ["SourceZenefits"] diff --git a/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/custom_field_values.json b/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/custom_field_values.json new file mode 100644 index 0000000000000..2cadf64dd492b --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/custom_field_values.json @@ -0,0 +1,46 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id":{ + "type":["string","null"] + }, + "url":{ + "type":["string","null"] + }, + "object":{ + "type":["string","null"] + }, + "value":{ + "type":["null","string","boolean"] + }, + "custom_field": { + "type": "object", + "properties": { + "ref_object": { + "type":["string","null"] + }, + "object": { + "type":["string","null"] + }, + "url": { + "type":["string","null"] + } + } + }, + "person": { + "type": "object", + "properties": { + "ref_object": { + "type":["string","null"] + }, + "object": { + "type":["string","null"] + }, + "url": { + "type":["string","null"] + } + } + } + } +} \ No newline at end of file diff --git a/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/custom_fields.json b/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/custom_fields.json new file mode 100644 index 0000000000000..ea57a75b129f8 --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/custom_fields.json @@ -0,0 +1,85 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id":{ + "type":["string","null"] + }, + "can_manager_view_field":{ + "type":["boolean","null"] + }, + "custom_field_values": { + "type": "object", + "properties": { + "ref_object": { + "type":["string","null"] + }, + "object": { + "type":["string","null"] + }, + "url": { + "type":["string","null"] + } + } + }, + "person_during_onboarding":{ + "type":["boolean","null"] + }, + "name":{ + "type":["string","null"] + }, + "is_field_completer_person":{ + "type":["boolean","null"] + }, + "url":{ + "type":["string","null"] + }, + "is_sensitive":{ + "type":["boolean","null"] + }, + "is_field_required":{ + "type":["boolean","null"] + }, + "object":{ + "type":["string","null"] + }, + "can_person_view_field":{ + "type":["boolean","null"] + }, + "can_person_edit_field":{ + "type":["boolean","null"] + }, + "company": { + "type": "object", + "properties": { + "ref_object": { + "type":["string","null"] + }, + "object": { + "type":["string","null"] + }, + "url": { + "type":["string","null"] + } + } + }, + "company_during_hiring":{ + "type":["boolean","null"] + }, + "custom_field_type":{ + "type":["string","null"] + }, + "help_url":{ + "type":["null","string"] + }, + "help_text":{ + "type":["string","null"] + }, + "help_url_media":{ + "type":["null","string"] + }, + "media_file_type":{ + "type":["null"] + } + } +} \ No newline at end of file diff --git a/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/departments.json b/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/departments.json new file mode 100644 index 0000000000000..8cc659d2506aa --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/departments.json @@ -0,0 +1,60 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id":{ + "type":["string","null"] + }, + "name":{ + "type":["string","null"] + }, + "labor_group": { + "type": "object", + "properties": { + "ref_object": { + "type":["string","null"] + }, + "object": { + "type":["string","null"] + }, + "url": { + "type":["string","null"] + } + } + }, + "people": { + "type": "object", + "properties": { + "ref_object": { + "type":["string","null"] + }, + "object": { + "type":["string","null"] + }, + "url": { + "type":["string","null"] + } + } + }, + "company": { + "type": "object", + "properties": { + "ref_object": { + "type":["string","null"] + }, + "object": { + "type":["string","null"] + }, + "url": { + "type":["string","null"] + } + } + }, + "url":{ + "type":["string","null"] + }, + "object":{ + "type":["string","null"] + } + } +} \ No newline at end of file diff --git a/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/employments.json b/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/employments.json new file mode 100644 index 0000000000000..f76a82609309f --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/employments.json @@ -0,0 +1,95 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "person": { + "type": "object", + "properties": { + "url": { + "type": [ + "string", + "null" + ] + }, + "object": { + "type": [ + "string", + "null" + ] + }, + "ref_object": { + "type": [ + "string", + "null" + ] + } + } + }, + "hire_date": { + "type": [ + "string", + "null" + ] + }, + "employment_type": { + "type": [ + "string", + "null" + ] + }, + "object": { + "type": [ + "string", + "null" + ] + }, + "is_active": { + "type": [ + "boolean", + "null" + ] + }, + "is_flsa_exempt": { + "type": [ + "string", + "null" + ] + }, + "termination_type": { + "type": [ + "string", + "null" + ] + }, + "termination_date": { + "type": [ + "string", + "null" + ] + }, + "url": { + "type": [ + "string", + "null" + ] + }, + "id": { + "type": [ + "string", + "null" + ] + }, + "working_hours_per_week": { + "type": [ + "string", + "null" + ] + }, + "employment_sub_type": { + "type": [ + "string", + "null" + ] + } + } +} \ No newline at end of file diff --git a/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/labor_group_types.json b/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/labor_group_types.json new file mode 100644 index 0000000000000..e94fb7f84eb2e --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/labor_group_types.json @@ -0,0 +1,46 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id":{ + "type":["string","null"] + }, + "name":{ + "type":["string","null"] + }, + "url":{ + "type":["string","null"] + }, + "company":{ + "type": "object", + "properties": { + "ref_object": { + "type":["string","null"] + }, + "object": { + "type":["string","null"] + }, + "url": { + "type":["string","null"] + } + } + }, + "labor_groups":{ + "type": "object", + "properties": { + "ref_object": { + "type":["string","null"] + }, + "object": { + "type":["string","null"] + }, + "url": { + "type":["string","null"] + } + } + }, + "object":{ + "type":["string","null"] + } + } +} \ No newline at end of file diff --git a/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/labor_groups.json b/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/labor_groups.json new file mode 100644 index 0000000000000..680a1a5caedfb --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/labor_groups.json @@ -0,0 +1,69 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id":{ + "type":["string","null"] + }, + "code":{ + "type":["string","null"] + }, + "name":{ + "type":["string","null"] + }, + "url":{ + "type":["string","null"] + }, + "object":{ + "type":["string","null"] + }, + "labor_group_type": { + "type": "object", + "properties": { + "ref_object": { + "type":["string","null"] + }, + "object": { + "type":["string","null"] + }, + "url": { + "type":["string","null"] + } + } + }, + "assigned_members": { + "type": "object", + "properties": { + "url": { + "type":["string","null"] + }, + "next_url": { + "type":["string","null"] + }, + "object": { + "type":["string","null"] + }, + "data":{ + "type": [ "array","null"], + "items": { + "type": ["object","null"], + "properties": { + "url":{ + "type":["string","null"] + }, + "is_primary":{ + "type":["boolean","null"] + }, + "object":{ + "type":["string","null"] + }, + "ref_object":{ + "type":["string","null"] + } + } + } + } + } + } + } +} diff --git a/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/locations.json b/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/locations.json new file mode 100644 index 0000000000000..dd35d4a62db93 --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/locations.json @@ -0,0 +1,81 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id":{ + "type":["string","null"] + }, + "name":{ + "type":["string","null"] + }, + "city":{ + "type":["string","null"] + }, + "labor_group": { + "type": "object", + "properties": { + "ref_object": { + "type":["string","null"] + }, + "object": { + "type":["string","null"] + }, + "url": { + "type":["string","null"] + } + } + }, + "zip":{ + "type":["string","null"] + }, + "people": { + "type": "object", + "properties": { + "ref_object": { + "type":["string","null"] + }, + "object": { + "type":["string","null"] + }, + "url": { + "type":["string","null"] + } + } + }, + "url":{ + "type":["string","null"] + }, + "street1":{ + "type":["string","null"] + }, + "street2":{ + "type":["string","null"] + }, + "object":{ + "type":["string","null"] + }, + "phone":{ + "type":["string","null"] + }, + "state":{ + "type":["string","null"] + }, + "country":{ + "type":["string","null"] + }, + "company": { + "type": "object", + "properties": { + "ref_object": { + "type":["string","null"] + }, + "object": { + "type":["string","null"] + }, + "url": { + "type":["string","null"] + } + } + } + } +} \ No newline at end of file diff --git a/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/people.json b/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/people.json new file mode 100644 index 0000000000000..c6fe26dc66104 --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/people.json @@ -0,0 +1,310 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "employee_number": { + "type": [ + "string", + "null" + ] + }, + "country": { + "type": [ + "string", + "null" + ] + }, + "labor_groups": { + "type": "object", + "properties": { + "ref_object": { + "type": [ + "string", + "null" + ] + }, + "object": { + "type": [ + "string", + "null" + ] + }, + "url": { + "type": [ + "string", + "null" + ] + } + } + }, + "is_admin": { + "type": [ + "boolean", + "null" + ] + }, + "object": { + "type": [ + "string", + "null" + ] + }, + "street1": { + "type": [ + "string", + "null" + ] + }, + "company": { + "type": "object", + "properties": { + "ref_object": { + "type": [ + "string", + "null" + ] + }, + "object": { + "type": [ + "string", + "null" + ] + }, + "url": { + "type": [ + "string", + "null" + ] + } + } + }, + "department": { + "type": "object", + "properties": { + "ref_object": { + "type": [ + "string", + "null" + ] + }, + "object": { + "type": [ + "string", + "null" + ] + }, + "url": { + "type": [ + "string", + "null" + ] + } + } + }, + "subordinates": { + "type": "object", + "properties": { + "ref_object": { + "type": [ + "string", + "null" + ] + }, + "object": { + "type": [ + "string", + "null" + ] + }, + "url": { + "type": [ + "string", + "null" + ] + } + } + }, + "location": { + "type": "object", + "properties": { + "ref_object": { + "type": [ + "string", + "null" + ] + }, + "object": { + "type": [ + "string", + "null" + ] + }, + "url": { + "type": [ + "string", + "null" + ] + } + } + }, + "work_phone": { + "type": [ + "string", + "null" + ] + }, + "middle_name": { + "type": [ + "string", + "null" + ] + }, + "custom_field_values": { + "type": "object", + "properties": { + "ref_object": { + "type": [ + "string", + "null" + ] + }, + "object": { + "type": [ + "string", + "null" + ] + }, + "url": { + "type": [ + "string", + "null" + ] + } + } + }, + "postal_code": { + "type": [ + "string", + "null" + ] + }, + "employments": { + "type": "object", + "properties": { + "ref_object": { + "type": [ + "string", + "null" + ] + }, + "object": { + "type": [ + "string", + "null" + ] + }, + "url": { + "type": [ + "string", + "null" + ] + } + } + }, + "manager": { + "type": "object", + "properties": { + "ref_object": { + "type": [ + "string", + "null" + ] + }, + "object": { + "type": [ + "string", + "null" + ] + }, + "url": { + "type": [ + "string", + "null" + ] + } + } + }, + "status": { + "type": [ + "string", + "null" + ] + }, + "last_name": { + "type": [ + "string", + "null" + ] + }, + "first_name": { + "type": [ + "string", + "null" + ] + }, + "state": { + "type": [ + "string", + "null" + ] + }, + "title": { + "type": [ + "string", + "null" + ] + }, + "url": { + "type": [ + "string", + "null" + ] + }, + "street2": { + "type": [ + "string", + "null" + ] + }, + "work_email": { + "type": [ + "string", + "null" + ] + }, + "preferred_name": { + "type": [ + "string", + "null" + ] + }, + "id": { + "type": [ + "string", + "null" + ] + }, + "type": { + "type": [ + "string", + "null" + ] + }, + "city": { + "type": [ + "string", + "null" + ] + } + } +} \ No newline at end of file diff --git a/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/time_durations.json b/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/time_durations.json new file mode 100644 index 0000000000000..09d6e9c856744 --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/time_durations.json @@ -0,0 +1,77 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "is_overnight":{ + "type":["boolean","null"] + }, + "is_approved":{ + "type":["boolean","null"] + }, + "object":{ + "type":["string","null"] + }, + "end":{ + "type":["string","null"], + "format": "date-time" + }, + "person": { + "type": "object", + "properties": { + "ref_object": { + "type":["string","null"] + }, + "object": { + "type":["string","null"] + }, + "url": { + "type":["string","null"] + } + } + }, + "url":{ + "type":["string","null"] + }, + "approver": { + "type": "object", + "properties": { + "ref_object": { + "type":["string","null"] + }, + "object": { + "type":["string","null"] + }, + "url": { + "type":["string","null"] + } + } + }, + "labor_group_ids":{ + "type":["string","null"] + }, + "hours":{ + "type":["string","null"] + }, + "start":{ + "type":["string","null"] + }, + "state":{ + "type":["string","null"] + }, + "approved_datetime":{ + "type":["string","null"] + }, + "valid_status":{ + "type":["string","null"] + }, + "date":{ + "type":["string","null"] + }, + "activity":{ + "type":["string","null"] + }, + "id":{ + "type":["string","null"] + } + } +} \ No newline at end of file diff --git a/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/vacation_requests.json b/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/vacation_requests.json new file mode 100644 index 0000000000000..8576786dd1030 --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/vacation_requests.json @@ -0,0 +1,141 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "status": { + "type": [ + "string", + "null" + ] + }, + "vacation_type": { + "type": "object", + "properties": { + "url": { + "type": [ + "string", + "null" + ] + }, + "object": { + "type": [ + "string", + "null" + ] + }, + "ref_object": { + "type": [ + "string", + "null" + ] + } + } + }, + "end_date": { + "type": [ + "string", + "null" + ] + }, + "creator": { + "type": "object", + "properties": { + "url": { + "type": [ + "string", + "null" + ] + }, + "object": { + "type": [ + "string", + "null" + ] + }, + "ref_object": { + "type": [ + "string", + "null" + ] + } + } + }, + "url": { + "type": [ + "string", + "null" + ] + }, + "object": { + "type": [ + "string", + "null" + ] + }, + "start_date": { + "type": [ + "string", + "null" + ] + }, + "hours": { + "type": [ + "string", + "null" + ] + }, + "approved_date": { + "type": [ + "string", + "null" + ] + }, + "reason": { + "type": [ + "string", + "null" + ] + }, + "person": { + "type": "object", + "properties": { + "url": { + "type": [ + "string", + "null" + ] + }, + "object": { + "type": [ + "string", + "null" + ] + }, + "ref_object": { + "type": [ + "string", + "null" + ] + } + } + }, + "created_date": { + "type": [ + "string", + "null" + ] + }, + "deny_reason": { + "type": [ + "string", + "null" + ] + }, + "id": { + "type": [ + "string", + "null" + ] + } + } +} \ No newline at end of file diff --git a/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/vacation_types.json b/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/vacation_types.json new file mode 100644 index 0000000000000..08bde21cdc533 --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/source_zenefits/schemas/vacation_types.json @@ -0,0 +1,88 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "status": { + "type": [ + "string", + "null" + ] + }, + "name": { + "type": [ + "string", + "null" + ] + }, + "url": { + "type": [ + "string", + "null" + ] + }, + "company": { + "type": "object", + "properties": { + "url": { + "type": [ + "string", + "null" + ] + }, + "object": { + "type": [ + "string", + "null" + ] + }, + "ref_object": { + "type": [ + "string", + "null" + ] + } + } + }, + "object": { + "type": [ + "string", + "null" + ] + }, + "vacation_requests": { + "type": "object", + "properties": { + "url": { + "type": [ + "string", + "null" + ] + }, + "object": { + "type": [ + "string", + "null" + ] + }, + "ref_object": { + "type": [ + "string", + "null" + ] + } + } + }, + "count_as": { + "type": [ + "string", + "null" + ] + }, + "id": { + "type": [ + "string", + "null" + ] + } + } +} \ No newline at end of file diff --git a/airbyte-integrations/connectors/source-zenefits/source_zenefits/source.py b/airbyte-integrations/connectors/source-zenefits/source_zenefits/source.py new file mode 100644 index 0000000000000..6d0ed8f175325 --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/source_zenefits/source.py @@ -0,0 +1,192 @@ +# +# Copyright (c) 2022 Airbyte, Inc., all rights reserved. +# + +from abc import ABC +from typing import Any, Iterable, List, Mapping, MutableMapping, Optional, Tuple +from urllib.parse import parse_qs, urlparse + +import requests +from airbyte_cdk.sources import AbstractSource +from airbyte_cdk.sources.streams import Stream +from airbyte_cdk.sources.streams.http import HttpStream + + +# Basic full refresh stream +class ZenefitsStream(HttpStream, ABC): + LIMIT = 100 + + url_base = "https://api.zenefits.com/" + + def __init__(self, token: str, **kwargs): + super().__init__(**kwargs) + self.token = token + + 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]: + + params = {"limit": self.LIMIT} + if next_page_token: + params = next_page_token + return params + + def request_headers(self, **kwargs) -> Mapping[str, Any]: + return {"Authorization": f"Bearer {self.token}", "Content-Type": "application/json", "Accept": "application/json"} + + + def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, Any]]: + response_json = response.json().get("data") + next_page_url = response_json.get("next_url") + if next_page_url: + next_url = urlparse(next_page_url) + next_params = parse_qs(next_url.query) + return next_params + + return None + + 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, + ) -> Iterable[Mapping]: + + return response.json().get("data", {}).get("data") + + +# Employee +class People(ZenefitsStream): + + primary_key = None + + def path(self, **kwargs) -> str: + + return "core/people" + + + +# Employee Employment details +class Employments(ZenefitsStream): + + primary_key = None + + def path(self, **kwargs) -> str: + return "core/employments" + + +# Departments +class Departments(ZenefitsStream): + + primary_key = None + + def path(self, **kwargs) -> str: + return "core/departments" + + + +# locations +class Locations(ZenefitsStream): + + primary_key = None + + def path(self, **kwargs) -> str: + return "core/locations" + + +# labor_groups +class Labor_groups(ZenefitsStream): + + primary_key = None + + def path(self, **kwargs) -> str: + return "core/labor_groups" + + + + +# labor_groups_types +class Labor_group_types(ZenefitsStream): + + primary_key = None + + def path(self, **kwargs) -> str: + return "core/labor_group_types" + + + + +# custom_fields +class Custom_fields(ZenefitsStream): + + primary_key = None + + def path(self, **kwargs) -> str: + return "core/custom_fields" + + + +# custom_field_values +class Custom_field_values(ZenefitsStream): + + primary_key = None + + def path(self, **kwargs) -> str: + return "core/custom_field_values" + + +# Vacation Requested +class Vacation_requests(ZenefitsStream): + primary_key = None + + def path(self, **kwargs) -> str: + return "time_off/vacation_requests" + + +# Vacation Types +class Vacation_types(ZenefitsStream): + primary_key = None + + def path(self, **kwargs) -> str: + return "time_off/vacation_types" + + + +# Time Durations +class Time_durations(ZenefitsStream): + primary_key = None + + def path(self, **kwargs) -> str: + return "time_attendance/time_durations" + + + +class SourceZenefits(AbstractSource): + def check_connection(self, logger, config) -> Tuple[bool, any]: + token = config["token"] + headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json", "Accept": "application/json"} + url = "https://api.zenefits.com/core/people" + + try: + session = requests.get(url, headers=headers) + session.raise_for_status() + return True, None + except requests.exceptions.RequestException as e: + return False, e + + def streams(self, config: Mapping[str, Any]) -> List[Stream]: + args = {"token": config["token"]} + return [ + People(**args), + Employments(**args), + Vacation_requests(**args), + Vacation_types(**args), + Time_durations(**args), + Departments(**args), + Locations(**args), + Labor_group_types(**args), + Custom_fields(**args), + Custom_field_values(**args), + Labor_groups(**args), + ] diff --git a/airbyte-integrations/connectors/source-zenefits/source_zenefits/spec.json b/airbyte-integrations/connectors/source-zenefits/source_zenefits/spec.json new file mode 100644 index 0000000000000..759e17e438602 --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/source_zenefits/spec.json @@ -0,0 +1,17 @@ +{ + "documentationUrl": "https://docsurl.com", + "connectionSpecification": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Zenefits Integration Spec", + "type": "object", + "required": ["token"], + "additionalProperties": false, + "properties": { + "token":{ + "title":"token", + "type": "string", + "description": "Use Sync with Zenefits button on the link given on the readme file, and get the token to access the api" + } + } + } +} diff --git a/airbyte-integrations/connectors/source-zenefits/unit_tests/__init__.py b/airbyte-integrations/connectors/source-zenefits/unit_tests/__init__.py new file mode 100644 index 0000000000000..1100c1c58cf51 --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/unit_tests/__init__.py @@ -0,0 +1,3 @@ +# +# Copyright (c) 2022 Airbyte, Inc., all rights reserved. +# diff --git a/airbyte-integrations/connectors/source-zenefits/unit_tests/test_source.py b/airbyte-integrations/connectors/source-zenefits/unit_tests/test_source.py new file mode 100644 index 0000000000000..37f2483509431 --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/unit_tests/test_source.py @@ -0,0 +1,29 @@ +# +# Copyright (c) 2022 Airbyte, Inc., all rights reserved. +# + +from unittest.mock import MagicMock + +from pytest import fixture +from source_zenefits.source import SourceZenefits + + +@fixture() +def config(request): + args = {"token": "YXNmnhkjf"} + return args + + +def test_check_connection(mocker, config): + source = SourceZenefits() + logger_mock = MagicMock() + (connection_status, error) = source.check_connection(logger_mock, config) + expected_status = False + assert connection_status == expected_status + + +def test_streams(mocker, config): + source = SourceZenefits() + streams = source.streams(config) + expected_streams_number = 11 + assert len(streams) == expected_streams_number diff --git a/airbyte-integrations/connectors/source-zenefits/unit_tests/test_streams.py b/airbyte-integrations/connectors/source-zenefits/unit_tests/test_streams.py new file mode 100644 index 0000000000000..53a57187b6190 --- /dev/null +++ b/airbyte-integrations/connectors/source-zenefits/unit_tests/test_streams.py @@ -0,0 +1,86 @@ +# +# Copyright (c) 2022 Airbyte, Inc., all rights reserved. +# + +from http import HTTPStatus + +# from unittest import result +from unittest.mock import MagicMock + +import pytest +from source_zenefits.source import ZenefitsStream + + +@pytest.fixture() +def config(request): + args = {"token": "YXNmnhkjf"} + return args + + +@pytest.fixture +def patch_base_class(mocker): + # Mock abstract methods to enable instantiating abstract class + mocker.patch.object(ZenefitsStream, "path", "v0/example_endpoint") + mocker.patch.object(ZenefitsStream, "primary_key", "test_primary_key") + mocker.patch.object(ZenefitsStream, "__abstractmethods__", set()) + + +def test_request_params(patch_base_class, config): + stream = ZenefitsStream(**config) + inputs = {"stream_slice": None, "stream_state": None, "next_page_token": None} + expected_params = {"limit": 100} + assert stream.request_params(**inputs) == expected_params + + +def test_next_page_token(patch_base_class, config): + stream = ZenefitsStream(**config) + response = MagicMock() + response.json.return_value = {"data": {"next_url": "https://api.zenefits.com/core/people?limit=100&starting_after=22334422"}} + inputs = {"response": response} + expected_token = {"limit": ["100"], "starting_after": ["22334422"]} + assert stream.next_page_token(**inputs) == expected_token + + +def test_request_headers(patch_base_class, config): + stream = ZenefitsStream(**config) + inputs = {"stream_slice": None, "stream_state": None, "next_page_token": None} + expected_headers = {"Authorization": "Bearer YXNmnhkjf", "Content-Type": "application/json", "Accept": "application/json"} + assert stream.request_headers(**inputs) == expected_headers + + +def test_parse_response(patch_base_class, config): + stream = ZenefitsStream(**config) + response = MagicMock() + response.json.return_value = {"people": [{"id": "123", "name": "John Doe"}]} + inputs = {"response": response, "stream_state": MagicMock()} + expected_parsed_object = [{"id": "123", "name": "John Doe"}] + return stream.parse_response(**inputs) == expected_parsed_object + + +def test_http_method(patch_base_class, config): + stream = ZenefitsStream(**config) + expected_method = "GET" + 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, config): + response_mock = MagicMock() + response_mock.status_code = http_status + stream = ZenefitsStream(**config) + assert stream.should_retry(response_mock) == should_retry + + +def test_backoff_time(patch_base_class, config): + response_mock = MagicMock() + stream = ZenefitsStream(**config) + expected_backoff_time = None + assert stream.backoff_time(response_mock) == expected_backoff_time diff --git a/docs/integrations/sources/zenefits.md b/docs/integrations/sources/zenefits.md new file mode 100644 index 0000000000000..44c7ef69e0d5c --- /dev/null +++ b/docs/integrations/sources/zenefits.md @@ -0,0 +1,56 @@ +# Zenefits + +This page contains the setup guide and reference information for the Zenefits source connector. + +## Prerequisites + +- A Zenefits [token](https://developers.zenefits.com/v1.0/docs/auth) + +## Set up Zenefits as a source in Airbyte + +### For Airbyte OSS + +To set up Zenefits as a source in Airbyte Cloud: + +1. In the left navigation bar, click **Sources**. In the top-right corner, click **+ New source**. +2. On the Set up the source page, select **Zenefits** from the **Source type** dropdown. +3. For Name, enter a name for the Zenefits connector. +4. For **Token**, enter the token you have got from [Authentication](https://developers.zenefits.com/v1.0/docs/auth) +5. Click **Set up source**. + +## Supported sync modes + +The Zenefits source connector supports the following sync modes: + +- [Full Refresh - Overwrite](https://docs.airbyte.com/understanding-airbyte/glossary#full-refresh-sync) + +## Supported Streams + +You can replicate the following tables using the Zenefits connector: + +- [People](https://developers.zenefits.com/docs/people) +- [Employments](https://developers.zenefits.com/docs/employment) +- [Vacation_requests](https://developers.zenefits.com/docs/vacation-requests) +- [Vacation_types](https://developers.zenefits.com/docs/vacation-types) +- [Time_durations](https://developers.zenefits.com/docs/time-durations) +- [Departments](https://developers.zenefits.com/docs/department) +- [Locations](https://developers.zenefits.com/docs/location) +- [Labor_groups](https://developers.zenefits.com/docs/labor-groups) +- [Labor_group_types](https://developers.zenefits.com/docs/labor-group-types) +- [Custom_fields](https://developers.zenefits.com/docs/custom-fields) +- [Custom_field_values](https://developers.zenefits.com/docs/custom-field-values) + +## Data type mapping + +| Integration Type | Airbyte Type | +| :--------------: | :----------: | +| string | string | +| number | number | +| array | array | +| object | object | + +## Changelog + +| Version | Date | Pull Request | Subject | +| :------ | :--------- | :------------------------------------------------------- | :-------------- | +| `0.1.0` | 2022-08-24 | [14809](https://github.com/airbytehq/airbyte/pull/14809) | Initial Release |