Skip to content

Commit 006325a

Browse files
committed
Fix non-42 user/hostname + cleanup
1 parent a3c5876 commit 006325a

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/RP42.cr

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@ require "oauth2"
22
require "./client"
33

44
module RP42
5-
VERSION = "0.1.0"
6-
7-
api_id = "6006639307c5ecc1506feb96d9f833df325e07573040acecad429f75b824a72e"
8-
api_secret = "<API-SECRET>"
5+
VERSION = "0.1.0"
6+
API_ID = "6006639307c5ecc1506feb96d9f833df325e07573040acecad429f75b824a72e"
7+
API_SECRET = "<API-SECRET>"
8+
9+
hostname = System.hostname.split(".", 2)
10+
exit if (hostname.size < 2 || hostname[1]) != "42.fr"
11+
username = `whoami`.chomp("\n")
912

10-
oauth2_client = OAuth2::Client.new("api.intra.42.fr", api_id, api_secret, authorize_uri: "/oauth/authorize", token_uri: "/oauth/token")
13+
oauth2_client = OAuth2::Client.new("api.intra.42.fr", API_ID, API_SECRET, authorize_uri: "/oauth/authorize", token_uri: "/oauth/token")
1114
access_token = oauth2_client.get_access_token_using_client_credentials
1215
http_client = HTTP::Client.new("api.intra.42.fr", tls: OpenSSL::SSL::Context::Client.insecure)
1316
access_token.authenticate(http_client)
1417

15-
username = `whoami`.chomp("\n")
16-
hostname = System.hostname.split(".", 2)
17-
hostname[0] = "At home" if hostname[1] != "42.fr"
18-
1918
coas : JSON::Any = JSON.parse(http_client.get("/v2/users/#{username}/coalitions").body)
2019
coa = coas[0]["name"].to_s
2120
coa = coas[1]["name"].to_s if coas.size > 1

0 commit comments

Comments
 (0)