Skip to content

Commit bb28fe0

Browse files
authored
Source twitter: Migrate to manifest-only (#44777)
1 parent 5db36ed commit bb28fe0

File tree

15 files changed

+221
-1637
lines changed

15 files changed

+221
-1637
lines changed

airbyte-integrations/connectors/source-twitter/README.md

+27-53
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,63 @@
11
# Twitter source connector
22

3+
This directory contains the manifest-only connector for `source-twitter`.
4+
This _manifest-only_ connector is not a Python package on its own, as it runs inside of the base `source-declarative-manifest` image.
35

4-
This is the repository for the Twitter source connector, written in Python.
5-
For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.com/integrations/sources/twitter).
6+
For information about how to configure and use this connector within Airbyte, see [the connector's full documentation](https://docs.airbyte.com/integrations/sources/twitter).
67

78
## Local development
89

9-
### Prerequisites
10-
* Python (~=3.9)
11-
* Poetry (~=1.7) - installation instructions [here](https://python-poetry.org/docs/#installation)
10+
We recommend using the Connector Builder to edit this connector.
11+
Using either Airbyte Cloud or your local Airbyte OSS instance, navigate to the **Builder** tab and select **Import a YAML**.
12+
Then select the connector's `manifest.yaml` file to load the connector into the Builder. You're now ready to make changes to the connector!
1213

14+
If you prefer to develop locally, you can follow the instructions below.
1315

14-
### Installing the connector
15-
From this connector directory, run:
16-
```bash
17-
poetry install --with dev
18-
```
19-
20-
21-
### Create credentials
22-
**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.com/integrations/sources/twitter)
23-
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_twitter/spec.yaml` file.
24-
Note that any directory named `secrets` is gitignored across the entire Airbyte repo, so there is no danger of accidentally checking in sensitive information.
25-
See `sample_files/sample_config.json` for a sample config file.
26-
27-
28-
### Locally running the connector
29-
```
30-
poetry run source-twitter spec
31-
poetry run source-twitter check --config secrets/config.json
32-
poetry run source-twitter discover --config secrets/config.json
33-
poetry run source-twitter read --config secrets/config.json --catalog sample_files/configured_catalog.json
34-
```
16+
### Building the docker image
3517

36-
### Running unit tests
37-
To run unit tests locally, from the connector directory run:
38-
```
39-
poetry run pytest unit_tests
40-
```
18+
You can build any manifest-only connector with `airbyte-ci`:
4119

42-
### Building the docker image
4320
1. Install [`airbyte-ci`](https://github.com/airbytehq/airbyte/blob/master/airbyte-ci/connectors/pipelines/README.md)
4421
2. Run the following command to build the docker image:
22+
4523
```bash
4624
airbyte-ci connectors --name=source-twitter build
4725
```
4826

4927
An image will be available on your host with the tag `airbyte/source-twitter:dev`.
5028

29+
### Creating credentials
30+
31+
**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.com/integrations/sources/twitter)
32+
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `spec` object in the connector's `manifest.yaml` file.
33+
Note that any directory named `secrets` is gitignored across the entire Airbyte repo, so there is no danger of accidentally checking in sensitive information.
5134

5235
### Running as a docker container
53-
Then run any of the connector commands as follows:
54-
```
36+
37+
Then run any of the standard source connector commands:
38+
39+
```bash
5540
docker run --rm airbyte/source-twitter:dev spec
5641
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-twitter:dev check --config /secrets/config.json
5742
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-twitter:dev discover --config /secrets/config.json
5843
docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-twitter:dev read --config /secrets/config.json --catalog /integration_tests/configured_catalog.json
5944
```
6045

61-
### Running our CI test suite
62-
You can run our full test suite locally using [`airbyte-ci`](https://github.com/airbytehq/airbyte/blob/master/airbyte-ci/connectors/pipelines/README.md):
63-
```bash
64-
airbyte-ci connectors --name=source-twitter test
65-
```
46+
### Running the CI test suite
6647

67-
### Customizing acceptance Tests
68-
Customize `acceptance-test-config.yml` file to configure acceptance tests. See [Connector Acceptance Tests](https://docs.airbyte.com/connector-development/testing-connectors/connector-acceptance-tests-reference) for more information.
69-
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.
48+
You can run our full test suite locally using [`airbyte-ci`](https://github.com/airbytehq/airbyte/blob/master/airbyte-ci/connectors/pipelines/README.md):
7049

71-
### Dependency Management
72-
All of your dependencies should be managed via Poetry.
73-
To add a new dependency, run:
7450
```bash
75-
poetry add <package-name>
51+
airbyte-ci connectors --name=source-twitter test
7652
```
7753

78-
Please commit the changes to `pyproject.toml` and `poetry.lock` files.
79-
8054
## Publishing a new version of the connector
81-
You've checked out the repo, implemented a million dollar feature, and you're ready to share your changes with the world. Now what?
82-
1. Make sure your changes are passing our test suite: `airbyte-ci connectors --name=source-twitter test`
83-
2. Bump the connector version (please follow [semantic versioning for connectors](https://docs.airbyte.com/contributing-to-airbyte/resources/pull-requests-handbook/#semantic-versioning-for-connectors)):
55+
56+
If you want to contribute changes to `source-twitter`, here's how you can do that:
57+
1. Make your changes locally, or load the connector's manifest into Connector Builder and make changes there.
58+
2. Make sure your changes are passing our test suite with `airbyte-ci connectors --name=source-twitter test`
59+
3. Bump the connector version (please follow [semantic versioning for connectors](https://docs.airbyte.com/contributing-to-airbyte/resources/pull-requests-handbook/#semantic-versioning-for-connectors)):
8460
- bump the `dockerImageTag` value in in `metadata.yaml`
85-
- bump the `version` value in `pyproject.toml`
86-
3. Make sure the `metadata.yaml` content is up to date.
8761
4. Make sure the connector documentation and its changelog is up to date (`docs/integrations/sources/twitter.md`).
8862
5. Create a Pull Request: use [our PR naming conventions](https://docs.airbyte.com/contributing-to-airbyte/resources/pull-requests-handbook/#pull-request-title-convention).
8963
6. Pat yourself on the back for being an awesome contributor.

airbyte-integrations/connectors/source-twitter/__init__.py

-3
This file was deleted.

airbyte-integrations/connectors/source-twitter/acceptance-test-config.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ test_strictness_level: "high"
55
acceptance_tests:
66
spec:
77
tests:
8-
- spec_path: "source_twitter/spec.yaml"
8+
- spec_path: "manifest.yaml"
99
connection:
1010
tests:
1111
- config_path: "secrets/config.json"
@@ -19,7 +19,10 @@ acceptance_tests:
1919
tests:
2020
- config_path: "secrets/config.json"
2121
expect_records:
22-
bypass_reason: "Only one stream tweets available. Retrieving tweets cannot be more than 7 days in the past. So need skip for expected records, but not skip for basic read."
22+
bypass_reason:
23+
"Only one stream tweets available. Retrieving tweets cannot
24+
be more than 7 days in the past. So need skip for expected records, but
25+
not skip for basic read."
2326
incremental:
2427
tests:
2528
- config_path: "secrets/config.json"

airbyte-integrations/connectors/source-twitter/main.py

-8
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
version: 4.5.4
2+
3+
type: DeclarativeSource
4+
5+
check:
6+
type: CheckStream
7+
stream_names:
8+
- tweets
9+
10+
definitions:
11+
streams:
12+
tweets:
13+
type: DeclarativeStream
14+
name: tweets
15+
primary_key:
16+
- id
17+
retriever:
18+
type: SimpleRetriever
19+
requester:
20+
$ref: "#/definitions/base_requester"
21+
path: /search/recent
22+
http_method: GET
23+
request_parameters:
24+
query: "{{ config['query'] }}"
25+
tweet.fields: author_id,conversation_id,created_at,in_reply_to_user_id,lang
26+
record_selector:
27+
type: RecordSelector
28+
extractor:
29+
type: DpathExtractor
30+
field_path:
31+
- data
32+
paginator:
33+
type: DefaultPaginator
34+
page_token_option:
35+
type: RequestOption
36+
inject_into: request_parameter
37+
field_name: next_token
38+
page_size_option:
39+
type: RequestOption
40+
field_name: max_results
41+
inject_into: request_parameter
42+
pagination_strategy:
43+
type: CursorPagination
44+
page_size: 100
45+
cursor_value: "{{ response.meta.next_token }}"
46+
stop_condition: "{{ 'next_token' not in response['meta'] }}"
47+
incremental_sync:
48+
type: DatetimeBasedCursor
49+
cursor_field: created_at
50+
cursor_datetime_formats:
51+
- "%Y-%m-%dT%H:%M:%S.000Z"
52+
datetime_format: "%Y-%m-%dT%H:%M:%S.000Z"
53+
start_datetime:
54+
type: MinMaxDatetime
55+
datetime: >-
56+
{{ config.start_date or (now_utc() -
57+
duration('P6DT23H')).strftime('%Y-%m-%dT%H:%M:%SZ') }}
58+
datetime_format: "%Y-%m-%dT%H:%M:%SZ"
59+
start_time_option:
60+
type: RequestOption
61+
field_name: start_time
62+
inject_into: request_parameter
63+
end_time_option:
64+
type: RequestOption
65+
field_name: end_time
66+
inject_into: request_parameter
67+
end_datetime:
68+
type: MinMaxDatetime
69+
datetime: >-
70+
{{ config.end_date or (now_utc() -
71+
duration('PT10S')).strftime('%Y-%m-%dT%H:%M:%SZ') }}
72+
datetime_format: "%Y-%m-%dT%H:%M:%SZ"
73+
step: P7D
74+
cursor_granularity: PT0S
75+
schema_loader:
76+
type: InlineSchemaLoader
77+
schema:
78+
$ref: "#/schemas/tweets"
79+
base_requester:
80+
type: HttpRequester
81+
url_base: https://api.twitter.com/2/tweets
82+
authenticator:
83+
type: BearerAuthenticator
84+
header: apikey
85+
api_token: "{{ config.api_key }}"
86+
87+
streams:
88+
- $ref: "#/definitions/streams/tweets"
89+
90+
spec:
91+
type: Spec
92+
connection_specification:
93+
type: object
94+
$schema: http://json-schema.org/draft-07/schema#
95+
required:
96+
- api_key
97+
- query
98+
properties:
99+
api_key:
100+
type: string
101+
description: >-
102+
App only Bearer Token. See the <a
103+
href="https://developer.twitter.com/en/docs/authentication/oauth-2-0/bearer-tokens">docs</a>
104+
for more information on how to obtain this token.
105+
title: Access Token
106+
airbyte_secret: true
107+
order: 0
108+
query:
109+
type: string
110+
description: >-
111+
Query for matching Tweets. You can learn how to build this query by
112+
reading <a
113+
href="https://developer.twitter.com/en/docs/twitter-api/tweets/search/integrate/build-a-query">
114+
build a query guide </a>.
115+
title: Search Query
116+
order: 1
117+
start_date:
118+
type: string
119+
description: >-
120+
The start date for retrieving tweets cannot be more than 7 days in the
121+
past.
122+
title: Start Date
123+
format: date-time
124+
order: 2
125+
end_date:
126+
type: string
127+
description: >-
128+
The end date for retrieving tweets must be a minimum of 10 seconds
129+
prior to the request time.
130+
title: End Date
131+
format: date-time
132+
order: 3
133+
additionalProperties: true
134+
135+
metadata:
136+
autoImportSchema:
137+
tweets: false
138+
yamlComponents:
139+
global:
140+
- authenticator
141+
testedStreams: {}
142+
assist: {}
143+
144+
schemas:
145+
tweets:
146+
type: object
147+
$schema: http://json-schema.org/draft-07/schema#
148+
properties:
149+
author_id:
150+
type:
151+
- "null"
152+
- string
153+
conversation_id:
154+
type:
155+
- "null"
156+
- string
157+
created_at:
158+
type:
159+
- "null"
160+
- string
161+
format: date-time
162+
edit_history_tweet_ids:
163+
type:
164+
- "null"
165+
- array
166+
items:
167+
type: string
168+
id:
169+
type:
170+
- "null"
171+
- string
172+
in_reply_to_user_id:
173+
type:
174+
- "null"
175+
- string
176+
lang:
177+
type:
178+
- "null"
179+
- string
180+
text:
181+
type:
182+
- "null"
183+
- string
184+
additionalProperties: true

airbyte-integrations/connectors/source-twitter/metadata.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ data:
88
connectorSubtype: api
99
connectorType: source
1010
definitionId: d7fd4f40-5e5a-4b8b-918f-a73077f8c131
11-
dockerImageTag: 0.1.15
11+
dockerImageTag: 0.2.0
1212
dockerRepository: airbyte/source-twitter
1313
documentationUrl: https://docs.airbyte.com/integrations/sources/twitter
1414
githubIssueLabel: source-twitter
@@ -17,7 +17,7 @@ data:
1717
name: Twitter
1818
remoteRegistries:
1919
pypi:
20-
enabled: true
20+
enabled: false
2121
packageName: airbyte-source-twitter
2222
registryOverrides:
2323
cloud:
@@ -27,8 +27,8 @@ data:
2727
releaseStage: beta
2828
supportLevel: community
2929
tags:
30-
- language:python
3130
- cdk:low-code
31+
- language:manifest-only
3232
connectorTestSuitesOptions:
3333
- suite: liveTests
3434
testConnections:
@@ -42,5 +42,5 @@ data:
4242
type: GSM
4343
alias: airbyte-connector-testing-secret-store
4444
connectorBuildOptions:
45-
baseImage: docker.io/airbyte/python-connector-base:2.0.0@sha256:c44839ba84406116e8ba68722a0f30e8f6e7056c726f447681bb9e9ece8bd916
45+
baseImage: docker.io/airbyte/source-declarative-manifest:4.5.4@sha256:b07a521add11f987c63c0db68c1b57e90bec0c985f1cb6f3c5a1940cde628a70
4646
metadataSpecVersion: "1.0"

0 commit comments

Comments
 (0)