Skip to content

Commit

Permalink
✨ Source Asana: Add SectionsCompact stream (#31009)
Browse files Browse the repository at this point in the history
Co-authored-by: sajarin <sajarindider@gmail.com>
Co-authored-by: sajarin <sajarin@users.noreply.github.com>
  • Loading branch information
3 people committed Oct 16, 2023
1 parent 1567eaa commit 9479979
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 101 deletions.
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-asana/BOOTSTRAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Connector is implemented with [Airbyte CDK](https://docs.airbyte.io/connector-de

Some streams depend on:
- workspaces (Teams, Users, CustomFields, Projects, Tags, Users streams);
- projects (Sections, Tasks streams);
- projects (SectionsCompact, Sections, Tasks streams);
- tasks (Stories stream);
- teams (TeamMemberships stream).

Expand Down
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-asana/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ RUN pip install .
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.1.7
LABEL io.airbyte.version=0.1.8
LABEL io.airbyte.name=airbyte/source-asana
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
"sync_mode": "full_refresh",
"destination_sync_mode": "overwrite"
},
{
"stream": {
"name": "sections_compact",
"json_schema": {},
"supported_sync_modes": ["full_refresh"]
},
"sync_mode": "full_refresh",
"destination_sync_mode": "overwrite"
},
{
"stream": {
"name": "sections",
Expand Down
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-asana/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data:
connectorSubtype: api
connectorType: source
definitionId: d0243522-dccf-4978-8ba0-37ed47a0bdbf
dockerImageTag: 0.1.7
dockerImageTag: 0.1.8
dockerRepository: airbyte/source-asana
documentationUrl: https://docs.airbyte.com/integrations/sources/asana
githubIssueLabel: source-asana
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"type": ["null", "object"],
"properties": {
"gid": {
"type": ["null", "string"]
},
"resource_type": {
"type": ["null", "string"]
},
"name": {
"type": ["null", "string"]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from airbyte_cdk.sources.streams.http.auth import TokenAuthenticator
from source_asana.oauth import AsanaOauth2Authenticator

from .streams import CustomFields, Projects, Sections, Stories, Tags, Tasks, TeamMemberships, Teams, Users, Workspaces
from .streams import CustomFields, Projects, Sections, SectionsCompact, Stories, Tags, Tasks, TeamMemberships, Teams, Users, Workspaces


class SourceAsana(AbstractSource):
Expand Down Expand Up @@ -46,6 +46,7 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]:
return [
CustomFields(**args),
Projects(**args),
SectionsCompact(**args),
Sections(**args),
Stories(**args),
Tags(**args),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def _handle_array_type(self, prop: str, value: MutableMapping[str, Any]) -> str:

def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]:
response_json = response.json()
yield from response_json.get("data", []) # Asana puts records in a container array "data"
# Asana puts records in a container array "data"
yield from response_json.get("data", [])

def read_slices_from_records(self, stream_class: AsanaStreamType, slice_field: str) -> Iterable[Optional[Mapping[str, Any]]]:
"""
Expand Down Expand Up @@ -132,7 +133,7 @@ def request_params(self, stream_slice: Mapping[str, Any] = None, **kwargs) -> Mu

class ProjectRelatedStream(AsanaStream, ABC):
"""
Few streams (Sections and Tasks) depends on `project gid`: Sections as a part of url and Tasks as `projects`
Few streams (SectionsCompact and Tasks) depends on `project gid`: SectionsCompact as a part of url and Tasks as `projects`
argument in request.
"""

Expand All @@ -153,12 +154,29 @@ def path(self, **kwargs) -> str:
return "projects"


class Sections(ProjectRelatedStream):
class SectionsCompact(ProjectRelatedStream):
def path(self, stream_slice: Mapping[str, Any] = None, **kwargs) -> str:
project_gid = stream_slice["project_gid"]
return f"projects/{project_gid}/sections"


class Sections(AsanaStream):
def path(self, stream_slice: Mapping[str, Any] = None, **kwargs) -> str:
section_gid = stream_slice["section_gid"]
return f"sections/{section_gid}"

def stream_slices(self, **kwargs) -> Iterable[Optional[Mapping[str, Any]]]:
yield from self.read_slices_from_records(stream_class=SectionsCompact, slice_field="section_gid")

def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]:
response_json = response.json()
section_data = response_json.get("data", {})
if isinstance(section_data, dict): # Check if section_data is a dictionary
yield section_data
elif isinstance(section_data, list): # Check if section_data is a list
yield from section_data


class Stories(AsanaStream):
def path(self, stream_slice: Mapping[str, Any] = None, **kwargs) -> str:
task_gid = stream_slice["task_gid"]
Expand Down

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions docs/integrations/sources/asana.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ The connector is restricted by normal Asana [requests limitation](https://develo

| Version | Date | Pull Request | Subject |
| :------ | :--------- | :------------------------------------------------------- | :--------------------------------------------------------- |
| 0.1.8 | 2023-10-16 | [31009](https://github.com/airbytehq/airbyte/pull/31009) | Add SectionsCompact stream |
| 0.1.7 | 2023-05-29 | [26716](https://github.com/airbytehq/airbyte/pull/26716) | Remove authSpecification from spec.json, use advancedAuth instead |
| 0.1.6 | 2023-05-26 | [26653](https://github.com/airbytehq/airbyte/pull/26653) | Fix order of authentication methods |
| 0.1.5 | 2022-11-16 | [19561](https://github.com/airbytehq/airbyte/pull/19561) | Added errors handling, updated SAT with new format |
Expand Down

0 comments on commit 9479979

Please sign in to comment.