mwunsch / tumblr

Command line interface and Ruby client for the Tumblr API (v2)
MIT License
282 stars 43 forks source link

Add a 'list' method to the command line client that lists post ids #25

Closed elstudio closed 11 years ago

elstudio commented 11 years ago

...and urls, optionally filtered by tag or post type.

Here's what the output looks like:

$ tumblr help list Usage: tumblr list

Options: [--tag=TAG] # Post tag [--type=TYPE] # Post type: text, quote, link, answer, video, audio, photo, chat [--credentials=CREDENTIALS] # The file path where your Tumblr OAuth keys are stored. Defaults to ~/.tumblr. [--host=HOST] # The hostname of the blog you want to post to i.e. "YOUR-NAME.tumblr.com"

List Tumblr post_ids and URLs for posts, optionally with a particular tag or post type

Or if you actually run the command you'll get something like this (provided you've got the correct authorization, etc):

$ tumblr list --type=quote 39948369647 => http://cca.elstudio.us/post/39948369647/please-just-do-this-if-you-do-nothing-else-git 39703564743 => http://cca.elstudio.us/post/39703564743/think-about-what-other-features-are-missing-in-the

Hope you'll find it helpful!

mwunsch commented 11 years ago

I've added some notes to the diff, but beyond that, I'm not sure what the utility of such a function is?

If you wanted to list posts by id and url, I would prefer using some kind of standard output format, such as CSV or TSV, to play nicely with other unix tools.

elstudio commented 11 years ago

Thanks for the comments -- the patch is much nicer for them.

Why a 'list' method? Since delete, edit and fetch all require a POST_ID, I needed a quick way of getting these POST_IDs. (In my case, I wanted to fetch all posts with a particular tag.) Copying them from the web browser window seemed tedious...

As for the output format, the patch now outputs as YAML. But I'm not sure that's the best way to go.

For scripting purposes, a list of POST_IDs would be best. But seeing the URL is very helpful for any manual use (like my purposes).

What do you think?

$ tumblr list --type=quote --host=cca.elstudio.us

39948369647: http://cca.elstudio.us/post/39948369647/please-just-do-this-if-you-do-nothing-else-git 39703564743: http://cca.elstudio.us/post/39703564743/think-about-what-other-features-are-missing-in-the

mwunsch commented 11 years ago

I'm getting this exception locally:

undefined method `y' for #<Tumblr::CommandLineInterface:0x007fcd8120bda8> (NoMethodError)

Not sure how the y method is appearing on your load path. I think it might be better if you explicitly serialize the Hash to yaml and use ui_puts or say to write it to STDOUT.

I like YAML as the serialization format.