Last active
February 16, 2020 19:09
-
-
Save igorwojda/2a2c2946a31ecbb8e05f393e54e036f0 to your computer and use it in GitHub Desktop.
Revisions
-
igorwojda revised this gist
Feb 16, 2020 . 1 changed file with 9 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,7 @@ val retrofit = Retrofit.Builder() val userService = retrofit.create(UserService::class.java) val accountRepository = AccountRepository(context) // Wee need this because userService.login function is suspended CoroutineScope(Dispatchers.IO).launch { val response = userService.login("email", "password") @@ -22,4 +23,11 @@ interface UserService { @Query("email") email: String, @Query("password") password: String ): LoginResponse? } // Data model returned by login endpoint // (JSON is converted by moshi converter into Kotlin data class instance) data class LoginResponse( val accessToken: String, val refreshToken: String ) -
igorwojda revised this gist
Feb 16, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ val retrofit = Retrofit.Builder() .baseUrl("https://igorwojda.com/app") .build() val userService = retrofit.create(UserService::class.java) -
igorwojda revised this gist
Feb 16, 2020 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,7 @@ val retrofit = Retrofit.Builder() .baseUrl("https://igor.wojda.com/app") .build() val userService = retrofit.create(UserService::class.java) val accountRepository = AccountRepository(context) -
igorwojda revised this gist
Feb 16, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,7 @@ CoroutineScope(Dispatchers.IO).launch { // Retrofit service definition interface UserService { @POST("auth/login") suspend fun authorizeAsync( @Query("email") email: String, @Query("password") password: String ): LoginResponse? -
igorwojda created this gist
Feb 16, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ val userService = retrofit.create(UserService::class.java) val accountRepository = AccountRepository(context) CoroutineScope(Dispatchers.IO).launch { val response = userService.login("email", "password") if(response != null) { accountRepository.addAccount(response.accessToken, response.refreshToken) } else { // show error } } // Retrofit service definition interface UserService { @POST("auth/login") fun authorizeAsync( @Query("email") email: String, @Query("password") password: String ): LoginResponse? }