Skip to content

Commit

Permalink
🎉 New Source: GNews [low-code CDK] (#18808)
Browse files Browse the repository at this point in the history
* Initial GNews source connector implementation

* Update changelog with PR id

* Add support for incremental syncs and error handling

* Make tests pass

* run format

* auto-bump connector version

Co-authored-by: marcosmarxm <marcosmarxm@gmail.com>
Co-authored-by: Octavia Squidington III <octavia-squidington-iii@users.noreply.github.com>
Co-authored-by: Marcos Marx <marcosmarxm@users.noreply.github.com>
  • Loading branch information
4 people authored Nov 9, 2022
1 parent 233dfd1 commit 88d743b
Show file tree
Hide file tree
Showing 29 changed files with 1,040 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,13 @@
icon: glassfrog.svg
sourceType: api
releaseStage: alpha
- name: GNews
sourceDefinitionId: ce38aec4-5a77-439a-be29-9ca44fd4e811
dockerRepository: airbyte/source-gnews
dockerImageTag: 0.1.0
documentationUrl: https://docs.airbyte.com/integrations/sources/gnews
sourceType: api
releaseStage: alpha
- name: GoCardless
sourceDefinitionId: ba15ac82-5c6a-4fb2-bf24-925c23a1180c
dockerRepository: airbyte/source-gocardless
Expand Down
229 changes: 229 additions & 0 deletions airbyte-config/init/src/main/resources/seed/source_specs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4271,6 +4271,235 @@
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
- dockerImage: "airbyte/source-gnews:0.1.0"
spec:
documentationUrl: "https://docs.airbyte.com/integrations/sources/gnews"
connectionSpecification:
$schema: "http://json-schema.org/draft-07/schema#"
title: "Gnews Spec"
type: "object"
required:
- "api_key"
- "query"
additionalProperties: true
properties:
api_key:
type: "string"
title: "API Key"
description: "API Key"
order: 0
airbyte_secret: true
query:
type: "string"
order: 1
title: "Query"
description: "This parameter allows you to specify your search keywords\
\ to find the news articles you are looking for. The keywords will be\
\ used to return the most relevant articles. It is possible to use logical\
\ operators with keywords. - Phrase Search Operator: This operator allows\
\ you to make an exact search. Keywords surrounded by \n quotation marks\
\ are used to search for articles with the exact same keyword sequence.\
\ \n For example the query: \"Apple iPhone\" will return articles matching\
\ at least once this sequence of keywords.\n- Logical AND Operator: This\
\ operator allows you to make sure that several keywords are all used\
\ in the article\n search. By default the space character acts as an\
\ AND operator, it is possible to replace the space character \n by AND\
\ to obtain the same result. For example the query: Apple Microsoft is\
\ equivalent to Apple AND Microsoft\n- Logical OR Operator: This operator\
\ allows you to retrieve articles matching the keyword a or the keyword\
\ b.\n It is important to note that this operator has a higher precedence\
\ than the AND operator. For example the \n query: Apple OR Microsoft\
\ will return all articles matching the keyword Apple as well as all articles\
\ matching \n the keyword Microsoft\n- Logical NOT Operator: This operator\
\ allows you to remove from the results the articles corresponding to\
\ the\n specified keywords. To use it, you need to add NOT in front of\
\ each word or phrase surrounded by quotes.\n For example the query:\
\ Apple NOT iPhone will return all articles matching the keyword Apple\
\ but not the keyword\n iPhone"
examples:
- "Microsoft Windows 10"
- "Apple OR Microsoft"
- "Apple AND NOT iPhone"
- "(Windows 7) AND (Windows 10)"
- "Intel AND (i7 OR i9)"
language:
type: "string"
title: "Language"
decription: "This parameter allows you to specify the language of the news\
\ articles returned by the API. You have to set as value the 2 letters\
\ code of the language you want to filter."
order: 2
enum:
- "ar"
- "zh"
- "nl"
- "en"
- "fr"
- "de"
- "el"
- "he"
- "hi"
- "it"
- "ja"
- "ml"
- "mr"
- "no"
- "pt"
- "ro"
- "ru"
- "es"
- "sv"
- "ta"
- "te"
- "uk"
country:
type: "string"
title: "Country"
description: "This parameter allows you to specify the country where the\
\ news articles returned by the API were published, the contents of the\
\ articles are not necessarily related to the specified country. You have\
\ to set as value the 2 letters code of the country you want to filter."
order: 3
enum:
- "au"
- "br"
- "ca"
- "cn"
- "eg"
- "fr"
- "de"
- "gr"
- "hk"
- "in"
- "ie"
- "il"
- "it"
- "jp"
- "nl"
- "no"
- "pk"
- "pe"
- "ph"
- "pt"
- "ro"
- "ru"
- "sg"
- "es"
- "se"
- "ch"
- "tw"
- "ua"
- "gb"
- "us"
in:
type: "array"
title: "In"
description: "This parameter allows you to choose in which attributes the\
\ keywords are searched. The attributes that can be set are title, description\
\ and content. It is possible to combine several attributes."
order: 4
items:
type: "string"
enum:
- "title"
- "description"
- "content"
nullable:
type: "array"
title: "Nullable"
description: "This parameter allows you to specify the attributes that you\
\ allow to return null values. The attributes that can be set are title,\
\ description and content. It is possible to combine several attributes"
order: 5
items:
type: "string"
enum:
- "title"
- "description"
- "content"
start_date:
type: "string"
title: "Start Date"
description: "This parameter allows you to filter the articles that have\
\ a publication date greater than or equal to the specified value. The\
\ date must respect the following format: YYYY-MM-DD hh:mm:ss (in UTC)"
order: 6
pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$"
examples:
- "2022-08-21 16:27:09"
end_date:
type: "string"
title: "End Date"
description: "This parameter allows you to filter the articles that have\
\ a publication date smaller than or equal to the specified value. The\
\ date must respect the following format: YYYY-MM-DD hh:mm:ss (in UTC)"
order: 6
pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$"
examples:
- "2022-08-21 16:27:09"
sortby:
type: "string"
title: "Sort By"
description: "This parameter allows you to choose with which type of sorting\
\ the articles should be returned. Two values are possible:\n - publishedAt\
\ = sort by publication date, the articles with the most recent publication\
\ date are returned first\n - relevance = sort by best match to keywords,\
\ the articles with the best match are returned first"
order: 7
enum:
- "publishedAt"
- "relevance"
top_headlines_query:
type: "string"
order: 8
title: "Top Headlines Query"
description: "This parameter allows you to specify your search keywords\
\ to find the news articles you are looking for. The keywords will be\
\ used to return the most relevant articles. It is possible to use logical\
\ operators with keywords. - Phrase Search Operator: This operator allows\
\ you to make an exact search. Keywords surrounded by \n quotation marks\
\ are used to search for articles with the exact same keyword sequence.\
\ \n For example the query: \"Apple iPhone\" will return articles matching\
\ at least once this sequence of keywords.\n- Logical AND Operator: This\
\ operator allows you to make sure that several keywords are all used\
\ in the article\n search. By default the space character acts as an\
\ AND operator, it is possible to replace the space character \n by AND\
\ to obtain the same result. For example the query: Apple Microsoft is\
\ equivalent to Apple AND Microsoft\n- Logical OR Operator: This operator\
\ allows you to retrieve articles matching the keyword a or the keyword\
\ b.\n It is important to note that this operator has a higher precedence\
\ than the AND operator. For example the \n query: Apple OR Microsoft\
\ will return all articles matching the keyword Apple as well as all articles\
\ matching \n the keyword Microsoft\n- Logical NOT Operator: This operator\
\ allows you to remove from the results the articles corresponding to\
\ the\n specified keywords. To use it, you need to add NOT in front of\
\ each word or phrase surrounded by quotes.\n For example the query:\
\ Apple NOT iPhone will return all articles matching the keyword Apple\
\ but not the keyword\n iPhone"
examples:
- "Microsoft Windows 10"
- "Apple OR Microsoft"
- "Apple AND NOT iPhone"
- "(Windows 7) AND (Windows 10)"
- "Intel AND (i7 OR i9)"
top_headlines_topic:
type: "string"
title: "Top Headlines Topic"
description: "This parameter allows you to change the category for the request."
order: 9
enum:
- "breaking-news"
- "world"
- "nation"
- "business"
- "technology"
- "entertainment"
- "sports"
- "science"
- "health"
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
- dockerImage: "airbyte/source-gocardless:0.1.0"
spec:
documentationUrl: "https://docs.airbyte.com/integrations/sources/gocardless"
Expand Down
6 changes: 6 additions & 0 deletions airbyte-integrations/connectors/source-gnews/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*
!Dockerfile
!main.py
!source_gnews
!setup.py
!secrets
38 changes: 38 additions & 0 deletions airbyte-integrations/connectors/source-gnews/Dockerfile
Original file line number Diff line number Diff line change
@@ -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_gnews ./source_gnews

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-gnews
79 changes: 79 additions & 0 deletions airbyte-integrations/connectors/source-gnews/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Gnews Source

This is the repository for the Gnews configuration based source connector.
For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.io/integrations/sources/gnews).

## Local development

#### 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-gnews:build
```

#### Create credentials
**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.io/integrations/sources/gnews)
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_gnews/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 gnews test creds`
and place them into `secrets/config.json`.

### Locally running the connector docker image

#### Build
First, make sure you build the latest Docker image:
```
docker build . -t airbyte/source-gnews:dev
```

You can also build the connector image via Gradle:
```
./gradlew :airbyte-integrations:connectors:source-gnews: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-gnews:dev spec
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-gnews:dev check --config /secrets/config.json
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-gnews:dev discover --config /secrets/config.json
docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-gnews:dev read --config /secrets/config.json --catalog /integration_tests/configured_catalog.json
```
## Testing

#### 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 docker

### Using gradle to run tests
All commands should be run from airbyte project root.
To run unit tests:
```
./gradlew :airbyte-integrations:connectors:source-gnews:unitTest
```
To run acceptance and custom integration tests:
```
./gradlew :airbyte-integrations:connectors:source-gnews: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.
3 changes: 3 additions & 0 deletions airbyte-integrations/connectors/source-gnews/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#
Loading

0 comments on commit 88d743b

Please sign in to comment.