有没有办法使用net/http
或net/https
创建匿名(公共或私人)主旨?从Ruby脚本创建Gist
回答
这对我有效。
require 'net/http'
require 'json'
uri = URI("https://api.github.com/gists")
payload = {
'description' => "My test gist",
'public' => true,
'files' => {
'test.txt' => {
'content' => "This is a test!\n\nI am making a public gist."
}
}
}
req = Net::HTTP::Post.new(uri.path)
req.body = payload.to_json
puts req.inspect
puts req.body.inspect
# GitHub API is strictly via HTTPS, so SSL is mandatory
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) do |http|
http.request(req)
end
puts res.inspect
puts res.body.inspect
结果:My test gist
这个宝石将为你做诡计https://github.com/defunkt/gist!
为了记录,它确实需要net/https。
我的问题是,我想只是为了不增加整体的依赖在增加我的一个创业板的小功能。 – 2013-05-03 18:46:25
http://www.travisberry.com/2011/05/create-github-gist-with-ruby/ - 这应该做的伎俩然后。 – baordog 2013-05-03 18:50:58
这是Gtihub API的指南v1 – 2013-05-03 18:53:15
- 1. 从脚本创建EventSystem
- 2. 创建脚本
- 3. 创建脚本PDF创建
- 4. 从Ruby运行sql脚本
- 5. 从Maven运行Ruby脚本
- 6. 从cron执行ruby脚本
- 7. 试图从Ruby脚本
- 8. 从Ruby调用脚本php
- 9. SQL脚本创建
- 10. 从sql脚本创建种子数据
- 11. 从sql脚本创建mdf文件
- 12. Unity从脚本创建UI控制
- 13. 从文件中创建CSV的脚本
- 14. 创建Shell脚本数据库 - 从PHP
- 15. 从VB脚本创建文档代码
- 16. 从Extendscript Toolkit创建外壳脚本
- 17. SQL从DBMS创建表脚本包含[]
- 18. 从脚本创建并填充HSQLDB
- 19. CloudFormation脚本 - 从AMI创建实例
- 20. 如何从服务器创建脚本
- 21. bash脚本创建脚本变量
- 22. 如何从现有脚本创建shell脚本?
- 23. bash:如何_best_从另一个脚本创建脚本
- 24. 从脚本块动态创建PowerShell脚本块
- 25. 从SQL创建表脚本的Rails迁移脚本
- 26. 需要创建一个脚本,从CSV创建目录结构
- 27. 创建一个运行Ruby脚本的批处理文件
- 28. AppArmor配置文件创建为Ruby脚本
- 29. Ruby on Rails:不再创建迁移脚本
- 30. 在Ruby on Rails中创建对象之后运行脚本
非常感谢:) – 2013-05-03 19:36:32
有什么办法可以使用Net :: HTTP.post_form(...)来做这个调用吗? – 2014-02-14 05:40:15