diff --git a/Gemfile b/Gemfile
index dcca53a..faac95a 100644
--- a/Gemfile
+++ b/Gemfile
@@ -15,6 +15,7 @@ gem "whenever", require: false
gem "hurley"
gem "omniauth-github"
gem "figaro"
+gem "githubstats"
group :development, :test do
gem "byebug"
diff --git a/Gemfile.lock b/Gemfile.lock
index 30c4afb..32fbecf 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -41,6 +41,7 @@ GEM
autoprefixer-rails (6.0.3)
execjs
json
+ basiccache (1.0.0)
better_errors (2.1.1)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
@@ -69,6 +70,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.9.1.1)
+ curb (0.8.8)
database_cleaner (1.5.0)
debug_inspector (0.0.2)
diff-lcs (1.2.5)
@@ -78,6 +80,10 @@ GEM
multipart-post (>= 1.2, < 3)
figaro (1.1.1)
thor (~> 0.14)
+ githubstats (1.1.0)
+ basiccache (~> 1.0.0)
+ curb (~> 0.8.6)
+ nokogiri (~> 1.6.5)
globalid (0.3.6)
activesupport (>= 4.1.0)
hashie (3.4.2)
@@ -224,6 +230,7 @@ DEPENDENCIES
coffee-rails (~> 4.1.0)
database_cleaner
figaro
+ githubstats
hurley
jbuilder (~> 2.0)
jquery-rails
diff --git a/app/presenters/github_presenter.rb b/app/presenters/github_presenter.rb
index 556a720..3ff8177 100644
--- a/app/presenters/github_presenter.rb
+++ b/app/presenters/github_presenter.rb
@@ -32,7 +32,15 @@ def organizations
end
def year_commits
- list = service.find_user_total_commits(user).map {|data| build_object(data)}
+ list = service.find_user_total_commits(user)
+ end
+
+ def current_streaks
+ list = service.find_user_current_streak(user)
+ end
+
+ def longest_streaks
+ list = service.find_user_longest_streak(user)
end
def starred_repos
diff --git a/app/services/github_service.rb b/app/services/github_service.rb
index c05fb5f..6f1848f 100644
--- a/app/services/github_service.rb
+++ b/app/services/github_service.rb
@@ -2,8 +2,9 @@ class GithubService
attr_reader :connection
def initialize(user)
- @connection = Hurley::Client.new("https://api.github.com")
+ @connection = Hurley::Client.new("https://api.github.com")
@connection.query[:access_token] = user.token
+ @stats = GithubStats.new('bad6e')
end
def find_user_repos(user)
@@ -23,7 +24,15 @@ def find_user_organizations(user)
end
def find_user_total_commits(user)
- parse(connection.get("repos/#{user.nickname}/gitcommit/stats/commit_activity"))
+ @stats.data.scores.reduce(:+)
+ end
+
+ def find_user_current_streak(user)
+ @stats.streak.count
+ end
+
+ def find_user_longest_streak(user)
+ @stats.longest_streak.count
end
def total_starred_repos(user)
diff --git a/app/views/dashboard/show.html.erb b/app/views/dashboard/show.html.erb
index c4f565a..e04b6b6 100644
--- a/app/views/dashboard/show.html.erb
+++ b/app/views/dashboard/show.html.erb
@@ -10,12 +10,15 @@
<%= @info.year_commits %>
<%= @info.current_streaks %>
<%= @info.longest_streaks %>