Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby ';获取自述文件';API V3 github已转换_Ruby_Api_Github - Fatal编程技术网

Ruby ';获取自述文件';API V3 github已转换

Ruby ';获取自述文件';API V3 github已转换,ruby,api,github,Ruby,Api,Github,我需要获取Github repo的自述内容,我选择了“”API V3,但它的编码为base64: { "name": "README.rdoc", "path": "README.rdoc", "sha": "d21b593aedfa49030478ead89c4ac991268c75c0", "size": 4939, "url": "https://api.github.com/repos/lgs/paymill-on-rails/contents/README.rdoc

我需要获取Github repo的自述内容,我选择了“”API V3,但它的编码为base64:

{
  "name": "README.rdoc",
  "path": "README.rdoc",
  "sha": "d21b593aedfa49030478ead89c4ac991268c75c0",
  "size": 4939,
  "url": "https://api.github.com/repos/lgs/paymill-on-rails/contents/README.rdoc?ref=master",
  "html_url": "https://github.com/lgs/paymill-on-rails/blob/master/README.rdoc",
  "git_url": "https://api.github.com/repos/lgs/paymill-on-rails/git/blobs/d21b593aedfa49030478ead89c4ac991268c75c0",
  "type": "file",
  "content": "PT0gUGF5bWlsbCBvbiBSYWlscyA0LjAuMCAKClBheW1pbGwgc3Vic2NyaXB0\naW9ucyBvbiBSYWlscyA0LjAuMCBhbmQgcnVieS0yLjAuMC1wMjQ3LCB7ZGVw\nbG95ZWQgb24gSGVyb2t1fVtodHRwczovL3BheW1pbGwtb24tcmFpbHMuaGVy\nb2t1YXBwLmNvbV0uIFRoaXMgaXMgYmFzZWQgb24ge01hcmMgQi4nc31baHR0
...
...,
  "encoding": "base64",
  "_links": {
    "self": "https://api.github.com/repos/lgs/paymill-on-rails/contents/README.rdoc?ref=master",
    "git": "https://api.github.com/repos/lgs/paymill-on-rails/git/blobs/d21b593aedfa49030478ead89c4ac991268c75c0",
    "html": "https://github.com/lgs/paymill-on-rails/blob/master/README.rdoc"
  }
}
获取/转换“内容”的方法是什么:“PT0gUGF5bWlsbCBv…”为明文(非base64编码)

更新(仅用于跟踪目的):

Linuxios推出的解决方案在nice中也得到了很好的实施,如下所示:

Octokit.contents 'lgs/paymill-on-rails', :path => 'README.rdoc', :accept => 'application/vnd.github.html'
获取整个html和

Octokit.contents 'lgs/paymill-on-rails', :path => 'README.rdoc', :accept => 'application/vnd.github.V3.raw'
如果您只想要干净、原始的内容

2.0.0p247 :001 > require 'octokit'
 => true 
2.0.0p247 :002 > Octokit.contents 'lgs/paymill-on-rails', :path => 'README.rdoc', :accept => 'application/vnd.github.V3.raw'
 => "== Paymill on Rails 4.0.0 \n\nPaymill subscriptions on Rails 4.0.0 and ruby-2.0.0-p247, {deployed on Heroku}[https://paymill-on-rails.herokuapp.com]. This is based on {Marc B.'s}[https://github.com/apalancat] {work}[https://github.com/apalancat/paymill-rails].\n\n== Usage\n\nRegister for a test account at {paymill.com}[https://paymill.com/] and create the subscription plans, also called Offers.\n\nSetup the app:\n\n    bundle\n    rake db:migrate\n    \n    \nReplace the test keys in \n\n   config/initializers/paymill.rb \n\nfor your own paymill API keys.\n\nTo get the plans and their IDs from paymill into the app run:\n\n    rake paymill:import_plans\n\nThat's it! Run \n\n    rails server\n\nand it should work.\n\n== Deploy on Heroku\n\nFrom rails app's root directory path run \n\n   heroku config:add BUNDLE_WITHOUT=\"development:test\"\n   heroku rake db:migrate\n   heroku rake paymill:import_plans\n\n== Current Bundle\n\nGEM\n  remote: https://rubygems.org/\n  specs:\n    actionmailer (4.0.0)\n      actionpack (= 4.0.0)\n      mail (~> 2.5.3)\n    actionpack (4.0.0)\n      activesupport (= 4.0.0)\n      builder (~> 3.1.0)\n      erubis (~> 2.7.0)\n      rack (~> 1.5.2)\n      rack-test (~> 0.6.2)\n    activemodel (4.0.0)\n      activesupport (= 4.0.0)\n      builder (~> 3.1.0)\n    activerecord (4.0.0)\n      activemodel (= 4.0.0)\n      activerecord-deprecated_finders (~> 1.0.2)\n      activesupport (= 4.0.0)\n      arel (~> 4.0.0)\n    activerecord-deprecated_finders (1.0.3)\n    activesupport (4.0.0)\n      i18n (~> 0.6, >= 0.6.4)\n      minitest (~> 4.2)\n      multi_json (~> 1.3)\n      thread_safe (~> 0.1)\n      tzinfo (~> 0.3.37)\n    arel (4.0.0)\n    atomic (1.1.12)\n    builder (3.1.4)\n    coffee-rails (4.0.0)\n      coffee-script (>= 2.2.0)\n      railties (>= 4.0.0.beta, < 5.0)\n    coffee-script (2.2.0)\n      coffee-script-source\n      execjs\n    coffee-script-source (1.6.3)\n    erubis (2.7.0)\n    execjs (1.4.0)\n      multi_json (~> 1.0)\n    hike (1.2.3)\n    i18n (0.6.4)\n    jbuilder (1.5.0)\n      activesupport (>= 3.0.0)\n      multi_json (>= 1.2.0)\n    jquery-rails (3.0.4)\n      railties (>= 3.0, < 5.0)\n      thor (>= 0.14, < 2.0)\n    json (1.8.0)\n    mail (2.5.4)\n      mime-types (~> 1.16)\n      treetop (~> 1.4.8)\n    mime-types (1.23)\n    minitest (4.7.5)\n    multi_json (1.7.8)\n    paymill (0.3.0)\n      json\n    polyglot (0.3.3)\n    rack (1.5.2)\n    rack-test (0.6.2)\n      rack (>= 1.0)\n    rails (4.0.0)\n      actionmailer (= 4.0.0)\n      actionpack (= 4.0.0)\n      activerecord (= 4.0.0)\n      activesupport (= 4.0.0)\n      bundler (>= 1.3.0, < 2.0)\n      railties (= 4.0.0)\n      sprockets-rails (~> 2.0.0)\n    railties (4.0.0)\n      actionpack (= 4.0.0)\n      activesupport (= 4.0.0)\n      rake (>= 0.8.7)\n      thor (>= 0.18.1, < 2.0)\n    rake (10.1.0)\n    rdoc (3.12.2)\n      json (~> 1.4)\n    sass (3.2.10)\n    sass-rails (4.0.0)\n      railties (>= 4.0.0.beta, < 5.0)\n      sass (>= 3.1.10)\n      sprockets-rails (~> 2.0.0)\n    sdoc (0.3.20)\n      json (>= 1.1.3)\n      rdoc (~> 3.10)\n    sprockets (2.10.0)\n      hike (~> 1.2)\n      multi_json (~> 1.0)\n      rack (~> 1.0)\n      tilt (~> 1.1, != 1.3.0)\n    sprockets-rails (2.0.0)\n      actionpack (>= 3.0)\n      activesupport (>= 3.0)\n      sprockets (~> 2.8)\n    sqlite3 (1.3.7)\n    thor (0.18.1)\n    thread_safe (0.1.2)\n      atomic\n    tilt (1.4.1)\n    treetop (1.4.14)\n      polyglot\n      polyglot (>= 0.3.1)\n    turbolinks (1.3.0)\n      coffee-rails\n    twitter-bootstrap-rails (2.2.7)\n      actionpack (>= 3.1)\n      execjs\n      rails (>= 3.1)\n      railties (>= 3.1)\n    tzinfo (0.3.37)\n    uglifier (2.1.2)\n      execjs (>= 0.3.0)\n      multi_json (~> 1.0, >= 1.0.2)\n\nPLATFORMS\n  ruby\n\nDEPENDENCIES\n  coffee-rails (~> 4.0.0)\n  jbuilder (~> 1.2)\n  jquery-rails\n  paymill\n  rails (= 4.0.0)\n  sass-rails (~> 4.0.0)\n  sdoc\n  sqlite3\n  turbolinks\n  twitter-bootstrap-rails\n  uglifier (>= 1.3.0)\n\n== Copyright\n\n(The MIT License)\n\nCopyright (c) 2013 Luca G. Soave\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the 'Software'), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n" 
2.0.0p247 :009 >
2.0.0p247:001>需要“octokit”
=>正确
2.0.0p247:002>Octokit.contents'lgs/paymill on rails',:path=>'README.rdoc',:accept=>'application/vnd.github.V3.raw'
=>“==Rails 4.0.0上的Paymill\n\n Rails 4.0.0和ruby-2.0.0-p247上的邮件订阅,{部署在Heroku上}[https://paymill-on-rails.herokuapp.com].这是基于{Marc B.'s}[https://github.com/apalancat]{工作}[https://github.com/apalancat/paymill-rails].\n\n==用法\n\n在{paymill.com}注册测试帐户[https://paymill.com/]并创建订阅计划,也称为优惠。\n\n安装应用程序:\n\n bundle\n rake db:migrate\n\n\n在config/initializers/paymill.rb\n\n中为您自己的paymill API密钥替换测试密钥。\n\n要将计划及其ID从paymill获取到应用程序,请运行:\n\n rake paymill:import\u plans\n\n就是这样!运行\n\n rails服务器\n\n并且它应该可以工作。\n\n==在Heroku上部署\n\n从rails应用程序的根目录路径运行\n\n Heroku配置:添加BUNDLE\u而不使用=\“development:test\”\n Heroku rake db:migrate\n Heroku rake paymill:import\n\n==当前BUNDLE\n\n远程:https://rubygems.org/\n规格:\n actionmailer(4.0.0)\n actionpack(=4.0.0)\n mail(~>2.5.3)\n actionpack(4.0.0)\n activesupport(=4.0.0)\n builder(~>3.1.0)\n erubis(~>2.7.0)\n rack(~>1.5.2)\n rack测试(~>0.6.2)\n activemodel(4.0.0)\n activesupport(=4.0.0)\n builder(~>3.1.0)\n activerecord(4.0.0)\n activemodel(=4.0.0)\n activerecord-deprecated\u finders(~>1.0.2)\n activesupport(=4.0.0)\n arel(~>4.0.0)\n activerecord-deprecated\u finders(1.0.3)\n activesupport(4.0.0)\n i18n(~>0.6,>=0.4)\n minitest(~>4.2)\n multi\u json(~>1.3)\n线程安全(~>0.1)\n tzinfo(~>0.3.37)\n arel(4.0.0.0.0.0\n(1.1.12)\n builder(3.1.4)\n coffee rails(4.0.0)\n coffee script(>=2.2.0)\n railties(>=4.0.0.beta,<5.0)\n coffee script(2.2.0)\n coffee script source\n execjs\n coffee script source(1.6.3)\n erubis(2.7.0)\n execjs(1.4.0)\n multi\u json(~>1.2.0)\n hike(1.2.3)\n i18n(0.6.4)\n jbuilder jbuilder(1.5.0)\n activesupport(>=3.0.0)\n multi\u json(>=1.2.0)\n jquery rails(3.0.4)\n railties(>=3.0,<5.0)\n thor(>=0.14,<2.0)\n json(1.8.0)\n mail(2.5.4)\n mime类型(~>1.16)\n treetop(~>1.4.8)\n mime类型(1.23)\n minitest(4.7.5)\n multi-U json(1.7.8)\n paymill(0.3)\n json\n polyglot(0.3.3)\n rack(1.5.2)\n rack test(0.6.2)\n rack(>=1.0)\n rails(4.0.0)\n actionmailer(=4.0.0)\n actionpack(=4.0.0)\n activerecord(=4.0.0)\n activesupport(=4.0.0)\n bundler(>=1.3.0,<2.0)\n railties(=4.0.0)\n链轮轨道(>2.0.0)\n actionpack(=4.0.0)\n activesupport(=4.0.0)\n rake(>=0.8.7)\n thor(>=0.18.1,<2.0)\n rake(10.1.0)\n rdoc(3.12.2)\n json(~>1.4)\n sass(3.2.10)\n sass rails(4.0.0)\n railties(>=4.0.0.beta,<5.0)\n sass(>=3.1.10)\n链轮轨道(~>2.0.0.0)\n(>=1.1.3)\n rdoc(~>3.10)\n链轮(2.10.0)\n徒步旅行(~>1.2)\n多json(~>1.0)\n机架(~>1.0)\n倾斜(~>1.1,!=1.3.0)\n链轮导轨(2.0.0)\n actionpack(>=3.0)\n活动支持(>=3.0)\n链轮(~>2.8)\n sqlite3 1.3(1.3.7)\n thor(0.18.1)\n安全线程(0.1.2)\n原子\n倾斜(1.4.1)\n树梢(1.4.14)\n多边形图\n多边形图(>=0.3.1)\n涡轮链接(1.3.0)\n咖啡导轨\n twitter引导导轨(2.2.7)\n actionpack(>=3.1)\n execjs\n rails(>=3.1)\n railties(>=3.1)\n tzinfo(0.3.37)\n uglifier(2.1.2)\n execjs(>=0.3.0)\n multi\u json(~>1.0,>=1.0.2)\n\n平台\n ruby\n\n独立性\n coffee rails(~>4.0.0)\n jbuilder(~>1.2)\n jquery rails\n paymill\n rails(=4.0.0)\n sass rails(~>4.0.0)\n sdoc\n sqlite3\n turbolinks\n twitter引导rails\n uglifier(>=1.3.0)\n\n\n==版权\n\n\n(麻省理工许可证)\n\n版权所有2013 Luca G.Soave特此免费授予获得本软件及相关文档文件副本的任何人(以下简称“软件”),在不受限制的情况下处理软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件的权利,并允许安装软件的人员这样做,但须符合以下条件:\n\n上述版权通知和本许可通知应包含在软件的所有部分或实质部分中。\n\n本软件按“原样”提供,不提供任何明示或实际使用的担保,包括但不限于适销性、特定用途的适销性和非侵权性担保。在任何情况下,版权所有人或版权所有人均不对Y索赔、损害赔偿或其他责任,无论是在合同诉讼、侵权诉讼或其他诉讼中,都是由软件或软件的使用或其他交易引起的或与之相关的。\n
2.0.0p247:009>

有两个选项。一个是解码:

require 'base64'
plaintext = Base64.decode64(data['content'])
或者,您可以在他们的API上使用原始内容请求
Accept: application/vnd.github.VERSION.raw