Created
September 5, 2018 04:48
-
-
Save prasannajeet/5c366e004538211a3be36b9e359b5957 to your computer and use it in GitHub Desktop.
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 characters
public class RecaptchaRepository { | |
public LiveData<RecaptchaVerifyResponse> doRecaptchaValidation(@NonNull String baseUrl, @NonNull String response, @NonNull String key) { | |
final MutableLiveData<RecaptchaVerifyResponse> data = new MutableLiveData<>(); | |
Map<String, String> params = new HashMap<>(); | |
params.put("response", response); | |
params.put("secret", key); | |
getRecaptchaValidationService(baseUrl).verifyResponse(params).enqueue(new Callback<RecaptchaVerifyResponse>() { | |
@Override | |
public void onResponse(Call<RecaptchaVerifyResponse> call, Response<RecaptchaVerifyResponse> response) { | |
data.setValue(response.body()); | |
} | |
@Override | |
public void onFailure(Call<RecaptchaVerifyResponse> call, Throwable t) { | |
data.setValue(null); | |
} | |
}); | |
return data; | |
} | |
private RecaptchaVerificationService getRecaptchaValidationService(@NonNull String baseUrl) { | |
return getRetrofit(baseUrl).create(RecaptchaVerificationService.class); | |
} | |
private Retrofit getRetrofit(@NonNull String baseUrl) { | |
return new Retrofit.Builder() | |
.baseUrl(baseUrl) | |
.addConverterFactory(GsonConverterFactory.create()) | |
.build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment