Module: Tweet

Defined in:
lib/tweet.rb

Constant Summary collapse

CONFIG_FILE =
ENV['HOME']+'/.tweet'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.passwordObject

Returns the value of attribute password.



10
11
12
# File 'lib/tweet.rb', line 10

def password
  @password
end

.usernameObject

Returns the value of attribute username.



10
11
12
# File 'lib/tweet.rb', line 10

def username
  @username
end

Class Method Details

.create_status(status, just_count = false) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/tweet.rb', line 12

def create_status(status, just_count = false)
  len = status.length
  if just_count
    puts "Counting... #{len} chars"
    exit 0 
  end

  abort "Message limit is 140 characters. You currently have #{len}" if len > 140
  get_credentials!

  if @debug
    puts "Would have tweeted:", status
  else
    resource = RestClient::Resource.new 'http://twitter.com/statuses/update.xml', username, password
    resource.post(:status => status, :source => 'tweetgem', :content_type => 'application/xml', :accept => 'application/xml')
  end
  puts "#{len} chars" + (len == 140 ? "!\nYou rock!" : '.')
end

.get_credentials!Object



31
32
33
34
35
36
# File 'lib/tweet.rb', line 31

def get_credentials!
  abort "You must create a #{CONFIG_FILE} file to use this CLI." unless File.exist?(CONFIG_FILE)
  config = YAML.load(File.read(CONFIG_FILE)).symbolize_keys
  @username, @password, @debug = config[:username], config[:password], config[:debug]
  warn "  debug mode (not really posting)" if @debug
end