console_tweet 0.0.6 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/console_tweet/cli.rb +52 -12
- data/lib/console_tweet/version.rb +1 -1
- metadata +4 -21
data/lib/console_tweet/cli.rb
CHANGED
@@ -7,7 +7,7 @@ module ConsoleTweet
|
|
7
7
|
require 'yaml'
|
8
8
|
|
9
9
|
# The allowed API methods
|
10
|
-
AllowedMethods = [:setup, :help, :status, :tweet]
|
10
|
+
AllowedMethods = [:setup, :help, :status, :tweet, :timeline]
|
11
11
|
|
12
12
|
# Twitter API details
|
13
13
|
ConsumerKey = 'MvVdCyl6xCVtEUVdcp4rw'
|
@@ -37,7 +37,7 @@ module ConsoleTweet
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
# get the first command as the method, and the rest of the commands as args
|
40
|
-
method = @commands.empty? ? :
|
40
|
+
method = @commands.empty? ? :timeline : @commands[0].to_sym
|
41
41
|
return method_missing(method) unless AllowedMethods.include?(method)
|
42
42
|
self.send(method, @commands[1..@commands.size])
|
43
43
|
end
|
@@ -56,7 +56,30 @@ module ConsoleTweet
|
|
56
56
|
false # Didn't get an access token
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
|
+
# Display the user's timeline
|
61
|
+
def timeline(*args)
|
62
|
+
load_default_token
|
63
|
+
return failtown("Unauthorized, re-run setup!") unless @client && @client.authorized?
|
64
|
+
|
65
|
+
# Only send since_id to @client if it's not nil
|
66
|
+
home_timeline = since_id ? @client.home_timeline(:since_id => since_id) : @client.home_timeline
|
67
|
+
|
68
|
+
if home_timeline.any?
|
69
|
+
# We want the latest tweets at the bottom on a CLI
|
70
|
+
home_timeline.reverse!
|
71
|
+
|
72
|
+
# Print each tweet, with user name on next line
|
73
|
+
home_timeline.each do |tweet|
|
74
|
+
puts "#{tweet['text']}\n#{NameColor}@#{tweet['user']['screen_name']} (#{tweet['user']['name']})#{DefaultColor}\n\n"
|
75
|
+
end
|
76
|
+
|
77
|
+
# Save the last id as since_id
|
78
|
+
self.since_id = home_timeline.last['id']
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
60
83
|
# Send a tweet for the user
|
61
84
|
def tweet(*args)
|
62
85
|
load_default_token
|
@@ -71,7 +94,7 @@ module ConsoleTweet
|
|
71
94
|
end
|
72
95
|
return failtown("Empty Tweet") if tweet_text.empty?
|
73
96
|
return failtown("Tweet is too long!") if tweet_text.size > 140
|
74
|
-
return failtown("Unauthorized, re-run setup!") unless @client.authorized?
|
97
|
+
return failtown("Unauthorized, re-run setup!") unless @client && @client.authorized?
|
75
98
|
# actually post it
|
76
99
|
@client.update(tweet_text)
|
77
100
|
puts "Tweet Posted!"
|
@@ -80,7 +103,7 @@ module ConsoleTweet
|
|
80
103
|
# Get the user's most recent status
|
81
104
|
def status(*args)
|
82
105
|
load_default_token
|
83
|
-
return failtown("Unauthorized, re-run setup!") unless @client.authorized?
|
106
|
+
return failtown("Unauthorized, re-run setup!") unless @client && @client.authorized?
|
84
107
|
user = @client.info
|
85
108
|
status = user['status']
|
86
109
|
puts "#{user['name']} (at #{status['created_at']}) #{status['text']}"
|
@@ -103,6 +126,7 @@ module ConsoleTweet
|
|
103
126
|
puts "#{NameColor}console-tweet#{DefaultColor} by John Crepezzi <john.crepezzi@gmail.com>"
|
104
127
|
puts 'http://github.com/seejohnrun/console-tweet'
|
105
128
|
puts
|
129
|
+
puts "#{CommandColor}twitter#{DefaultColor} View your timeline, since last view"
|
106
130
|
puts "#{CommandColor}twitter setup#{DefaultColor} Setup your account"
|
107
131
|
puts "#{CommandColor}twitter status#{DefaultColor} Get your most recent status"
|
108
132
|
puts "#{CommandColor}twitter tweet \"Hello World\"#{DefaultColor} Send out a tweet"
|
@@ -123,17 +147,21 @@ module ConsoleTweet
|
|
123
147
|
|
124
148
|
# Load the default token from the ~/.twitter file
|
125
149
|
def load_default_token
|
126
|
-
tokens = load_tokens
|
127
|
-
|
128
|
-
|
150
|
+
if tokens = load_tokens
|
151
|
+
default_hash = tokens[:default]
|
152
|
+
@client = TwitterOAuth::Client.new(:consumer_key => ConsumerKey, :consumer_secret => ConsumerSecret, :token => default_hash[:token], :secret => default_hash[:secret])
|
153
|
+
default_hash
|
154
|
+
end
|
129
155
|
end
|
130
156
|
|
131
157
|
# Load tokens from the ~/.twitter file
|
132
158
|
def load_tokens
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
159
|
+
if File.exists?(TOKEN_PATH)
|
160
|
+
f = File.open(TOKEN_PATH, 'r')
|
161
|
+
tokens = YAML::load(f)
|
162
|
+
f.close
|
163
|
+
tokens
|
164
|
+
end
|
137
165
|
end
|
138
166
|
|
139
167
|
# Save the set of tokens to the ~/.twitter file
|
@@ -147,6 +175,18 @@ module ConsoleTweet
|
|
147
175
|
def self.get_input
|
148
176
|
STDIN.gets.strip.chomp
|
149
177
|
end
|
178
|
+
|
179
|
+
# Getter for since_id in ~/.twitter file
|
180
|
+
def since_id
|
181
|
+
load_default_token[:since_id]
|
182
|
+
end
|
183
|
+
|
184
|
+
# Setter for since_id in ~/.twitter file
|
185
|
+
def since_id=(id)
|
186
|
+
tokens = load_default_token
|
187
|
+
tokens[:since_id] = id
|
188
|
+
save_tokens(:default => tokens)
|
189
|
+
end
|
150
190
|
|
151
191
|
end
|
152
192
|
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: console_tweet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 6
|
10
|
-
version: 0.0.6
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- John Crepezzi
|
@@ -15,7 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-
|
13
|
+
date: 2011-05-20 00:00:00 -04:00
|
19
14
|
default_executable:
|
20
15
|
dependencies:
|
21
16
|
- !ruby/object:Gem::Dependency
|
@@ -26,9 +21,6 @@ dependencies:
|
|
26
21
|
requirements:
|
27
22
|
- - ">="
|
28
23
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
|
-
segments:
|
31
|
-
- 0
|
32
24
|
version: "0"
|
33
25
|
type: :development
|
34
26
|
version_requirements: *id001
|
@@ -40,9 +32,6 @@ dependencies:
|
|
40
32
|
requirements:
|
41
33
|
- - ">="
|
42
34
|
- !ruby/object:Gem::Version
|
43
|
-
hash: 3
|
44
|
-
segments:
|
45
|
-
- 0
|
46
35
|
version: "0"
|
47
36
|
type: :runtime
|
48
37
|
version_requirements: *id002
|
@@ -73,23 +62,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
62
|
requirements:
|
74
63
|
- - ">="
|
75
64
|
- !ruby/object:Gem::Version
|
76
|
-
hash: 3
|
77
|
-
segments:
|
78
|
-
- 0
|
79
65
|
version: "0"
|
80
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
67
|
none: false
|
82
68
|
requirements:
|
83
69
|
- - ">="
|
84
70
|
- !ruby/object:Gem::Version
|
85
|
-
hash: 3
|
86
|
-
segments:
|
87
|
-
- 0
|
88
71
|
version: "0"
|
89
72
|
requirements: []
|
90
73
|
|
91
74
|
rubyforge_project: console_tweet
|
92
|
-
rubygems_version: 1.
|
75
|
+
rubygems_version: 1.6.2
|
93
76
|
signing_key:
|
94
77
|
specification_version: 3
|
95
78
|
summary: CLI Twitter Client
|