Class: RTMShell
- Inherits:
-
Object
- Object
- RTMShell
- Defined in:
- lib/rtm-shell.rb
Constant Summary collapse
- RTM_API_KEY =
"a3b06fba6c10dc78b6e5bde93dc6be41"- RTM_SHARED_SECRET =
"e771be2641870ace"
Instance Method Summary collapse
- #authentification ⇒ Object
- #dispatch(command) ⇒ Object
-
#initialize ⇒ RTMShell
constructor
A new instance of RTMShell.
Constructor Details
#initialize ⇒ RTMShell
Returns a new instance of RTMShell.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rtm-shell.rb', line 16 def initialize @rtm = RememberTheMilk.new(RTM_API_KEY, RTM_SHARED_SECRET) puts "ok1" @cmd = RCommand.new($stdin, $stdout) ["exit", "end", "quit", "lists"].each {|c| @cmd << c} authentification loop do @cmd.prompt = "RTM:> " dispatch(@cmd.readline) end end |
Instance Method Details
#authentification ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rtm-shell.rb', line 30 def authentification # Create config-dir if not exist Dir::mkdir(ENV['HOME']+ "/.rtm-shell") unless File::exists?(ENV['HOME']+"/.rtm-shell") # Authentification begin # Try to read the token from token.rtm puts "testing ..." @rtm.auth_token = File.new(ENV['HOME']+ "/.rtm-shell/token", "r").gets.chomp @rtm.user rescue RememberTheMilkAPIError => e p e # The token is not valid puts "There is a problem with your token. Please restart the program to do the authorize-process again." File.delete(ENV['HOME']+ "/.rtm-shell/token") exit rescue Exception => e p e # Auth the user puts "Please authorize this program to use your rtm-data by opening the following url and put the frob value back in here." puts @rtm.auth_url frob = gets auth = @rtm.auth.getToken('frob' => frob.chomp) token_file = File.new(ENV['HOME']+ "/.rtm-shell/token", "w+") token_file << auth.token puts "Restart the programm now." exit end end |
#dispatch(command) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rtm-shell.rb', line 62 def dispatch(command) params = command.split(" ") c = params.shift exit if c =~ /^(exit|end|quit)$/ rtmc = RTMCommands.new(@rtm) # Some introspection exec = false rtmc.methods.find { |m| if m == c print rtmc.method(c).call(*params) exec = true end } if !exec then print "Command not found.\n" end end |