· 6 years ago · Nov 08, 2018, 08:42 AM
1require 'tumblr_client'
2Tumblr.configure do |config|
3 config.consumer_key = "conumer_key"
4 config.consumer_secret = "consumer_secret"
5 config.oauth_token = "oauth_token"
6 config.oauth_token_secret = "oauth_token_secret"
7end
8client = Tumblr::Client.new
9posts = client.posts("blog", id: id, notes_info: true)
10notes = posts["posts"].first["notes"]
11notes = notes.uniq { |note| note["blog_name"] } # prevent multiple entries
12notes = notes.delete_if do |note|
13 note["blog_name"] == "authors blog" || # prevent author from winning
14 note["type"] != "reblog" # allow only reblogs to win
15end
16winner = notes.shuffle.first
17puts "#{winner["blog_name"]} - #{winner["type"]}"