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

Support for child items #22

Open
mendykrauss opened this issue Feb 2, 2022 · 4 comments
Open

Support for child items #22

mendykrauss opened this issue Feb 2, 2022 · 4 comments

Comments

@mendykrauss
Copy link

mendykrauss commented Feb 2, 2022

I'm wondering how to get child item info.

i.e. /service/boards/{id}/statuses

(Same with board types, subtypes, etc.)

@emichaud
Copy link

emichaud commented Feb 8, 2022

hi @mendykrauss,
At the moment, those board api endpoints are not available in ConnectPyse (CP). There are over 18 of them in total. CP supports boards only at the moment.

CP does not have 100% coverage of all the CW apis. It has broad coverage of many of the more commonly used modules of CW like service tickets and companies plus many others. for example CP wraps about 37 api's of CW yet CW api count is closer to 200 ish.

wish I had better news.

@emichaud
Copy link

emichaud commented Feb 8, 2022

Hey @mendykrauss,

I know that was a lame answer. I took a deeper look this morning at how to accomplish this in the short term without an official CP api wrapper.

For just getting that info, it's not too difficult by subclassing CWcontroller. I'm sure this can be accomplished in a cleaner way but its not terrible. There is a-lot of meta programming the in the base objects and I haven't quite got my heard around it all. It helps that several of the board child items already have an object type created in CP. This includes boards/types, boards/sub_types, boards/items, boards/team, boards/status, etc. However some are missing. I added logic to serialize the data when possible and if not just return the json response direct from CW. In the latter case, it's up to the user to get what they need from the json.

Here is an example class that will return serialized board child elements for items that have a object definition or just json for ones that don't. Note: it only provides support for the "get" function. Other actions would have to be built out.
I hope this is helpful for you.

from connectPyse.service import tickets_api, boards_api, board, board_type, board_status, board_item, board_sub_type, board_team
from connectPyse import CWController
from connectPyse.restapi import ApiError

class BoardChildItemsAPI(CWController):
	def __init__(self, **kwargs):
		self.module_url = 'service'
		self.module = 'boards'
		self._class = None
		super().__init__(**kwargs)

	def call_api(self, url_suffix=None):
		endpoint = getattr(self, self.module)
		try:
			json_results = endpoint.get(the_id=url_suffix, user_headers=self.basic_auth,
			                            user_params=self._format_user_params())
		except ApiError as e:
			raise e

		if self._class is not None:
			for json in json_results:
				yield self._class(json)
		else:
			return json_results

	def get_board_types(self, board_id=None) -> [board_type.BoardType]:
		self._class = board_type.BoardType
		suffix = f'{board_id}/types'
		return self.call_api(url_suffix=suffix)

	def get_board_sub_types(self, board_id=None) -> [board_sub_type.BoardSubType]:
		self._class = board_sub_type.BoardSubType
		suffix = f'{board_id}/subtypes'
		return self.call_api(url_suffix=suffix)

	def get_board_items(self, board_id=None) -> [board_item.BoardItem]:
		self._class = board_item.BoardItem
		suffix = f'{board_id}/items'
		return self.call_api(url_suffix=suffix)

	def get_board_status(self, board_id=None) -> [board_status.BoardStatus]:
		self._class = board_status.BoardStatus
		suffix = f'{board_id}/statuses'
		return self.call_api(url_suffix=suffix)

	def get_board_teams(self, board_id=None) -> [board_team.BoardTeam]:
		self._class = board_team.BoardTeam
		suffix = f'{board_id}/teams'
		return self.call_api(url_suffix=suffix)

	def get_board_type_subtype_item_association(self, board_id=None) -> []:
		suffix = f'{board_id}/typeSubTypeItemAssociations'
		return self.call_api(url_suffix=suffix)

	def get_board_auto_templates(self, board_id=None) -> []:
		suffix = f'{board_id}/autoTemplates'
		return self.call_api(url_suffix=suffix)



# example usage of BoardChildItems api subclass
api = BoardChildItemsAPI(url=BASE_URL, auth=AUTH)
obj_list = api.get_board_types(board_id=1)
# obj_list = api.get_board_sub_types(board_id=1)
# obj_list = api.get_board_items(board_id=1)
# obj_list = api.get_board_status(board_id=1)
# obj_list = api.get_board_teams(board_id=1)
# obj_list = api.get_board_type_subtype_item_association(board_id=1)
# obj_list = api.get_board_auto_templates(board_id=1)
for o in obj_list:
	print(o)

@mendykrauss
Copy link
Author

Thank you! For now I was only looking for get...

@markciecior
Copy link
Owner

I solved this for Purchase Order Line Items with this module, but that was a one-off. An example is here.

I think @emichaud's solution is probably more scalable than mine. Either way, somebody's got to write the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants