Return to Snippet

Revision: 2298
at February 2, 2007 14:07 by gtcaz


Updated Code
#!/usr/bin/env ruby -w
require "xmlrpc/client"
require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes.rb"

code = STDIN.read
COCOA_DIALOG = ENV['TM_SUPPORT_PATH'] + '/bin/CocoaDialog.exe'
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

title_bx = %x("#{COCOA_DIALOG}" standard-inputbox \
    --title "Snippet Name" \
    --no-newline \
    --informative text "Enter a name for your new snippet:" )
button, title = title_bx.split("\n")
TextMate.exit_discard if "2" == button || title.nil?
languages = server.call("languages.list")
langs_arr = []
languages.each_value{|k| langs_arr.push(k)} 
language_list = ""
langs_arr.sort.each{ |k| language_list += "'#{k}' "}

lang_bx = %x("#{COCOA_DIALOG}" dropdown \
  --string-output --no-newline \
  --title "Snippet Language" \
  --text "Please choose a language for you snippet:" \
  --items  #{language_list} \
  --button1 "Accept" --button2 "Cancel")
button, language_selection = lang_bx.split("\n")
TextMate.exit_discard if "Cancel" == button
language = languages.index(language_selection)

tags_bx = %x("#{COCOA_DIALOG}" standard-inputbox \
  --no-newline \
  --title "Snippet Tags" \
  --informative text "Enter A space delimited list of keywords:" )
button, tags = tags_bx.split("\n")
TextMate.exit_discard if "2" == button
tags = "" if tags.nil?

server.call("snippet.post", API_KEY, title, code, tags, language)
puts "Added your snippet!"

Revision: 2297
at February 2, 2007 14:02 by gtcaz


Updated Code
#!/usr/bin/env ruby -w
require "xmlrpc/client"
require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes.rb"

code = STDIN.read

# Need to hardcode API_KEY 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

title_bx = %x("#{COCOA_DIALOG}" standard-inputbox \
    --title "Snippet Name" \
    --no-newline \
    --informative text "Enter a name for your new snippet:" )
button, title = title_bx.split("\n")
TextMate.exit_discard if "2" == button || title.nil?
languages = server.call("languages.list")
langs_arr = []
languages.each_value{|k| langs_arr.push(k)} 
language_list = ""
langs_arr.sort.each{ |k| language_list += "'#{k}' "}

lang_bx = %x("#{COCOA_DIALOG}" dropdown \
  --string-output --no-newline \
  --title "Snippet Language" \
  --text "Please choose a language for you snippet:" \
  --items  #{language_list} \
  --button1 "Accept" --button2 "Cancel")
button, language_selection = lang_bx.split("\n")
TextMate.exit_discard if "Cancel" == button
language = languages.index(language_selection)

tags_bx = %x("#{COCOA_DIALOG}" standard-inputbox \
  --no-newline \
  --title "Snippet Tags" \
  --informative text "Enter A space delimited list of keywords:" )
button, tags = tags_bx.split("\n")
TextMate.exit_discard if "2" == button
tags = "" if tags.nil?

server.call("snippet.post", API_KEY, title, code, tags, language)
puts "Added your snippet!"

Revision: 2296
at February 2, 2007 13:39 by gtcaz


Updated Code
#!/usr/bin/env ruby -w
require "xmlrpc/client"
require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes.rb"

code = STDIN.read

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

title_bx = %x("#{COCOA_DIALOG}" standard-inputbox \
    --title "Snippet Name" \
    --no-newline \
    --informative text "Enter a name for your new snippet:" )
button, title = title_bx.split("\n")
TextMate.exit_discard if "2" == button.chomp
languages = server.call("languages.list")
langs_arr = []
languages.each_value{|k| langs_arr.push(k)} 
language_list = ""
langs_arr.sort.each{ |v| language_list += "'#{v}' "}

lang_bx = %x("#{COCOA_DIALOG}" dropdown \
  --string-output --no-newline \
  --title "Snippet Language" \
  --text "Please choose a language for you snippet:" \
  --items  #{language_list} \
  --button1 "Accept" --button2 "Cancel")
button, language_selection = lang_bx.split("\n")
button.chomp! and language_selection.chomp!
TextMate.exit_discard if "Cancel" == button
language = languages.index(language_selection)

tags_bx = %x("#{COCOA_DIALOG}" standard-inputbox \
  --no-newline \
  --title "Snippet Tags" \
  --informative text "Enter A space delimited list of keywords:" )
button, tags = tags_bx.split("\n")
TextMate.exit_discard if "2" == button.chomp
tags = "" if tags.nil?
server.call("snippet.post", API_KEY, title, code, tags, language)
puts "Added your snippet!"

Revision: 2295
at January 31, 2007 22:19 by gtcaz


Updated Code
#!/usr/bin/env ruby -w
require "xmlrpc/client"
require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes.rb"

code = STDIN.read

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

title_bx = %x("#{COCOA_DIALOG}" standard-inputbox \
    --title "Snippet Name" \
    --no-newline \
    --informative text "Enter a name for your new snippet:" )
button, title = title_bx.split("\n")
TextMate.exit_discard if "2" == button.chomp

languages = server.call("languages.list")
lang_names = ""
languages.each_value{|k| lang_names += "'#{k}' "}

lang_bx = %x("#{COCOA_DIALOG}" dropdown \
  --string-output --no-newline \
  --title "Snippet Language" \
  --text "Please choose a language for you snippet:" \
  --items  #{lang_names} \
  --button1 "Accept" --button2 "Cancel")
button, language_selection = lang_bx.split("\n")
button.chomp! and language_selection.chomp!
TextMate.exit_discard if "Cancel" == button
language = languages.index(language_selection)

tags_bx = %x("#{COCOA_DIALOG}" standard-inputbox \
  --no-newline \
  --title "Snippet Tags" \
  --informative text "Enter A space delimited list of keywords:" )
button, tags = tags_bx.split("\n")
TextMate.exit_discard if "2" == button.chomp

server.call("snippet.post", API_KEY, title, code, tags, language)
puts "Added your snippet!"

Revision: 2294
at January 30, 2007 20:27 by gtcaz


Updated Code
#!/usr/bin/env ruby -w
require "xmlrpc/client"
require "cgi"
require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes.rb"

code = CGI::escapeHTML(STDIN.read)

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

title_bx = %x("#{COCOA_DIALOG}" standard-inputbox \
    --title "Snippet Name" \
    --informative text "Enter a name for your new snippet:" )
button, title = title_bx.split("\n")
TextMate.exit_discard if "2" == button.chomp

tags_bx = %x("#{COCOA_DIALOG}" standard-inputbox \
    --title "Snippet Tags" \
    --informative text "Enter A space delimited list of keywords:" )
button, tags = tags_bx.split("\n")
TextMate.exit_discard if "2" == button.chomp


server.call("snippet.post", API_KEY, title, code, tags)
puts "Added your snippet!"

Revision: 2293
at January 30, 2007 20:26 by gtcaz


Initial Code
#!/usr/bin/env ruby -w
require "xmlrpc/client"
require "cgi"
require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes.rb"

code = CGI::escapeHTML(STDIN.read)

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

title_bx = %x("#{COCOA_DIALOG}" standard-inputbox \
    --title "Snippet Name" \
    --informative text "Enter a name for your new snippet:" )
button, title = title_bx.split("\n")
TextMate.exit_discard if "2" == button.chomp

tags_bx = %x("#{COCOA_DIALOG}" standard-inputbox \
    --title "Snippet Tags" \
    --informative text "Enter A space delimited list of keywords:" )
button, tags = tags_bx.split("\n")
TextMate.exit_discard if "2" == button.chomp


server.call("snippet.post", API_KEY, title, code, tags)
puts "Added your snippet!"

Initial URL


Initial Description
Alternative bundle command for e (http://www.e-texteditor.com) or TextMate.

Replace YOUR_API_KEY_HERE with a valid API key -- you can find it on your Settings page (http://snipplr.com/settings/).

Changed the command to allow selection of language.  (Thanks, Tyler!)  Also it was unnecessary to escape entities when posting to Snipplr, so that caused problems.  Please let me know if you have any issues with or suggestions for this command.  If you're using TextMate, you'll need to alter the path to CocoaDialog, and you might as well use an environment variable for the API Key.

2/2/2007: Fixed a bug that prevented posting snippets with no tags.  Languages are now sorted alphabetically.

Initial Title
Post snippet to Snipplr

Initial Tags
command

Initial Language
Ruby