-
Notifications
You must be signed in to change notification settings - Fork 1
/
github.rb
39 lines (28 loc) · 1.06 KB
/
github.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
# frozen_string_literal: true
require 'httparty'
module Github
# Following a specific github user, using basic auth.
def follow_user(credentials, fuser)
base_uri = URI("https://api.github.com/user/following/#{fuser}")
response = HTTParty.put(base_uri.to_s, headers: {
'Authorization' => ('Basic ' + credentials),
'User-Agent' => 'Patassaura'
})
puts "followed #{fuser}"
end
# Getting all the followers from a github user.
def get_followers(fuser, current_page)
base_uri = URI("https://api.github.com/users/#{fuser}/followers?page=#{current_page}")
response = HTTParty.get(base_uri.to_s, headers: {
'User-Agent' => 'Patassaura'
}).parsed_response
response
end
# Method that iterates through json and starts to follow everyone.
def follow_all_users(credentials, json)
json.each do |user|
login_user = user['login']
follow_user(credentials, login_user)
end
end
end