Created
February 21, 2017 11:35
-
-
Save kinsomicrote/18a014b0febf0f4f1714baca6ce2b634 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'faraday' | |
require 'json' | |
require 'pry' | |
class UserCommits | |
def initialize(username) | |
@username = username | |
end | |
def github_url | |
"https://api.github.com/users/#{@username}/events" | |
end | |
def fetch_commits | |
data = get_api_data | |
push_event_data = grab_push_events(data) | |
payload_data = collect_payloads(push_event_data) | |
commit_history = collect_commit_history(payload_data) | |
collect_messages(commit_history) | |
binding.pry | |
end | |
private | |
def collect_messages(data) | |
data.map do |commit| | |
commit['message'] | |
end | |
end | |
def collect_commit_history(data) | |
data.collect do |payload| | |
payload['commits'].collect { |commit| commit } | |
end.flatten | |
end | |
def collect_payloads(data) | |
data.collect do |push_event| | |
push_event['payload'] | |
end | |
end | |
def grab_push_events(data) | |
data.select do |event| | |
event['type'] == 'PushEvent' | |
end | |
end | |
def get_api_data | |
response = Faraday.get(github_url) | |
JSON.parse(response.body) | |
end | |
end | |
u = UserCommits.new("iMacTia") | |
puts u.fetch_commits |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment