Last Updated: February 25, 2016
·
2.289K
· martintsch

Take a picture of you and upload it to tumblr via post-commit

Have you ever wondered how you look like during your coding sessions?

Make some pictures on every commit...

  • create a new application on tumblr
  • brew install imagesnap (shoots pictures via your webcam)
  • get your tumblr api keys
  • use the code underneath in your post-commit git hook
  • don't forget to make it executable (chmod a+x .git/hooks/post-commit)

(scroll in the code if it doesn't display everything)

#!/usr/bin/env ruby

 require 'tumblr_client'

 Tumblr.configure do |config|
   config.consumer_key = ""
   config.consumer_secret = ""
   config.oauth_token = ""
   config.oauth_token_secret = ""
 end

 client = Tumblr::Client.new

 file="path/to/some/folder/#{Time.now.to_i}.jpg"
 puts "Taking capture into #{file}!"
 system "imagesnap -q #{file}"

 Process.fork {
   raw = File.open(file, 'rb').read
   client.photo('yourblog.tumblr.com', :data_raw => [raw])
 }
 exit 0

Have fun and enjoy :-)

see also Link

4 Responses
Add your response

Hey. This is pretty cool. It's a shame though that it's a bit fiddly/annoying to get all the right tokens etc for the tumblr API.

over 1 year ago ·

The tumblr_client gem should help you. The first time you try to go to the console it walks you through the token generation.

https://github.com/tumblr/tumblr_client#the-irb-console

over 1 year ago ·

Is there any documentation on this anywhere? I'm not familiar with Ruby, and I can't find squat. I've managed to instantiate a tumblr_client, I think, but it's not "walking me through" a thing.

irb(main):002:0> require 'tumblrclient'
require 'tumblr
client'
=> true
irb(main):003:0> client = Tumblr::Client.new
client = Tumblr::Client.new
=> #<Tumblr::Client:0x007fb23a4a0530 @consumerkey=nil, @consumersecret=nil, @oauthtoken=nil, @oauthtoken_secret=nil, @client=nil>
irb(main):004:0> likes = client.likes
likes = client.likes
=> {"status"=>401, "msg"=>"Not Authorized"}

over 1 year ago ·

Instead of running irb in your shell and requiring tumblr_client. Execute tumblr in the shell after installing the gem.

over 1 year ago ·