Skip to content

Commit

Permalink
feat: support worms-server 0.5.1
Browse files Browse the repository at this point in the history
Add support for worms-server 0.5.1. This adds the `acceptedAphiaId` field to the `WormsNode` DTOs as well as a new endpoint for getting a `WormsNames` DTO by Aphia ID.
  • Loading branch information
kevinsbarnard committed Feb 29, 2024
1 parent a93ccf0 commit f1989bc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion fathomnet/api/worms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List

from fathomnet.api import EndpointManager
from fathomnet.dto import WormsNode
from fathomnet.dto import WormsNames, WormsNode


class Worms(EndpointManager):
Expand All @@ -20,6 +20,12 @@ def get_all_names(limit: int = 100, offset: int = 0) -> List[str]:
return res_json['items']


def get_names_by_aphia_id(aphia_id: int) -> WormsNames:
"""Get the names data for a given Aphia ID."""
res_json = Worms.get(f'names/aphiaid/{aphia_id}')
return WormsNames.from_dict(res_json)


def get_ancestors_names(name: str) -> List[str]:
"""Get all ancestors' names of a given name."""
return Worms.get(f'ancestors/{name}')
Expand Down
10 changes: 10 additions & 0 deletions fathomnet/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,5 +608,15 @@ class WormsNode:
name: Optional[str] = None
rank: Optional[str] = None
aphiaId: Optional[int] = None
acceptedAphiaId: Optional[int] = None
alternateNames: Optional[List[str]] = None
children: Optional[List['WormsNode']] = None


@dataclass_json
@dataclass
class WormsNames:
aphiaId: Optional[int] = None
name: Optional[str] = None
acceptedName: Optional[str] = None
alternateNames: Optional[List[str]] = None
5 changes: 5 additions & 0 deletions test/test_worms.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def test_get_all_names(self):
names = worms.get_all_names()
self.assertIsNotNone(names)

def test_get_names_by_aphia_id(self):
names_obj = worms.get_names_by_aphia_id(2)
self.assertIsNotNone(names_obj)
self.assertEqual(2, names_obj.aphiaId)

def test_get_ancestors_names(self):
ancestors = worms.get_ancestors_names('Animalia')
self.assertIsNotNone(ancestors)
Expand Down

0 comments on commit f1989bc

Please sign in to comment.