Skip to content

Commit 1bc0868

Browse files
lazebnyisherifnada
authored andcommitted
🎉 New Source: Pinterest (airbytehq#7493)
* Add Pinterest implementation * Updated to review * Added rate limits and PR number to doc * Fixed unit tests and data slicing bug * Update airbyte-integrations/connectors/source-pinterest/source_pinterest/spec.json Co-authored-by: Sherif A. Nada <snadalive@gmail.com> * Update airbyte-integrations/connectors/source-pinterest/build.gradle Co-authored-by: Sherif A. Nada <snadalive@gmail.com> * Update airbyte-integrations/connectors/source-pinterest/source_pinterest/spec.json Co-authored-by: Sherif A. Nada <snadalive@gmail.com> * Updated to review * Updated window in days * Fixed unit test Co-authored-by: Sherif A. Nada <snadalive@gmail.com>
1 parent 77c2446 commit 1bc0868

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2934
-0
lines changed

.github/workflows/publish-command.yml

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ jobs:
131131
MIXPANEL_INTEGRATION_TEST_CREDS: ${{ secrets.MIXPANEL_INTEGRATION_TEST_CREDS }}
132132
MSSQL_RDS_TEST_CREDS: ${{ secrets.MSSQL_RDS_TEST_CREDS }}
133133
PAYPAL_TRANSACTION_CREDS: ${{ secrets.SOURCE_PAYPAL_TRANSACTION_CREDS }}
134+
PINTEREST_TEST_CREDS: ${{ secrets.PINTEREST_TEST_CREDS }}
134135
POSTGRES_SSH_KEY_TEST_CREDS: ${{ secrets.POSTGRES_SSH_KEY_TEST_CREDS }}
135136
POSTGRES_SSH_PWD_TEST_CREDS: ${{ secrets.POSTGRES_SSH_PWD_TEST_CREDS }}
136137
MYSQL_SSH_KEY_TEST_CREDS: ${{ secrets.MYSQL_SSH_KEY_TEST_CREDS }}

.github/workflows/test-command.yml

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ jobs:
127127
MIXPANEL_INTEGRATION_TEST_CREDS: ${{ secrets.MIXPANEL_INTEGRATION_TEST_CREDS }}
128128
MSSQL_RDS_TEST_CREDS: ${{ secrets.MSSQL_RDS_TEST_CREDS }}
129129
PAYPAL_TRANSACTION_CREDS: ${{ secrets.SOURCE_PAYPAL_TRANSACTION_CREDS }}
130+
PINTEREST_TEST_CREDS: ${{ secrets.PINTEREST_TEST_CREDS }}
130131
POSTGRES_SSH_KEY_TEST_CREDS: ${{ secrets.POSTGRES_SSH_KEY_TEST_CREDS }}
131132
POSTGRES_SSH_PWD_TEST_CREDS: ${{ secrets.POSTGRES_SSH_PWD_TEST_CREDS }}
132133
MYSQL_SSH_KEY_TEST_CREDS: ${{ secrets.MYSQL_SSH_KEY_TEST_CREDS }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"sourceDefinitionId": "5cb7e5fe-38c2-11ec-8d3d-0242ac130003",
3+
"name": "Pinterest",
4+
"dockerRepository": "airbyte/source-pinterest",
5+
"dockerImageTag": "0.1.0",
6+
"documentationUrl": "https://docs.airbyte.io/integrations/sources/pinterest"
7+
}

airbyte-config/init/src/main/resources/seed/source_definitions.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,12 @@
395395
documentationUrl: https://docs.airbyte.io/integrations/sources/paystack
396396
icon: paystack.svg
397397
sourceType: api
398+
- name: Pinterest
399+
sourceDefinitionId: 5cb7e5fe-38c2-11ec-8d3d-0242ac130003
400+
dockerRepository: airbyte/source-pinterest
401+
dockerImageTag: 0.1.0
402+
documentationUrl: https://docs.airbyte.io/integrations/sources/pinterest
403+
sourceType: api
398404
- name: Pipedrive
399405
sourceDefinitionId: d8286229-c680-4063-8c59-23b9b391c700
400406
dockerRepository: airbyte/source-pipedrive
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*
2+
!Dockerfile
3+
!Dockerfile.test
4+
!main.py
5+
!source_pinterest
6+
!setup.py
7+
!secrets
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
FROM python:3.7.11-alpine3.14 as base
2+
3+
# build and load all requirements
4+
FROM base as builder
5+
WORKDIR /airbyte/integration_code
6+
7+
# upgrade pip to the latest version
8+
RUN apk --no-cache upgrade \
9+
&& pip install --upgrade pip \
10+
&& apk --no-cache add tzdata build-base
11+
12+
13+
COPY setup.py ./
14+
# install necessary packages to a temporary folder
15+
RUN pip install --prefix=/install .
16+
17+
# build a clean environment
18+
FROM base
19+
WORKDIR /airbyte/integration_code
20+
21+
# copy all loaded and built libraries to a pure basic image
22+
COPY --from=builder /install /usr/local
23+
# add default timezone settings
24+
COPY --from=builder /usr/share/zoneinfo/Etc/UTC /etc/localtime
25+
RUN echo "Etc/UTC" > /etc/timezone
26+
27+
# bash is installed for more convenient debugging.
28+
RUN apk --no-cache add bash
29+
30+
# copy payload code only
31+
COPY main.py ./
32+
COPY source_pinterest ./source_pinterest
33+
34+
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
35+
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
36+
37+
LABEL io.airbyte.version=0.1.0
38+
LABEL io.airbyte.name=airbyte/source-pinterest
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Pinterest Source
2+
3+
This is the repository for the Pinterest source connector, written in Python.
4+
For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.io/integrations/sources/pinterest).
5+
6+
## Local development
7+
8+
### Prerequisites
9+
**To iterate on this connector, make sure to complete this prerequisites section.**
10+
11+
#### Minimum Python version required `= 3.7.0`
12+
13+
#### Build & Activate Virtual Environment and install dependencies
14+
From this connector directory, create a virtual environment:
15+
```
16+
python -m venv .venv
17+
```
18+
19+
This will generate a virtualenv for this module in `.venv/`. Make sure this venv is active in your
20+
development environment of choice. To activate it from the terminal, run:
21+
```
22+
source .venv/bin/activate
23+
pip install -r requirements.txt
24+
pip install '.[tests]'
25+
```
26+
If you are in an IDE, follow your IDE's instructions to activate the virtualenv.
27+
28+
Note that while we are installing dependencies from `requirements.txt`, you should only edit `setup.py` for your dependencies. `requirements.txt` is
29+
used for editable installs (`pip install -e`) to pull in Python dependencies from the monorepo and will call `setup.py`.
30+
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
31+
should work as you expect.
32+
33+
#### Building via Gradle
34+
You can also build the connector in Gradle. This is typically used in CI and not needed for your development workflow.
35+
36+
To build using Gradle, from the Airbyte repository root, run:
37+
```
38+
./gradlew :airbyte-integrations:connectors:source-pinterest:build
39+
```
40+
41+
#### Create credentials
42+
**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.io/integrations/sources/pinterest)
43+
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_pinterest/spec.json` file.
44+
Note that any directory named `secrets` is gitignored across the entire Airbyte repo, so there is no danger of accidentally checking in sensitive information.
45+
See `integration_tests/sample_config.json` for a sample config file.
46+
47+
**If you are an Airbyte core member**, copy the credentials in Lastpass under the secret name `source pinterest test creds`
48+
and place them into `secrets/config.json`.
49+
50+
### Locally running the connector
51+
```
52+
python main.py spec
53+
python main.py check --config secrets/config.json
54+
python main.py discover --config secrets/config.json
55+
python main.py read --config secrets/config.json --catalog integration_tests/configured_catalog.json
56+
```
57+
58+
### Locally running the connector docker image
59+
60+
#### Build
61+
First, make sure you build the latest Docker image:
62+
```
63+
docker build . -t airbyte/source-pinterest:dev
64+
```
65+
66+
You can also build the connector image via Gradle:
67+
```
68+
./gradlew :airbyte-integrations:connectors:source-pinterest:airbyteDocker
69+
```
70+
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
71+
the Dockerfile.
72+
73+
#### Run
74+
Then run any of the connector commands as follows:
75+
```
76+
docker run --rm airbyte/source-pinterest:dev spec
77+
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-pinterest:dev check --config /secrets/config.json
78+
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-pinterest:dev discover --config /secrets/config.json
79+
docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-pinterest:dev read --config /secrets/config.json --catalog /integration_tests/configured_catalog.json
80+
```
81+
## Testing
82+
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.
83+
First install test dependencies into your virtual environment:
84+
```
85+
pip install .[tests]
86+
```
87+
### Unit Tests
88+
To run unit tests locally, from the connector directory run:
89+
```
90+
python -m pytest unit_tests
91+
```
92+
93+
### Integration Tests
94+
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).
95+
#### Custom Integration tests
96+
Place custom tests inside `integration_tests/` folder, then, from the connector root, run
97+
```
98+
python -m pytest integration_tests
99+
```
100+
#### Acceptance Tests
101+
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.
102+
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.
103+
To run your integration tests with acceptance tests, from the connector root, run
104+
```
105+
python -m pytest integration_tests -p integration_tests.acceptance
106+
```
107+
To run your integration tests with docker
108+
109+
### Using gradle to run tests
110+
All commands should be run from airbyte project root.
111+
To run unit tests:
112+
```
113+
./gradlew :airbyte-integrations:connectors:source-pinterest:unitTest
114+
```
115+
To run acceptance and custom integration tests:
116+
```
117+
./gradlew :airbyte-integrations:connectors:source-pinterest:integrationTest
118+
```
119+
120+
## Dependency Management
121+
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.
122+
We split dependencies between two groups, dependencies that are:
123+
* required for your connector to work need to go to `MAIN_REQUIREMENTS` list.
124+
* required for the testing need to go to `TEST_REQUIREMENTS` list
125+
126+
### Publishing a new version of the connector
127+
You've checked out the repo, implemented a million dollar feature, and you're ready to share your changes with the world. Now what?
128+
1. Make sure your changes are passing unit and integration tests.
129+
1. Bump the connector version in `Dockerfile` -- just increment the value of the `LABEL io.airbyte.version` appropriately (we use [SemVer](https://semver.org/)).
130+
1. Create a Pull Request.
131+
1. Pat yourself on the back for being an awesome contributor.
132+
1. Someone from Airbyte will take a look at your PR and iterate with you to merge it into master.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See [Source Acceptance Tests](https://docs.airbyte.io/connector-development/testing-connectors/source-acceptance-tests-reference)
2+
# for more information about how to configure these tests
3+
connector_image: airbyte/source-pinterest:dev
4+
tests:
5+
spec:
6+
- spec_path: "source_pinterest/spec.json"
7+
connection:
8+
- config_path: "secrets/config.json"
9+
status: "succeed"
10+
- config_path: "integration_tests/invalid_config.json"
11+
status: "failed"
12+
discovery:
13+
- config_path: "secrets/config.json"
14+
basic_read:
15+
- config_path: "secrets/config.json"
16+
configured_catalog_path: "integration_tests/configured_catalog.json"
17+
empty_streams: []
18+
incremental:
19+
- config_path: "secrets/config.json"
20+
configured_catalog_path: "integration_tests/configured_catalog.json"
21+
full_refresh:
22+
- config_path: "secrets/config.json"
23+
configured_catalog_path: "integration_tests/configured_catalog.json"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env sh
2+
3+
# Build latest connector image
4+
docker build . -t $(cat acceptance-test-config.yml | grep "connector_image" | head -n 1 | cut -d: -f2)
5+
6+
# Pull latest acctest image
7+
docker pull airbyte/source-acceptance-test:latest
8+
9+
# Run
10+
docker run --rm -it \
11+
-v /var/run/docker.sock:/var/run/docker.sock \
12+
-v /tmp:/tmp \
13+
-v $(pwd):/test_input \
14+
airbyte/source-acceptance-test \
15+
--acceptance-test-config /test_input
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## Core streams
2+
3+
Pinterest is a REST based API. Connector is implemented with [Airbyte CDK](https://docs.airbyte.io/connector-development/cdk-python).
4+
5+
Connector has such core streams:
6+
7+
* [Account analytics](https://developers.pinterest.com/docs/api/v5/#operation/user_account/analytics) \(Incremental\)
8+
* [Boards](https://developers.pinterest.com/docs/api/v5/#operation/boards/list) \(Full table\)
9+
* [Board sections](https://developers.pinterest.com/docs/api/v5/#operation/board_sections/list) \(Full table\)
10+
* [Pins on board section](https://developers.pinterest.com/docs/api/v5/#operation/board_sections/list_pins) \(Full table\)
11+
* [Pins on board](https://developers.pinterest.com/docs/api/v5/#operation/boards/list_pins) \(Full table\)
12+
* [Ad accounts](https://developers.pinterest.com/docs/api/v5/#operation/ad_accounts/list) \(Full table\)
13+
* [Ad account analytics](https://developers.pinterest.com/docs/api/v5/#operation/ad_account/analytics) \(Incremental\)
14+
* [Campaigns](https://developers.pinterest.com/docs/api/v5/#operation/campaigns/list) \(Incremental\)
15+
* [Campaign analytics](https://developers.pinterest.com/docs/api/v5/#operation/campaigns/list) \(Incremental\)
16+
* [Ad groups](https://developers.pinterest.com/docs/api/v5/#operation/ad_groups/list) \(Incremental\)
17+
* [Ad group analytics](https://developers.pinterest.com/docs/api/v5/#operation/ad_groups/analytics) \(Incremental\)
18+
* [Ads](https://developers.pinterest.com/docs/api/v5/#operation/ads/list) \(Incremental\)
19+
* [Ad analytics](https://developers.pinterest.com/docs/api/v5/#operation/ads/analytics) \(Incremental\)
20+
21+
22+
Connector uses `start_date` config for initial reports sync depend on connector and current date as an end data.
23+
24+
Connector has `window_in_days` config which allows set the amount of days for each data-chunk begining from start_date. Default: 30 days. Max: 30 days.
25+
26+
See [this](https://docs.airbyte.io/integrations/sources/pinterest) link for the nuances about the connector.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
plugins {
2+
id 'airbyte-python'
3+
id 'airbyte-docker'
4+
id 'airbyte-source-acceptance-test'
5+
}
6+
7+
airbytePython {
8+
moduleDirectory 'source_pinterest'
9+
}
10+
11+
dependencies {
12+
implementation files(project(':airbyte-integrations:bases:source-acceptance-test').airbyteDocker.outputs)
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#
2+
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
3+
#
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"user_account_analytics": {
3+
"date": "3021-06-09"
4+
},
5+
"ad_account_analytics": {
6+
"DATE": "3021-06-09"
7+
},
8+
"campaigns": {
9+
"updated_time": 9628867244
10+
},
11+
"ad_groups": {
12+
"updated_time": 9628867244
13+
},
14+
"ads": {
15+
"updated_time": 9628867244
16+
},
17+
"campaign_analytics": {
18+
"DATE": "3021-06-09"
19+
},
20+
"ad_group_analytics": {
21+
"DATE": "3021-06-09"
22+
},
23+
"ad_analytics": {
24+
"DATE": "3021-06-09"
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
3+
#
4+
5+
6+
import pytest
7+
8+
pytest_plugins = ("source_acceptance_test.plugin",)
9+
10+
11+
@pytest.fixture(scope="session", autouse=True)
12+
def connector_setup():
13+
yield

0 commit comments

Comments
 (0)