@@ -25,6 +25,7 @@ import java.time.Instant
25
25
class CoderRestClientService {
26
26
private lateinit var retroRestClient: CoderV2RestFacade
27
27
lateinit var me: User
28
+ lateinit var sessionToken: String
28
29
29
30
/* *
30
31
* This must be called before anything else. It will authenticate with coder and retrieve a session token
@@ -53,14 +54,15 @@ class CoderRestClientService {
53
54
.build()
54
55
.create(CoderV2RestFacade ::class .java)
55
56
56
- val sessionTokenResponse = retroRestClient.authenticate(LoginWithPasswordRequest (email, password)).execute()
57
+ val loginResponse = retroRestClient.authenticate(LoginWithPasswordRequest (email, password)).execute()
57
58
58
- if (! sessionTokenResponse .isSuccessful) {
59
- throw AuthenticationException (" Authentication failed with code:${sessionTokenResponse .code()} , reason: ${sessionTokenResponse .message()} " )
59
+ if (! loginResponse .isSuccessful) {
60
+ throw AuthenticationException (" Authentication failed with code:${loginResponse .code()} , reason: ${loginResponse .message()} " )
60
61
}
61
62
62
- val userResponse = retroRestClient.me().execute()
63
+ sessionToken = loginResponse.body()?.sessionToken !!
63
64
65
+ val userResponse = retroRestClient.me().execute()
64
66
if (! userResponse.isSuccessful) {
65
67
throw IllegalStateException (" Could not retrieve information about logged use:${userResponse.code()} , reason: ${userResponse.message()} " )
66
68
}
@@ -85,5 +87,10 @@ class CoderRestClientService {
85
87
86
88
return sshKeysResponse.body()!!
87
89
}
90
+ }
88
91
92
+ fun main () {
93
+ val restClient = CoderRestClientService ()
94
+ restClient.initClientSession(UriScheme .HTTPS , " dev.coder.com" , 443 , " faur@coder.com" , " coder123" )
95
+ println (restClient.workspaces())
89
96
}
0 commit comments