Snipplr API ruby库
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Snipplr API ruby库相关的知识,希望对你有一定的参考价值。
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")
以上是关于Snipplr API ruby库的主要内容,如果未能解决你的问题,请参考以下文章
使用 octokit ruby toolkit for github api 获取存储库名称
为 Java、Python、Ruby、Node.JS 和 PHP 开放支付网关库