Consuming the GitHub API


class User < ActiveRecord::Base   def self.create_with_omniauth(auth) 
create! do |user|
user.provider = auth["provider"]
user.uid = auth["uid"] = auth["info"]["name"]
user.token = auth["credentials"]["token"]
user.nickname = auth["info"]["nickname"]
user.image = auth["extra"]["raw_info"]["avatar_url"]

Making API Calls

class GithubService 
attr_reader :current_user
def initialize(current_user)
@current_user = current_user
@_connection ="")
connection.headers['Authorization'] = "token #{current_user.token}"
def repos
def get(path)
def connection

Presenting the Data

  • When the data was ready, hide the spinning wheel that was in the section of the page where the data belonged, and access the information at the route specified in the AJAX call:
var renderRepos = function() {
url: '/repositories',
success: function(data) {
var items = [];
$.each(data, function(key, repository) {
items.push( "<p>" + + "</p>" );
showHide('#all_repos', '#repo-wheel', items);
var showHide = function(divId, wheelId, items) {
  • Found at the “/repositories” route was this:
class RepositoriesController < ApplicationController 
def index
@repositories = Repository.all(current_user)
render json: @repositories
  • Calling Repository.all accessed the Repository PORO (not an ActiveRecord model), which looked like this:
class Repository < OpenStruct 
def self.service(current_user)
def self.all(current_user)
repos_hash = service(current_user).repos do |repo_hash|
  • And that brings us full circle back to the service and the Faraday call shown above!

Other Features


  • Caching: Even with AJAX calls, the site loaded pretty slowly. Since there was one landing page for everything beyond the gist functionality, it required quite a few API calls, as well as the Nokogiri scraping. I need to think more about the balance between performance, and being up to date — the information on someone’s GitHub page changes pretty frequently.
  • Background workers: for the reason mentioned above. I don’t know much about how background workers work, but I would like to read up on it.
  • Move away from the use of OpenStructs to POROs with only the attributes I actually need, that I define.
  • Updated my AJAX calls to use the $.getJSON method. I’m glad I did it the way I did this time around so I have a better understanding of what is happening (and to practice my JavaScript!), but the jQuery route would be cleaner.

Senior Software Engineer |

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adrienne Domingus

Adrienne Domingus

Senior Software Engineer |

More from Medium

Ruby 3 on Rails 7: RESTful JSON API

5 Useful Git Commands for Devs

Basics of Cross Site Request Forgery (CSRF), and ways to prevent it in NodeJs and Ruby on Rails

Building a Ruby CLI app