module Shogun class GitHubScore DEFAULT_POINTS = { "IssuesEvent" => 1, "IssueCommentEvent" => 2, "PushEvent" => 3, "PullRequestReviewCommentEvent" => 4, "WatchEvent" => 5, "CreateEvent" => 6 }.freeze def initialize(handle, points: DEFAULT_POINTS) @handle = handle @points = points end def score events.sum do |event| points.fetch(event["type"], 1) end end private attr_reader :points, :handle def build_url "https://api.github.com/users/#{handle}/events/public" end def events response = Net::HTTP.get_response(URI.parse(build_url)) raise UserNotFound.new(handle) if response.code == "404" JSON.parse(response.body) end end end