-
Notifications
You must be signed in to change notification settings - Fork 2
/
v1.rb
39 lines (34 loc) · 900 Bytes
/
v1.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require 'uri'
require 'net/http'
require 'net/https'
module CCS
class V1 < Sinatra::Base
def self.new(*)
super
end
get '/' do
content_type :json
message = Hash.new
message[:message] = 'alive'
message.to_json
end
get 'count/:owner/:repo/:user/?' do
content_type :json
begin
contributions = Hash.new
contributions[:count] = 0
contributors_text = RestClient.get "https://api.github.com/repos/#{params[:owner]}/#{params[:repo]}/contributors"
contributors = JSON.parse(contributors_text)
contributors.each do |contributor|
if contributor['login'] == params[:user]
contributions[:count] = contributor['contributions']
break
end
end
contributions.to_json
rescue => e
e.response
end
end
end
end