Revision: 2292
Updated Code
at February 5, 2007 23:13 by gtcaz
Updated Code
#!/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
Revision: 2291
Updated Code
at February 2, 2007 14:10 by gtcaz
Updated Code
#!/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."
exit
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
Revision: 2290
Updated Code
at February 2, 2007 11:55 by gtcaz
Updated Code
#!/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'
unless File.exists?(COCOA_DIALOG)
print "Error: wxCocoaDialog not found"
TextMate.exit_show_tool_tip
end
# Need to hardcode the variable until we get
# environment variables in e.
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."
exit
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
Revision: 2289
Updated Code
at February 1, 2007 10:42 by gtcaz
Updated Code
#!/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'
unless File.exists?(COCOA_DIALOG)
print "Error: wxCocoaDialog not found"
TextMate.exit_show_tool_tip
end
# Need to hardcode the variable until we get
# environment variables in e.
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
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."
exit
end
puts e_sn(CGI::unescapeHTML($snippet['source']))
Revision: 2288
Updated Code
at January 31, 2007 21:01 by gtcaz
Updated Code
#!/usr/bin/env ruby -w
require "xmlrpc/client"
require "cgi"
require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes.rb"
COCOA_DIALOG = ENV['TM_SUPPORT_PATH'] + '/bin/CocoaDialog'
unless File.exists?(COCOA_DIALOG)
print "Error: wxCocoaDialog not found"
TextMate.exit_show_tool_tip
end
# Need to hardcode the variable until we get
# environment variables in e.
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
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."
exit
end
puts CGI::unescapeHTML($snippet['source']).gsub(/\$/, '\\\$')
Revision: 2287
Updated Code
at January 31, 2007 20:56 by gtcaz
Updated Code
#!/usr/bin/env ruby -w
require "xmlrpc/client"
require "cgi"
require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes.rb"
COCOA_DIALOG = ENV['TM_SUPPORT_PATH'] + '/bin/CocoaDialog'
unless File.exists?(COCOA_DIALOG)
print "Error: wxCocoaDialog not found"
TextMate.exit_show_tool_tip
end
# Need to hardcode the variable until we get
# environment variables in e.
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
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."
exit
end
puts CGI::unescapeHTML($snippet['source']).gsub(/\$/, '\\\$')
Revision: 2286
Updated Code
at January 31, 2007 20:52 by gtcaz
Updated Code
#!/usr/bin/env ruby -w
require "xmlrpc/client"
require "cgi"
require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes.rb"
COCOA_DIALOG = ENV['TM_SUPPORT_PATH'] + '/bin/CocoaDialog'
unless File.exists?(COCOA_DIALOG)
print "Error: wxCocoaDialog not found"
TextMate.exit_show_tool_tip
end
# Need to hardcode the variable until we get
# environment variables in e.
API_KEY = "75f0f2d2dd80cf39e69a"
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
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."
exit
end
puts CGI::unescapeHTML($snippet['source']).gsub(/\$/, '\\\$')
Revision: 2285
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 30, 2007 15:26 by gtcaz
Initial Code
#!/usr/bin/env ruby -w
require "xmlrpc/client"
require "cgi"
require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes.rb"
COCOA_DIALOG = ENV['TM_SUPPORT_PATH'] + '/bin/CocoaDialog.exe'
unless File.exists?(COCOA_DIALOG)
print "Error: wxCocoaDialog not found"
TextMate.exit_show_tool_tip
end
# Need to hardcode the variable until we get
# environment variables in e.
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
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."
exit
end
puts CGI::unescapeHTML($snippet['source'])
Initial URL
Initial Description
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).
Initial Title
Get one of your snippets from Snipplr
Initial Tags
command
Initial Language
Ruby