py-trello
py-trello copied to clipboard
Convert web based shortURL to something usable by the API
Trello uses short URLs for the web experience but the API uses IDs exclusively. There isn't an easy way to convert a URL to an ID that is usable to the API.
I'm trying to build a small simple CLI tool to help clone templates that are provided by users.
For instance, it would be useful to have some variant of the following
board = trello.get_board_from_shorturl('https://trello.com/b/FcTw02R1/py-trello)
card = trello.get_card_from_shorturl('https://trello.com/c/IwcZ4DR2/1-py-trello-can-be-found-at-https-githubcom-sarumont-py-trello')
board_id = trello.get_id_for_url('https://trello.com/b/FcTw02R1/py-trello')
card_id = trello.get_id_for_url(''https://trello.com/c/IwcZ4DR2/1-py-trello-can-be-found-at-https-githubcom-sarumont-py-trello')
It currently looks like I'd need to refactor the fetch_json() method to extract the auth/header/request bits and then use the new method to fetch shortURL.json. From there it would be pretty mechanical to extract the Id and build the shims around various from_json() calls.
Is there a simpler solution?
@sibson Yes, that's currently where all the URLs are fetched, so you'd need to refactor or overload fetch_json to handle the short URLs.