-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83ae5c0
commit 504884d
Showing
3 changed files
with
41 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,32 @@ | ||
require 'octokit' | ||
|
||
class Github::FollowService | ||
def initialize; end | ||
def initialize | ||
@client = github_client | ||
end | ||
|
||
def follow_user(target_user) | ||
headers = { | ||
'Accept' => '*/*', | ||
'Accept-Language' => 'en-US,en;q=0.9,vi;q=0.8', | ||
'Cookie' => '', | ||
'Origin' => 'https://github.com', | ||
'Referer' => 'https://github.com/filiph?tab=followers', | ||
'Sec-Ch-UA' => '"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"', | ||
'Sec-Ch-UA-Mobile' => '?0', | ||
'Sec-Ch-UA-Platform' => '"macOS"', | ||
'Sec-Fetch-Dest' => 'empty', | ||
'Sec-Fetch-Mode' => 'cors', | ||
'Sec-Fetch-Site' => 'same-origin', | ||
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36', | ||
'X-Requested-With' => 'XMLHttpRequest' | ||
} | ||
def follow_user(target_username) | ||
# Follow the user on GitHub | ||
@client.follow(target_username) | ||
|
||
# { success: true, message: "Successfully followed #{target_username}" } | ||
puts '###############################################################################' | ||
puts "############################# Done #{target_username} #########################" | ||
puts '###############################################################################' | ||
rescue Octokit::NotFound | ||
puts "Fail #{target_username}" | ||
rescue Octokit::Unauthorized | ||
puts "Fail #{target_username}" | ||
rescue StandardError => e | ||
puts "Fail #{target_username}" | ||
end | ||
|
||
options = { | ||
headers: headers, | ||
body: { | ||
commit: 'Follow', | ||
authenticity_token: ENV["GITHUB_ACCESS_TOKEN"] | ||
} | ||
} | ||
private | ||
|
||
response = HTTParty.post("https://github.com/users/follow?target=#{target_user}", options) | ||
def github_client | ||
token = ENV['GITHUB_ACCESS_TOKEN'] | ||
raise StandardError, 'GitHub access token not found in environment variables' if token.nil? || token.empty? | ||
|
||
if response.success? | ||
puts "Successfully followed #{target_user}!" | ||
else | ||
puts "Error following #{target_user}: #{response.code} - #{response.message}" | ||
end | ||
Octokit::Client.new(access_token: token) | ||
end | ||
end |