Search code examples
rubyoctokit

Ruby Script using Octokit: Making API Calls


I am trying to create a script that gets a list of all repositories from GitHub. GitHub has a ruby gem called Octokit that I am trying to utilize, but I am a little lost.

The API has a reference here. It shows that I can get this response using a GET request. I am trying to figure out how to perform this using the Octokit Gem.

I may be completely off base with this question as I am new to Ruby, but I'd appreciate some steps showing how this can be completed. If I should not be using Octokit for this, a recommendation for creating HTTP Requests and Parsing the appropriate JSON response would be appreciated as well.

The Code I have so far:

#!/usr/bin/ruby
require 'Octokit'

client = Octokit::Client.new \
  :login    => '',
  :password => ''

user = client.user
user.login

Solution

  • Following along with the code you already wrote, you can get all of the repositories for the user who's credentials you're using when authenticating the client with:

    client.repositories
    

    You can also get the public repositories of another user by passing their login as an argument:

    client.repositories('username_here')