Class: CliBlog

Inherits:
Object
  • Object
show all
Defined in:
lib/cliblog.rb

Instance Method Summary collapse

Constructor Details

#initialize(conf) ⇒ CliBlog

Returns a new instance of CliBlog.



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cliblog.rb', line 34

def initialize(conf)
  @blogid = conf.blogid
  server  = URI.parse(conf.url)
  proxy   = Struct.new(:host, :port).new
  if ENV.has_key? 'http_proxy' then
    proxy = URI.parse(ENV['http_proxy'])
    proxy.host = proxy.host
    proxy.port = proxy.port
  end
  @xmlrpc = XMLRPC::Client.new(server.host, server.path, server.port,
                               proxy.host, proxy.port)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(cmd, *arg) ⇒ Object



55
56
57
58
# File 'lib/cliblog.rb', line 55

def method_missing(cmd, *arg)
  @arg = *arg
  send("_#{cmd.to_s}".to_sym) if COMMANDS.include? cmd.to_s
end

Instance Method Details

#command_loopObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/cliblog.rb', line 59

def command_loop
  cmd = arg = nil
  loop do
    print_commands
    case input = ask(">> ")
    when /^(exit|q|quit)/ then break
    when /^(\d+)/
      cmd = 'view'
      arg = $1
    else
      cmd, arg = input.split(' ', 2)
      cmd ||= 'list'
    end
    send(cmd.to_sym, arg)
  end
end

#loginObject



46
47
48
49
50
51
52
53
54
# File 'lib/cliblog.rb', line 46

def 
  @username = ask('Username: ')
  @password = ask('Password: ') {|q| q.echo = false }
  begin
    _list
  rescue XMLRPC::FaultException => e
    raise "Cannot login"
  end
end