-
Notifications
You must be signed in to change notification settings - Fork 1
/
follow_tumblr.rb
69 lines (53 loc) · 1.93 KB
/
follow_tumblr.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
gem 'oauth'
require 'oauth'
require 'oauth/consumer'
# Instantiate consumer object
puts "Paste in your consumer key:"
consumer_key = gets.chomp
puts "Paste in your secret key:"
secret_key = gets.chomp
@consumer = OAuth::Consumer.new(consumer_key,
secret_key,
site: "http://www.tumblr.com")
@request_token = @consumer.get_request_token
puts "Go here to authorize your app:"
puts @request_token.authorize_url # outputs a url that authorizes the app
puts "\nPaste url from post authorization:"
url = gets
oauth_verifier = url.match(/oauth_verifier=(.+)\n/)[1]
# If we don't yet have an access token, we need to go through the
# OAuth redirect and copy the oauth_verifier from the URL
# We can then use the method below to trade our oauth_verifier for
# and access token. Be careful, oauth_verifiers expire on the order of
# minutes
@access_token = @request_token.get_access_token(:oauth_verifier => oauth_verifier)
puts <<-EOF
+-----------------------------------+
| Paste this code in to get started |
+-----------------------------------+
@consumer = OAuth::Consumer.new("#{consumer_key}",
"#{secret_key}",
site: "http://www.tumblr.com")
OAUTH_TOKEN = '#{@access_token.token}'
OAUTH_SECRET = '#{@access_token.secret}'
access_token = OAuth::AccessToken.new(@consumer, OAUTH_TOKEN, OAUTH_SECRET)
EOF
# Can now do whatever we need to
# access_token has all the normal http request methods
# and returns a standard ruby http response
#### Tumblr API
# All API requests start with api.tumblr.com
#
# To get blog data or write to a blog:
# api.tumblr.com/v2/blog/#{base-hostname}/...
# Example
# api.tumblr.com/v2/blog/#{base-hostname}/posts[/type]
#
# To get user data or perform user actions
# api.tumblr.com/v2/user/...
#
#
# /info — Retrieve Blog Info
# /avatar response is a string url
# /followers
# /posts