console_tweet 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/twitter CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../lib/console_tweet'
2
+
3
+ require 'rubygems'
4
+ require 'console_tweet'
3
5
 
4
6
  console = ConsoleTweet::CLI.new
5
7
  console.start
data/lib/console_tweet.rb CHANGED
@@ -1,5 +1,5 @@
1
- module ConsoleTweet
1
+ require 'lib/console_tweet'
2
2
 
3
- require 'lib/console_tweet/cli'
3
+ module ConsoleTweet
4
4
 
5
5
  end
@@ -6,23 +6,30 @@ module ConsoleTweet
6
6
  require 'twitter_oauth'
7
7
  require 'yaml'
8
8
 
9
+ # The allowed API methods
9
10
  AllowedMethods = [:setup, :help, :status, :tweet]
11
+
12
+ # Twitter API details
10
13
  ConsumerKey = 'MvVdCyl6xCVtEUVdcp4rw'
11
14
  ConsumerSecret = '3xD0oy47WhWYUIBCU6QzcIBqsrAAL3KnYWKhd6ALk2k'
12
15
 
16
+ # Where to store the .twitter file
13
17
  TOKEN_PATH = File.expand_path('~/.twitter')
14
18
 
19
+ # Some colors used in the output
15
20
  NameColor = "\e[33m"
16
21
  CommandColor = "\e[36m"
17
22
  DefaultColor = "\e[0m"
18
- NoteColor = "\e[37m"
19
23
  ErrorColor = "\e[31m"
20
24
 
25
+ # By default there are no arguments and no commands
21
26
  def initialize
22
27
  @commands = []
23
28
  @arguments = {}
24
29
  end
25
30
 
31
+ # Get the commands from the command line
32
+ # (Somewhat primitive, will be expanded) TODO
26
33
  def start
27
34
  ARGV.each do |arg|
28
35
  unless arg.index('-') === 0
@@ -50,6 +57,7 @@ module ConsoleTweet
50
57
  end
51
58
  end
52
59
 
60
+ # Send a tweet for the user
53
61
  def tweet(*args)
54
62
  load_default_token
55
63
  return failtown("Unauthorized, re-run setup!") unless @client.authorized?
@@ -57,6 +65,7 @@ module ConsoleTweet
57
65
  puts "Tweet Posted!"
58
66
  end
59
67
 
68
+ # Get the user's most recent status
60
69
  def status(*args)
61
70
  load_default_token
62
71
  return failtown("Unauthorized, re-run setup!") unless @client.authorized?
@@ -65,6 +74,7 @@ module ConsoleTweet
65
74
  puts "#{user['name']} (at #{status['created_at']}) #{status['text']}"
66
75
  end
67
76
 
77
+ # Get the access token for the user and save it
68
78
  def setup(*args)
69
79
  # Keep trying to get the access token
70
80
  until @access_token = self.get_access_token
@@ -76,32 +86,37 @@ module ConsoleTweet
76
86
  save_tokens(tokens)
77
87
  end
78
88
 
89
+ # Display help section
79
90
  def help(*args)
80
91
  puts "#{NameColor}console-tweet#{DefaultColor} by John Crepezzi <john.crepezzi@gmail.com>"
81
- puts 'github: http://github.com/seejohnrun/console-tweet'
92
+ puts 'http://github.com/seejohnrun/console-tweet'
82
93
  puts
83
94
  puts "#{CommandColor}twitter setup#{DefaultColor} Setup your account"
84
95
  puts "#{CommandColor}twitter status#{DefaultColor} Get your most recent status"
85
96
  puts "#{CommandColor}twitter tweet \"Hello World\"#{DefaultColor} Send out a tweet"
86
97
  end
87
98
 
99
+ # Show error message with help below it
88
100
  def failtown(message = nil)
89
101
  puts "#{ErrorColor}Uh-oh! #{message}#{DefaultColor}\n" if message
90
102
  help
91
103
  end
92
104
 
105
+ # Catch other methods
93
106
  def method_missing(command, *arguments)
94
107
  failtown "Unknown command: #{command}\n"
95
108
  end
96
109
 
97
110
  private
98
111
 
112
+ # Load the default token from the ~/.twitter file
99
113
  def load_default_token
100
114
  tokens = load_tokens
101
115
  default_hash = tokens[:default]
102
116
  @client = TwitterOAuth::Client.new(:consumer_key => ConsumerKey, :consumer_secret => ConsumerSecret, :token => default_hash[:token], :secret => default_hash[:secret])
103
117
  end
104
118
 
119
+ # Load tokens from the ~/.twitter file
105
120
  def load_tokens
106
121
  f = File.open(TOKEN_PATH, 'r')
107
122
  tokens = YAML::load(f)
@@ -109,12 +124,14 @@ module ConsoleTweet
109
124
  tokens
110
125
  end
111
126
 
127
+ # Save the set of tokens to the ~/.twitter file
112
128
  def save_tokens(tokens)
113
129
  f = File.open(TOKEN_PATH, 'w')
114
130
  YAML::dump(tokens, f)
115
131
  f.close
116
132
  end
117
133
 
134
+ # Get input from STDIN, strip it and cut the newline off the end
118
135
  def self.get_input
119
136
  STDIN.gets.strip.chomp
120
137
  end
@@ -1,3 +1,5 @@
1
+ require 'console_tweet/cli'
2
+
1
3
  module ConsoleTweet
2
4
 
3
5
  end
@@ -1,5 +1,5 @@
1
1
  module ConsoleTweet
2
2
 
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console_tweet
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Crepezzi