-
Notifications
You must be signed in to change notification settings - Fork 0
/
twurlrc-reader.rb
47 lines (39 loc) · 1.36 KB
/
twurlrc-reader.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
#!/usr/bin/ruby
require 'yaml'
require 'twitter'
class TwurlrcReader
# provide me username and consumer key and i'll return all the good stuff
# from a twurl rc file. see https://github.com/kurrik/twurlrc
attr_reader :username, :consumer_key, :consumer_secret, :access_token, :access_token_secret
attr_accessor :client
def initialize(username, consumer_key, path = false)
if path
@path = path
else
@path = ENV['HOME']+'/.twurlrc'
end
@username = username
@consumer_key = consumer_key
#load our yaml and set rest of class variables
profile = YAML.load_file(@path)['profiles'][@username][@consumer_key]
@consumer_secret = profile['consumer_secret']
@access_token = profile['token']
@access_token_secret = profile['secret']
end
def get_rest_client
# set up a twitter client if requested
return Twitter::REST::Client.new do |config|
config.consumer_key = @consumer_key
config.consumer_secret = @consumer_secret
config.access_token = @access_token
config.access_token_secret = @access_token_secret
end
end
end
#account = TwurlrcReader.new('MarbleckaeYumte','lN1fHeFIm7LTAKQYV03DDpVNO')
#puts account.username
#puts account.consumer_key
#puts account.consumer_secret
#puts account.access_token
#puts account.access_token_secret
#client = account.get_rest_client()