sarumont / py-trello

Python API wrapper around Trello's API
BSD 3-Clause "New" or "Revised" License
948 stars 329 forks source link

Convert web based shortURL to something usable by the API #260

Open sibson opened 6 years ago

sibson commented 6 years ago

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')
sibson commented 6 years ago

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?

sarumont commented 6 years ago

@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.