Skip to content

Commit 1421ba7

Browse files
marcosmarxmHarshil0512octavia-squidington-iii
authored
New Connector Polygon (#19504)
* Weather API CDK Added * Polygon-Stocks-API CDK Added Polygon-Stocks-API is the API provided by https://polygon.io/ to get details about the stock * spec.yaml updated * Files Changes Resolved * Review Changes Are Performed * Some Requested Changes Are Done Add title to your parameters is done Change from to start_date and to to end_date is done * correct schema * add polygon to source def * run format * correct primary key * auto-bump connector version Co-authored-by: Harshil Khamar <[email protected]> Co-authored-by: Harshil Khamar <[email protected]> Co-authored-by: Octavia Squidington III <[email protected]>
1 parent a968078 commit 1421ba7

File tree

25 files changed

+635
-0
lines changed

25 files changed

+635
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,13 @@
11671167
icon: pokeapi.svg
11681168
sourceType: api
11691169
releaseStage: alpha
1170+
- name: Polygon Stock API
1171+
sourceDefinitionId: 5807d72f-0abc-49f9-8fa5-ae820007032b
1172+
dockerRepository: airbyte/source-polygon-stock-api
1173+
dockerImageTag: 0.1.0
1174+
documentationUrl: https://docs.airbyte.com/integrations/sources/polygon-stock-api
1175+
sourceType: api
1176+
releaseStage: alpha
11701177
- name: PostHog
11711178
sourceDefinitionId: af6d50ee-dddf-4126-a8ee-7faee990774f
11721179
dockerRepository: airbyte/source-posthog

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10838,6 +10838,89 @@
1083810838
supportsNormalization: false
1083910839
supportsDBT: false
1084010840
supported_destination_sync_modes: []
10841+
- dockerImage: "airbyte/source-polygon-stock-api:0.1.0"
10842+
spec:
10843+
documentationUrl: "https://docs.airbyte.com/integrations/sources/airtable"
10844+
connectionSpecification:
10845+
$schema: "http://json-schema.org/draft-07/schema#"
10846+
title: "Weather API Spec"
10847+
type: "object"
10848+
required:
10849+
- "apiKey"
10850+
- "stocksTicker"
10851+
- "multiplier"
10852+
- "timespan"
10853+
- "start_date"
10854+
- "end_date"
10855+
additionalProperties: true
10856+
properties:
10857+
apiKey:
10858+
title: "API Key"
10859+
type: "string"
10860+
description: "Your API ACCESS Key"
10861+
airbyte_secret: true
10862+
stocksTicker:
10863+
title: "Stock Ticker"
10864+
type: "string"
10865+
description: "The exchange symbol that this item is traded under."
10866+
examples:
10867+
- "IBM"
10868+
- "MSFT"
10869+
multiplier:
10870+
title: "Multiplier"
10871+
type: "integer"
10872+
description: "The size of the timespan multiplier."
10873+
examples:
10874+
- 1
10875+
- 2
10876+
timespan:
10877+
title: "Timespan"
10878+
type: "string"
10879+
description: "The size of the time window."
10880+
examples:
10881+
- "day"
10882+
start_date:
10883+
title: "Start Date"
10884+
type: "string"
10885+
pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
10886+
description: "The beginning date for the aggregate window."
10887+
examples:
10888+
- "2020-10-14"
10889+
end_date:
10890+
title: "End Date"
10891+
type: "string"
10892+
pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
10893+
description: "The target date for the aggregate window."
10894+
examples:
10895+
- "2020-10-14"
10896+
adjusted:
10897+
title: "Adjusted"
10898+
type: "string"
10899+
description: "Determines whether or not the results are adjusted for splits.\
10900+
\ By default, results are adjusted and set to true. Set this to false\
10901+
\ to get results that are NOT adjusted for splits."
10902+
examples:
10903+
- "true"
10904+
- "false"
10905+
sort:
10906+
title: "Sort"
10907+
type: "string"
10908+
description: "Sort the results by timestamp. asc will return results in\
10909+
\ ascending order (oldest at the top), desc will return results in descending\
10910+
\ order (newest at the top)."
10911+
examples:
10912+
- "asc"
10913+
- "desc"
10914+
limit:
10915+
title: "Limit"
10916+
type: "integer"
10917+
description: "The target date for the aggregate window."
10918+
examples:
10919+
- 100
10920+
- 120
10921+
supportsNormalization: false
10922+
supportsDBT: false
10923+
supported_destination_sync_modes: []
1084110924
- dockerImage: "airbyte/source-posthog:0.1.7"
1084210925
spec:
1084310926
documentationUrl: "https://docs.airbyte.com/integrations/sources/posthog"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*
2+
!Dockerfile
3+
!main.py
4+
!source_polygon_stock_api
5+
!setup.py
6+
!secrets
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
FROM python:3.9.11-alpine3.15 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_polygon_stock_api ./source_polygon_stock_api
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-polygon-stock-api
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Polygon Stock Api Source
2+
3+
This is the repository for the Polygon Stock Api configuration based source connector.
4+
For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.io/integrations/sources/polygon-stock-api).
5+
6+
## Local development
7+
8+
#### Building via Gradle
9+
You can also build the connector in Gradle. This is typically used in CI and not needed for your development workflow.
10+
11+
To build using Gradle, from the Airbyte repository root, run:
12+
```
13+
./gradlew :airbyte-integrations:connectors:source-polygon-stock-api:build
14+
```
15+
16+
#### Create credentials
17+
**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.io/integrations/sources/polygon-stock-api)
18+
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_polygon_stock_api/spec.yaml` file.
19+
Note that any directory named `secrets` is gitignored across the entire Airbyte repo, so there is no danger of accidentally checking in sensitive information.
20+
See `integration_tests/sample_config.json` for a sample config file.
21+
22+
**If you are an Airbyte core member**, copy the credentials in Lastpass under the secret name `source polygon-stock-api test creds`
23+
and place them into `secrets/config.json`.
24+
25+
### Locally running the connector docker image
26+
27+
#### Build
28+
First, make sure you build the latest Docker image:
29+
```
30+
docker build . -t airbyte/source-polygon-stock-api:dev
31+
```
32+
33+
You can also build the connector image via Gradle:
34+
```
35+
./gradlew :airbyte-integrations:connectors:source-polygon-stock-api:airbyteDocker
36+
```
37+
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
38+
the Dockerfile.
39+
40+
#### Run
41+
Then run any of the connector commands as follows:
42+
```
43+
docker run --rm airbyte/source-polygon-stock-api:dev spec
44+
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-polygon-stock-api:dev check --config /secrets/config.json
45+
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-polygon-stock-api:dev discover --config /secrets/config.json
46+
docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-polygon-stock-api:dev read --config /secrets/config.json --catalog /integration_tests/configured_catalog.json
47+
```
48+
## Testing
49+
50+
#### Acceptance Tests
51+
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.
52+
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.
53+
54+
To run your integration tests with docker
55+
56+
### Using gradle to run tests
57+
All commands should be run from airbyte project root.
58+
To run unit tests:
59+
```
60+
./gradlew :airbyte-integrations:connectors:source-polygon-stock-api:unitTest
61+
```
62+
To run acceptance and custom integration tests:
63+
```
64+
./gradlew :airbyte-integrations:connectors:source-polygon-stock-api:integrationTest
65+
```
66+
67+
## Dependency Management
68+
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.
69+
We split dependencies between two groups, dependencies that are:
70+
* required for your connector to work need to go to `MAIN_REQUIREMENTS` list.
71+
* required for the testing need to go to `TEST_REQUIREMENTS` list
72+
73+
### Publishing a new version of the connector
74+
You've checked out the repo, implemented a million dollar feature, and you're ready to share your changes with the world. Now what?
75+
1. Make sure your changes are passing unit and integration tests.
76+
1. Bump the connector version in `Dockerfile` -- just increment the value of the `LABEL io.airbyte.version` appropriately (we use [SemVer](https://semver.org/)).
77+
1. Create a Pull Request.
78+
1. Pat yourself on the back for being an awesome contributor.
79+
1. Someone from Airbyte will take a look at your PR and iterate with you to merge it into master.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#
2+
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
3+
#
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# See [Source Acceptance Tests](https://docs.airbyte.com/connector-development/testing-connectors/source-acceptance-tests-reference)
2+
# for more information about how to configure these tests
3+
connector_image: airbyte/source-polygon-stock-api:dev
4+
acceptance_tests:
5+
spec:
6+
tests:
7+
- spec_path: "source_polygon_stock_api/spec.yaml"
8+
connection:
9+
tests:
10+
- config_path: "secrets/config.json"
11+
status: "succeed"
12+
- config_path: "integration_tests/invalid_config.json"
13+
status: "failed"
14+
discovery:
15+
tests:
16+
- config_path: "secrets/config.json"
17+
basic_read:
18+
tests:
19+
- config_path: "secrets/config.json"
20+
configured_catalog_path: "integration_tests/configured_catalog.json"
21+
empty_streams: []
22+
# TODO uncomment this block to specify that the tests should assert the connector outputs the records provided in the input file a file
23+
# expect_records:
24+
# path: "integration_tests/expected_records.txt"
25+
# extra_fields: no
26+
# exact_order: no
27+
# extra_records: yes
28+
incremental:
29+
bypass_reason: "This connector does not implement incremental sync"
30+
# TODO uncomment this block this block if your connector implements incremental sync:
31+
# tests:
32+
# - config_path: "secrets/config.json"
33+
# configured_catalog_path: "integration_tests/configured_catalog.json"
34+
# future_state_path: "integration_tests/abnormal_state.json"
35+
full_refresh:
36+
tests:
37+
- config_path: "secrets/config.json"
38+
configured_catalog_path: "integration_tests/configured_catalog.json"
Lines changed: 16 additions & 0 deletions
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+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
plugins {
2+
id 'airbyte-python'
3+
id 'airbyte-docker'
4+
id 'airbyte-source-acceptance-test'
5+
}
6+
7+
airbytePython {
8+
moduleDirectory 'source_polygon_stock_api'
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#
2+
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
3+
#
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"ticker": "microsoft",
3+
"queryCount": 0,
4+
"resultsCount": 0,
5+
"adjusted": true,
6+
"status": "OK",
7+
"request_id": "2c243c1c9bc396cad059cd18253f3ab2"
8+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Copyright (c) 2022 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+
"""This fixture is a placeholder for external resources that acceptance test might require."""
14+
# TODO: setup test dependencies if needed. otherwise remove the TODO comments
15+
yield
16+
# TODO: clean up test dependencies
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"streams": [
3+
{
4+
"stream": {
5+
"name": "stock_api",
6+
"json_schema": {},
7+
"supported_sync_modes": ["full_refresh"]
8+
},
9+
"sync_mode": "full_refresh",
10+
"destination_sync_mode": "overwrite"
11+
}
12+
]
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"apiKey": "INVALID_API_KEY",
3+
"limit": "120",
4+
"sort": "asc",
5+
"adjusted": "true",
6+
"stocksTicker": "MSFT",
7+
"multiplier": "1",
8+
"timespan": "day",
9+
"start_date": "2021-07-22",
10+
"end_date": "2021-07-22"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"apiKey": "YOUR API KEY",
3+
"limit": "120",
4+
"sort": "asc",
5+
"adjusted": "true",
6+
"stocksTicker": "AAPL",
7+
"multiplier": "1",
8+
"timespan": "day",
9+
"start_date": "2021-07-22",
10+
"end_date": "2021-07-22"
11+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"ticker": "AAPL",
3+
"queryCount": 1,
4+
"resultsCount": 1,
5+
"adjusted": true,
6+
"results": [
7+
{
8+
"v": 77287356,
9+
"vw": 146.991,
10+
"o": 145.935,
11+
"c": 146.8,
12+
"h": 148.195,
13+
"l": 145.81,
14+
"t": 1626926400000,
15+
"n": 480209
16+
}
17+
],
18+
"status": "OK",
19+
"request_id": "6aae8b7d3d4d2cd896085a840d2e3ed1",
20+
"count": 1
21+
}

0 commit comments

Comments
 (0)