Top Level Namespace
Defined Under Namespace
Modules: FriendFeed
Classes: Array, Hash, IO, String
Constant Summary
collapse
- MYNAME =
File.basename($0)
URI.parse('http://twitter.com/')
Instance Method Summary
collapse
Instance Method Details
#agent ⇒ Object
75
76
77
|
# File 'bin/tw2ff', line 75
def agent
$agent ||= Mechanize.new
end
|
#Config(keypath, default = :omitted) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'bin/tw2ff', line 41
def Config(keypath, default = :omitted)
$config ||= YAML.load_file(ConfigFile())
keypath.split('.').inject($config) { |hash, key|
hash.is_a?(Hash) or raise TypeError
hash.fetch(key)
}
rescue => e
return default if default != :omitted
STDERR.print <<EOM
The key "#{keypath}" is missing in #{ConfigFile()}.
Please run "#{$0} config" and fill out necessary information.
EOM
exit 1
end
|
#ConfigDir ⇒ Object
26
27
28
29
30
31
32
33
34
35
|
# File 'bin/tw2ff', line 26
def ConfigDir()
$config_dir ||=
begin
config_dir = File.expand_path('~/.%s' % MYNAME)
if !File.directory?(config_dir)
Dir.mkdir(config_dir, 0700)
end
config_dir
end
end
|
#ConfigFile ⇒ Object
37
38
39
|
# File 'bin/tw2ff', line 37
def ConfigFile()
$config_file ||= File.join(ConfigDir(), 'config.yml')
end
|
#friendfeed_client ⇒ Object
117
118
119
120
121
122
123
124
125
|
# File 'bin/tw2ff', line 117
def friendfeed_client
$ff_client ||=
begin
username = Config('friendfeed.username')
password = Config('friendfeed.password')
putinfo 'Logging in to FriendFeed as %s', username
FriendFeed::Client.new.login(username, password)
end
end
|
#get_file(url) ⇒ Object
93
94
95
96
97
|
# File 'bin/tw2ff', line 93
def get_file(url)
uri = parse_uri(url)
putinfo 'Fetching %s', uri
agent.get_file(uri)
end
|
#parse_uri(url) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'bin/tw2ff', line 79
def parse_uri(url)
case url
when URI
url
else
begin
URI.parse(url)
rescue URI::InvalidURIError
dir, file = File.split(url)
URI.parse(File.join(dir, URI.escape(file)))
end
end
end
|
#putinfo(fmt, *args) ⇒ Object
58
59
60
|
# File 'bin/tw2ff', line 58
def putinfo(fmt, *args)
STDERR.puts sprintf(fmt, *args)
end
|
#Status(key) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'bin/tw2ff', line 62
def Status(key)
$status ||= YAML::Store.new(File.join(ConfigDir(), 'status.yml'))
if block_given?
$status.transaction(false) {
return $status[key] = yield
}
else
$status.transaction(true) {
return $status[key]
}
end
end
|
142
143
144
145
146
147
148
149
150
|
# File 'bin/tw2ff', line 142
def
$tw_client ||=
begin
username = Config('twitter.username')
password = Config('twitter.password')
putinfo 'Logging in to Twitter as %s', username
Twitter::Base.new(Twitter::HTTPAuth.new(username, password))
end
end
|