console_tweet 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ module ConsoleTweet
7
7
  require 'yaml'
8
8
 
9
9
  # The allowed API methods
10
- AllowedMethods = [:setup, :help, :status, :tweet, :timeline]
10
+ AllowedMethods = [:setup, :help, :status, :tweet, :timeline, :show]
11
11
 
12
12
  # Twitter API details
13
13
  ConsumerKey = 'MvVdCyl6xCVtEUVdcp4rw'
@@ -61,23 +61,13 @@ module ConsoleTweet
61
61
  def timeline(*args)
62
62
  load_default_token
63
63
  return failtown("Unauthorized, re-run setup!") unless @client && @client.authorized?
64
-
65
64
  # Only send since_id to @client if it's not nil
66
65
  home_timeline = since_id ? @client.home_timeline(:since_id => since_id) : @client.home_timeline
67
-
68
66
  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
-
67
+ print_tweets(home_timeline)
77
68
  # Save the last id as since_id
78
69
  self.since_id = home_timeline.last['id']
79
70
  end
80
-
81
71
  end
82
72
 
83
73
  # Send a tweet for the user
@@ -100,13 +90,25 @@ module ConsoleTweet
100
90
  puts "Tweet Posted!"
101
91
  end
102
92
 
93
+ # Get 20 most recent statuses of user, or specified user
94
+ def show(args)
95
+ # If we have no user to get, use the timeline instead
96
+ return timeline(args) if args.nil? || args.count == 0
97
+ target_user = args[0]
98
+ # Get the timeline and print the tweets if we don't get an error
99
+ load_default_token # for private tweets
100
+ res = @client.user_timeline(:screen_name => target_user)
101
+ return failtown("show :: #{res['error']}") if !res || res.include?('error')
102
+ print_tweets(res)
103
+ end
104
+
103
105
  # Get the user's most recent status
104
106
  def status(*args)
105
107
  load_default_token
106
108
  return failtown("Unauthorized, re-run setup!") unless @client && @client.authorized?
107
109
  user = @client.info
108
110
  status = user['status']
109
- puts "#{user['name']} (at #{status['created_at']}) #{status['text']}"
111
+ puts "#{user['name']} (at #{status['created_at']}) #{status['text']}" unless status.nil?
110
112
  end
111
113
 
112
114
  # Get the access token for the user and save it
@@ -130,6 +132,7 @@ module ConsoleTweet
130
132
  puts "#{CommandColor}twitter setup#{DefaultColor} Setup your account"
131
133
  puts "#{CommandColor}twitter status#{DefaultColor} Get your most recent status"
132
134
  puts "#{CommandColor}twitter tweet \"Hello World\"#{DefaultColor} Send out a tweet"
135
+ puts "#{CommandColor}twitter show [username]#{DefaultColor} Show the timeline for a user"
133
136
  end
134
137
 
135
138
  # Show error message with help below it
@@ -149,9 +152,14 @@ module ConsoleTweet
149
152
  def load_default_token
150
153
  if tokens = load_tokens
151
154
  default_hash = tokens[:default]
152
- @client = TwitterOAuth::Client.new(:consumer_key => ConsumerKey, :consumer_secret => ConsumerSecret, :token => default_hash[:token], :secret => default_hash[:secret])
155
+ if default_hash[:token] && default_hash[:secret]
156
+ @client = TwitterOAuth::Client.new(:consumer_key => ConsumerKey, :consumer_secret => ConsumerSecret, :token => default_hash[:token], :secret => default_hash[:secret])
157
+ end
153
158
  default_hash
159
+ else
160
+ @client = TwitterOAuth::Client.new(:consumer_key => ConsumerKey, :consumer_secret => ConsumerSecret)
154
161
  end
162
+
155
163
  end
156
164
 
157
165
  # Load tokens from the ~/.twitter file
@@ -188,6 +196,14 @@ module ConsoleTweet
188
196
  save_tokens(:default => tokens)
189
197
  end
190
198
 
199
+ # Standardized formating of timelines
200
+ def print_tweets(tweets)
201
+ tweets.reverse!
202
+ tweets.each do |tweet|
203
+ puts "#{tweet['text']}\n#{NameColor}@#{tweet['user']['screen_name']} (#{tweet['user']['name']})#{DefaultColor}\n\n"
204
+ end
205
+ end
206
+
191
207
  end
192
208
 
193
209
  end
@@ -1,5 +1,5 @@
1
1
  module ConsoleTweet
2
2
 
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,49 +1,46 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: console_tweet
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
4
5
  prerelease:
5
- version: 0.1.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - John Crepezzi
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-05-20 00:00:00 -04:00
12
+ date: 2011-07-31 00:00:00.000000000 -04:00
14
13
  default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
17
16
  name: rspec
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &70328169435640 !ruby/object:Gem::Requirement
20
18
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
25
23
  type: :development
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: twitter_oauth
29
24
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *70328169435640
26
+ - !ruby/object:Gem::Dependency
27
+ name: twitter_oauth
28
+ requirement: &70328169435120 !ruby/object:Gem::Requirement
31
29
  none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- version: "0"
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
36
34
  type: :runtime
37
- version_requirements: *id002
35
+ prerelease: false
36
+ version_requirements: *70328169435120
38
37
  description: CLI Twitter Client - with OAuth
39
38
  email: john@crepezzi.com
40
- executables:
39
+ executables:
41
40
  - twitter
42
41
  extensions: []
43
-
44
42
  extra_rdoc_files: []
45
-
46
- files:
43
+ files:
47
44
  - lib/console_tweet/cli.rb
48
45
  - lib/console_tweet/version.rb
49
46
  - lib/console_tweet.rb
@@ -51,30 +48,26 @@ files:
51
48
  has_rdoc: true
52
49
  homepage: http://seejohnrun.github.com/console_tweet/
53
50
  licenses: []
54
-
55
51
  post_install_message:
56
52
  rdoc_options: []
57
-
58
- require_paths:
53
+ require_paths:
59
54
  - lib
60
- required_ruby_version: !ruby/object:Gem::Requirement
55
+ required_ruby_version: !ruby/object:Gem::Requirement
61
56
  none: false
62
- requirements:
63
- - - ">="
64
- - !ruby/object:Gem::Version
65
- version: "0"
66
- required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
62
  none: false
68
- requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- version: "0"
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
72
67
  requirements: []
73
-
74
68
  rubyforge_project: console_tweet
75
69
  rubygems_version: 1.6.2
76
70
  signing_key:
77
71
  specification_version: 3
78
72
  summary: CLI Twitter Client
79
73
  test_files: []
80
-