forked from jeremytregunna/ruby-trello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
64 lines (47 loc) · 2.06 KB
/
Rakefile
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
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new
task :default => [:spec]
namespace :example do
$LOAD_PATH.unshift 'lib'
require "addressable/uri"
require "trello"
include Trello
include Trello::Authorization
desc "get a new request token"
task :get_request_token do
ensure_consumer_credentials
@developer_public_key = ENV["DEVELOPER_PUBLIC_KEY"]
@developer_secret = ENV["DEVELOPER_SECRET"]
OAuthPolicy.consumer_credential = OAuthCredential.new @developer_public_key, @developer_secret
OAuthPolicy.token = nil
request = Request.new :get, URI.parse("https://trello.com/1/OAuthGetRequestToken")
response = TInternet.execute OAuthPolicy.authorize(request)
the_request_token = parse_token(response.body)
puts "key => #{the_request_token.key}, secret => #{the_request_token.secret}"
end
desc "convert request token to access token"
task :get_access_token, :request_token_key, :request_token_secret, :oauth_verifier do |t, args|
ensure_consumer_credentials
@developer_public_key = ENV["DEVELOPER_PUBLIC_KEY"]
@developer_secret = ENV["DEVELOPER_SECRET"]
OAuthPolicy.consumer_credential = OAuthCredential.new @developer_public_key, @developer_secret
OAuthPolicy.token = OAuthCredential.new args.request_token_key, args.request_token_secret
access_token_request = Request.new :get, URI.parse("https://trello.com/1/OAuthGetAccessToken?oauth_verifier=#{args.oauth_verifier}")
response = TInternet.execute OAuthPolicy.authorize(access_token_request)
the_access_token = parse_token response.body
puts "key => #{the_access_token.key}, secret => #{the_access_token.secret}"
end
def ensure_consumer_credentials
%w{PUBLIC_KEY SECRET}.each do |name|
fullname = "DEVELOPER_#{name}"
unless ENV[fullname]
puts "ERROR: Missing <#{fullname}> environment variable."
exit 1
end
end
end
def parse_token(text)
matchdata = /oauth_token=([^&]+)&oauth_token_secret=(.+)/.match text
the_request_token = OAuthCredential.new *matchdata[1..2]
end
end