Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source Zendesk: add streams: PostVotes, PostCommentVotes #27991

Merged
merged 15 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ COPY source_zendesk_support ./source_zendesk_support
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.9.0
LABEL io.airbyte.version=0.10.0
LABEL io.airbyte.name=airbyte/source-zendesk-support
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ acceptance_tests:
- name: "audit_logs"
bypass_reason: "no records"
- name: "post_comments"
bypass_reason: "can not populate"
bypass_reason: "not available in current subscription plan"
- name: "post_votes"
bypass_reason: "not available in current subscription plan"
- name: "post_comment_votes"
bypass_reason: "not available in current subscription plan"
incremental:
tests:
- config_path: "secrets/config.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,28 @@
"sync_mode": "full_refresh",
"destination_sync_mode": "append"
},
{
"stream": {
"name": "post_votes",
"json_schema": {},
"supported_sync_modes": ["full_refresh", "incremental"],
"source_defined_cursor": true,
"source_defined_primary_key": [["id"]]
},
"sync_mode": "full_refresh",
"destination_sync_mode": "append"
},
{
"stream": {
"name": "post_comment_votes",
"json_schema": {},
"supported_sync_modes": ["full_refresh", "incremental"],
"source_defined_cursor": true,
"source_defined_primary_key": [["id"]]
},
"sync_mode": "full_refresh",
"destination_sync_mode": "append"
},
{
"stream": {
"name": "organization_memberships",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data:
connectorType: source
maxSecondsBetweenMessages: 10800
definitionId: 79c1aa37-dae3-42ae-b333-d1c105477715
dockerImageTag: 0.9.0
dockerImageTag: 0.10.0
dockerRepository: airbyte/source-zendesk-support
githubIssueLabel: source-zendesk-support
icon: zendesk-support.svg
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "https://json-schema.org/draft-07/schema#",
"title": "Votes",
"type": ["null", "object"],
"properties": {
"created_at": {
"type": ["null", "string"],
"format": "date-time"
},
"id": {
"type": ["null", "integer"]
},
"item_id": {
"type": ["null", "integer"]
},
"item_type": {
"type": ["null", "string"]
},
"updated_at": {
"type": ["null", "string"],
"format": "date-time"
},
"url": {
"type": ["null", "string"]
},
"user_id": {
"type": ["null", "integer"]
},
"value": {
"type": ["null", "integer"]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
OrganizationMemberships,
Organizations,
PostComments,
PostCommentVotes,
Posts,
PostVotes,
SatisfactionRatings,
Schedules,
SlaPolicies,
Expand Down Expand Up @@ -126,6 +128,8 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]:
OrganizationMemberships(**args),
Posts(**args),
PostComments(**args),
PostCommentVotes(**args),
PostVotes(**args),
SatisfactionRatings(**args),
SlaPolicies(**args),
Tags(**args),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
import requests
from airbyte_cdk.models import SyncMode
from airbyte_cdk.sources.streams.availability_strategy import AvailabilityStrategy
from airbyte_cdk.sources.streams.core import package_name_from_class
from airbyte_cdk.sources.streams.http import HttpStream, HttpSubStream
from airbyte_cdk.sources.streams.http.auth.core import HttpAuthenticator
from airbyte_cdk.sources.streams.http.availability_strategy import HttpAvailabilityStrategy
from airbyte_cdk.sources.streams.http.exceptions import DefaultBackoffException
from airbyte_cdk.sources.streams.http.rate_limiting import TRANSIENT_EXCEPTIONS
from airbyte_cdk.sources.utils.schema_helpers import ResourceSchemaLoader
from airbyte_cdk.sources.utils.transform import TransformConfig, TypeTransformer
from requests.auth import AuthBase
from requests_futures.sessions import PICKLE_ERROR, FuturesSession
Expand Down Expand Up @@ -871,3 +873,44 @@ def path(
) -> str:
post_id = stream_slice.get("parent").get("id")
return f"community/posts/{post_id}/comments"


class AbstractVotes(SourceZendeskSupportFullRefreshStream, ABC):

response_list_name = "votes"

def get_json_schema(self) -> Mapping[str, Any]:
return ResourceSchemaLoader(package_name_from_class(self.__class__)).get_schema("votes")


class PostVotes(AbstractVotes, HttpSubStream):
def __init__(self, **kwargs):
parent = Posts(**kwargs)
super().__init__(parent=parent, **kwargs)

def path(
self,
*,
stream_state: Mapping[str, Any] = None,
stream_slice: Mapping[str, Any] = None,
next_page_token: Mapping[str, Any] = None,
) -> str:
post_id = stream_slice.get("parent").get("id")
return f"community/posts/{post_id}/votes"


class PostCommentVotes(AbstractVotes, HttpSubStream):
def __init__(self, **kwargs):
parent = PostComments(**kwargs)
super().__init__(parent=parent, **kwargs)

def path(
self,
*,
stream_state: Mapping[str, Any] = None,
stream_slice: Mapping[str, Any] = None,
next_page_token: Mapping[str, Any] = None,
) -> str:
post_id = stream_slice.get("parent").get("post_id")
comment_id = stream_slice.get("parent").get("id")
return f"community/posts/{post_id}/comments/{comment_id}/votes"
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
Macros,
OrganizationMemberships,
Organizations,
PostCommentVotes,
Posts,
SatisfactionRatings,
Schedules,
Expand Down Expand Up @@ -142,12 +143,12 @@ def test_check(response, start_date, check_passed):
@pytest.mark.parametrize(
"ticket_forms_response, status_code, expected_n_streams, expected_warnings",
[
({"ticket_forms": [{"id": 1, "updated_at": "2021-07-08T00:05:45Z"}]}, 200, 25, []),
({"ticket_forms": [{"id": 1, "updated_at": "2021-07-08T00:05:45Z"}]}, 200, 27, []),
(
{"error": "Not sufficient permissions"},
403,
22,
["Skipping stream ticket_forms: Check permissions, error message: Not sufficient permissions."],
{"error": "Not sufficient permissions"},
403,
24,
["Skipping stream ticket_forms: Check permissions, error message: Not sufficient permissions."],
),
],
ids=["forms_accessible", "forms_inaccessible"],
Expand Down Expand Up @@ -989,3 +990,26 @@ def test_read_tickets_stream(requests_mock):
]
},
]


def test_read_post_comment_votes_stream(requests_mock):
post_response = {
"posts": [
{"id": 7253375870607, "title": "Test_post", "created_at": "2023-01-01T00:00:00Z", "updated_at": "2023-01-01T00:00:00Z"}
]
}
requests_mock.get("https://subdomain.zendesk.com/api/v2/community/posts", json=post_response)

post_comments_response = {
"comments": [
{"author_id": 89567, "body": "Test_comment for Test_post", "id": 35467, "post_id": 7253375870607}
]
}
requests_mock.get("https://subdomain.zendesk.com/api/v2/community/posts/7253375870607/comments", json=post_comments_response)

votes = [{"id": 35467, "user_id": 888887, "value": -1}]
requests_mock.get("https://subdomain.zendesk.com/api/v2/community/posts/7253375870607/comments/35467/votes",
json={"votes": votes})
stream = PostCommentVotes(subdomain="subdomain", start_date="2020-01-01T00:00:00Z")
records = read_full_refresh(stream)
assert records == votes
1 change: 1 addition & 0 deletions docs/integrations/sources/zendesk-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ The Zendesk connector ideally should not run into Zendesk API limitations under

| Version | Date | Pull Request | Subject |
|:---------|:-----------|:---------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `0.10.0` | 2023-07-06 | [27991](https://github.com/airbytehq/airbyte/pull/27991) | add streams: `PostVotes`, `PostCommentVotes` |
| `0.9.0` | 2023-07-05 | [27961](https://github.com/airbytehq/airbyte/pull/27961) | Add stream: `Post Comments` |
| `0.8.1` | 2023-06-27 | [27765](https://github.com/airbytehq/airbyte/pull/27765) | Bugfix: Nonetype error while syncing more then 100000 organizations |
| `0.8.0` | 2023-06-09 | [27156](https://github.com/airbytehq/airbyte/pull/27156) | Add stream `Posts` |
Expand Down
Loading