Skip to content

Instantly share code, notes, and snippets.

@prasannajeet
Created September 5, 2018 04:48
Show Gist options
  • Save prasannajeet/5c366e004538211a3be36b9e359b5957 to your computer and use it in GitHub Desktop.
Save prasannajeet/5c366e004538211a3be36b9e359b5957 to your computer and use it in GitHub Desktop.
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