Module: Twiq::Commands

Extended by:
OAuth::CLI::Twitter, Commands
Included in:
Commands
Defined in:
lib/twiq/commands.rb

Constant Summary collapse

CONSUMER_KEY =
'9gu06q0SOcJLOwKpAeaClA'
CONSUMER_SECRET =
'K8Kb6JpfRkzjQl4IRn2CWbCL67rEtO0mSeoqKCQdSFQ'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#stdinObject

Returns the value of attribute stdin.



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

def stdin
  @stdin
end

#stdoutObject

Returns the value of attribute stdout.



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

def stdout
  @stdout
end

Instance Method Details

#clear(args) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/twiq/commands.rb', line 41

def clear(args)
  if args.size == 0
    Statuses.delete
  else
    args.each do |arg|
      case arg
      when String  then key = :user
      when Integer then key = :id
      else next
      end
      Statuses[key => arg].delete
    end
  end
end

#deq(args) ⇒ Object

Raises:



25
26
27
28
29
30
31
# File 'lib/twiq/commands.rb', line 25

def deq(args)
  raise Error, 'user not specified.' if args.size == 0
  s = Statuses.filter(:user => args[0]).first
  Statuses.filter(:id => s[:id]).delete
  at = get_access_token(CONSUMER_KEY, CONSUMER_SECRET, :pit => 'twiq-' + s[:user])
  at.post('/statuses/update.json', 'status' => s[:text])
end

#enq(args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/twiq/commands.rb', line 12

def enq(args)
  case args.size
  when 0
    raise Error, 'arguments required (at least 1)'
  when 1
    while text = stdin.gets
      Statuses.insert(:user => args[0], :text => text)
    end
  else
    Statuses.insert(:user => args[0], :text => args[1])
  end
end

#list(args) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/twiq/commands.rb', line 33

def list(args)
  statuses = args.size > 0 ? Statuses.filter(:user => args[0]) : Statuses.all
  stdout.puts "id\tuser\ttext"
  statuses.each do |s|
    stdout.puts "#{s[:id]}\t#{s[:user]}\t#{s[:text]}"
  end
end