Sha256: 10fe85fe82bc702b0fbeadba2955075e984675ac7572ea4c3f9ae7398424a3b8

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

require "github_contributions_api/version"
require 'json'
require "httparty"

# A ruby interface to the GitHub Contributions Archive API (https://githubcontributions.io). To the author's knowlege, this API is undocumented.
module GithubContributionsApi
  # The prexix for all GitHub Contributions API endpoints.
  URL_BASE = "https://githubcontributions.io/api"

  # Get information about a given github user.
  # @param [String] github_username The username of the github user.
  # @example GithubContributionsApi.user("octocat")
  # @return [Hash]
  def self.user(github_username)
    request_url = "#{URL_BASE}/user/#{github_username}"
    response = HTTParty.get(request_url)
    JSON.parse(response.body)
  end

  # Get events for a given github user.
  # @param [String] github_username The username of the github user.
  # @param [Hash] options
  # @option options [Integer] :page (1) The requested page number.
  # @example GithubContributionsApi.user_events("octocat")
  # @example GithubContributionsApi.user_events("octocat", :page => 1)
  # @example GithubContributionsApi.user_events("s2t2", :page => 2)
  # @return [Hash]
  def self.user_events(github_username, options = {})
    page_number = options[:page] || 1
    request_url = "#{URL_BASE}/user/#{github_username}/events/#{page_number}"
    response = HTTParty.get(request_url)
    JSON.parse(response.body)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
github_contributions_api-1.0.0 lib/github_contributions_api.rb