gpt4 book ai didi

ruby - '获取 README' API V3 github 转换

转载 作者:数据小太阳 更新时间:2023-10-29 07:45:14 26 4
gpt4 key购买 nike

我需要获取我的 Github 存储库的 README 内容,我去了 ' Get the README ' 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"
}
}

以明文(非 base64 编码)获取/转换“内容”:“PT0gUGF5bWlsbCBv ...”的方法是什么?

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

Linuxios 提出的解决方案在 nice Octokit API wrapper for Ruby 中也得到了很好的实现。如下:

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 >

最佳答案

两个选项。一种是解码它:

require 'base64'
plaintext = Base64.decode64(data['content'])

或者,您可以在他们的 API 上使用原始内容请求。将此添加到您的标题中:

Accept: application/vnd.github.VERSION.raw

用您的 API 版本替换 VERSION。

关于ruby - '获取 README' API V3 github 转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18290925/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com