Snipplr API ruby库

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Snipplr API ruby库相关的知识,希望对你有一定的参考价值。

  1. module SnipplrAPI
  2. require 'xmlrpc/client'
  3.  
  4. API_URL = "http://snipplr.com/xml-rpc.php"
  5. class Snipplr
  6. attr_accessor :api_key
  7.  
  8. def initialize(key)
  9. @api_key = key
  10. @server = XMLRPC::Client::new2(SnipplrAPI::API_URL)
  11. end
  12.  
  13. def list(tags="", sort="", limit="")
  14. cmd = "snippet.list"
  15. result = @server.call(cmd, @api_key, tags, sort, limit)
  16. end
  17.  
  18. def get(snippet_id)
  19. cmd = "snippet.get"
  20. result = @server.call(cmd, snippet_id)
  21. end
  22.  
  23. def post(title,code,tags="",language="")
  24. cmd = "snippet.post"
  25. result = @server.call(cmd, @api_key, title, code, tags, language)
  26. end
  27.  
  28. def delete(snippet_id)
  29. cmd = "snippet.delete"
  30. result = @server.call(cmd, @api_key, snippet_id)
  31. end
  32.  
  33. def checkkey(api_key)
  34. cmd = "user.checkkey"
  35. result = @server.call(cmd, api_key)
  36. end
  37.  
  38. def languages()
  39. cmd = "languages.list"
  40. result = @server.call(cmd)
  41. end
  42.  
  43. end
  44. end
  45.  
  46. # =========================================
  47. # Testing: Do not include in class file
  48. # =========================================
  49. require 'pp' #used to Pretty Print results not required to use above module
  50.  
  51. # Replace YOUR_API_KEY below with your assigned API key
  52. # can be found at snipplr.com at http://snipplr.com/settings/
  53. # at the bottom of the page.
  54.  
  55. key = "YOUR_API_KEY"
  56. snipplr = SnipplrAPI::Snipplr.new(key)
  57.  
  58. # list your snippets
  59. pp snippets.list
  60.  
  61. # list only snippets tagged with php or xml
  62. #pp snipplr.list("PHP")

以上是关于Snipplr API ruby库的主要内容,如果未能解决你的问题,请参考以下文章

使用 octokit ruby​​ toolkit for github api 获取存储库名称

TextMate Ruby代码段发布

TextMate Ruby代码段检索

为 Java、Python、Ruby、Node.JS 和 PHP 开放支付网关库

在 chef lwrp 中安装、要求和使用 ruby​​ 库

如何使用Rugged ruby gem拉出git存储库