Revision: 10832
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 15, 2009 13:47 by dbug13
Initial Code
module SnipplrAPI
require 'xmlrpc/client'
API_URL = "http://snipplr.com/xml-rpc.php"
class Snipplr
attr_accessor :api_key
def initialize(key)
@api_key = key
@server = XMLRPC::Client::new2(SnipplrAPI::API_URL)
end
def list(tags="", sort="", limit="")
cmd = "snippet.list"
result = @server.call(cmd, @api_key, tags, sort, limit)
end
def get(snippet_id)
cmd = "snippet.get"
result = @server.call(cmd, snippet_id)
end
def post(title,code,tags="",language="")
cmd = "snippet.post"
result = @server.call(cmd, @api_key, title, code, tags, language)
end
def delete(snippet_id)
cmd = "snippet.delete"
result = @server.call(cmd, @api_key, snippet_id)
end
def checkkey(api_key)
cmd = "user.checkkey"
result = @server.call(cmd, api_key)
end
def languages()
cmd = "languages.list"
result = @server.call(cmd)
end
end
end
# =========================================
# Testing: Do not include in class file
# =========================================
require 'pp' #used to Pretty Print results not required to use above module
# Replace YOUR_API_KEY below with your assigned API key
# can be found at snipplr.com at http://snipplr.com/settings/
# at the bottom of the page.
key = "YOUR_API_KEY"
snipplr = SnipplrAPI::Snipplr.new(key)
# list your snippets
pp snippets.list
# list only snippets tagged with php or xml
#pp snipplr.list("PHP")
Initial URL
Initial Description
Initial Title
Snipplr API ruby library
Initial Tags
ruby, api
Initial Language
Ruby