/ Published in: Ruby
This command allows you to browse your snippet collection on Snipplr and retrieve them into e. Requires the installation of the wxCocoaDialog exe in the /Support/bin subdirectory.
Replace YOUR_API_KEY_HERE with the API key -- you can find it on your Settings page (http://snipplr.com/settings/).
Update 1/31/2007: I found escaping the $ was necessary to prevent the snippet engine from eating the variable.
Update 2/01/2007: Use the standard library function for escaping the snippet (instead of my own gsub() regex.
Update 2/02/2007: Add error checking code; handle empty accounts a bit more gracefully (and informatively).
Replace YOUR_API_KEY_HERE with the API key -- you can find it on your Settings page (http://snipplr.com/settings/).
Update 1/31/2007: I found escaping the $ was necessary to prevent the snippet engine from eating the variable.
Update 2/01/2007: Use the standard library function for escaping the snippet (instead of my own gsub() regex.
Update 2/02/2007: Add error checking code; handle empty accounts a bit more gracefully (and informatively).
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/usr/bin/env ruby -w require "xmlrpc/client" require "cgi" require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes.rb" require ENV['TM_SUPPORT_PATH'] + "/lib/escape.rb" COCOA_DIALOG = ENV['TM_SUPPORT_PATH'] + '/bin/CocoaDialog' API_KEY = "YOUR_API_KEY_HERE" server = XMLRPC::Client.new( "snipplr.com", "/xml-rpc.php") if 0 == server.call("user.checkkey", API_KEY) puts "#{API_KEY} was not accepted as a valid API Key" TextMate.exit_show_tool_tip end begin result = server.call("snippet.list", API_KEY) result_list = "" result.each { |row| result_list += "'#{row['id']} : #{row['title']}' " } res=%x("#{COCOA_DIALOG}" dropdown \ --title "Retrieve Snippet" \ --string-output \ --text "You have #{result.length} Snipplr entries stored under this API Key." \ --items #{result_list} \ --button1 'Retreive' --button2 'Cancel') button, item = res.split case button when 'Retreive' $snippet = server.call("snippet.get", item) when 'Cancel' puts "Snippet retreival cancelled." TextMate.exit_show_tool_tip end puts e_sn(CGI::unescapeHTML($snippet['source'])) rescue XMLRPC::FaultException => err if err.faultString =~ /No snippets found/ print "You don't have any snippets yet!" else print "Error: " + err.faultCode.to_s + ", " + err.faultString end TextMate.exit_show_tool_tip rescue print "Error: #{$!}" TextMate.exit_show_tool_tip end