Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Get the README' API V3 github converted

Tags:

github

ruby

I need to get the README content of my Github repo and I went for 'Get the README' API V3, but it is encoded 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"
  }
}

What is the way to get/convert the "content": "PT0gUGF5bWlsbCBv ..." in clear text (not base64 encoded) ?

UPDATE (just for tracking purposes):

The solution propesed by Linuxios, is also well implemented within the nice Octokit API wrapper for Ruby as following:

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

to get the entire html and

Octokit.contents 'lgs/paymill-on-rails', :path => 'README.rdoc', :accept => 'application/vnd.github.V3.raw'

if you want the clean, raw content only :

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 >
like image 835
Luca G. Soave Avatar asked Aug 19 '26 14:08

Luca G. Soave


1 Answers

Two options. One is just to decode it:

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

Or, you can use the raw content request on their API. Add this to your headers:

Accept: application/vnd.github.VERSION.raw

Replacing VERSION with your API version.

like image 154
Linuxios Avatar answered Aug 22 '26 06:08

Linuxios