use of retrofit2.http.GET in project retrofit by square.
the class RetrofitTest method methodAnnotationsPassedToCallAdapter.
@Test
public void methodAnnotationsPassedToCallAdapter() {
final AtomicReference<Annotation[]> annotationsRef = new AtomicReference<>();
class MyCallAdapterFactory extends CallAdapter.Factory {
@Override
public CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit) {
annotationsRef.set(annotations);
return null;
}
}
Retrofit retrofit = new Retrofit.Builder().baseUrl(server.url("/")).addConverterFactory(new ToStringConverterFactory()).addCallAdapterFactory(new MyCallAdapterFactory()).build();
Annotated annotated = retrofit.create(Annotated.class);
// Trigger internal setup.
annotated.method();
Annotation[] annotations = annotationsRef.get();
assertThat(annotations).hasAtLeastOneElementOfType(Annotated.Foo.class);
}
use of retrofit2.http.GET in project azure-sdk-for-java by Azure.
the class WebAppsInner method listPublishingProfileXmlWithSecretsSlotWithServiceResponseAsync.
/**
* Gets the publishing profile for an app (or deployment slot, if specified).
* Gets the publishing profile for an app (or deployment slot, if specified).
*
* @param resourceGroupName Name of the resource group to which the resource belongs.
* @param name Name of the app.
* @param slot Name of the deployment slot. If a slot is not specified, the API will get the publishing profile for the production slot.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the InputStream object
*/
public Observable<ServiceResponse<InputStream>> listPublishingProfileXmlWithSecretsSlotWithServiceResponseAsync(String resourceGroupName, String name, String slot) {
if (resourceGroupName == null) {
throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
}
if (name == null) {
throw new IllegalArgumentException("Parameter name is required and cannot be null.");
}
if (slot == null) {
throw new IllegalArgumentException("Parameter slot is required and cannot be null.");
}
if (this.client.subscriptionId() == null) {
throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
}
final String apiVersion = "2016-08-01";
final PublishingProfileFormat format = null;
CsmPublishingProfileOptions publishingProfileOptions = new CsmPublishingProfileOptions();
publishingProfileOptions.withFormat(null);
return service.listPublishingProfileXmlWithSecretsSlot(resourceGroupName, name, slot, this.client.subscriptionId(), apiVersion, this.client.acceptLanguage(), publishingProfileOptions, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<InputStream>>>() {
@Override
public Observable<ServiceResponse<InputStream>> call(Response<ResponseBody> response) {
try {
ServiceResponse<InputStream> clientResponse = listPublishingProfileXmlWithSecretsSlotDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
use of retrofit2.http.GET in project Tusky by Vavassor.
the class LoginActivity method onButtonClick.
/**
* Obtain the oauth client credentials for this app. This is only necessary the first time the
* app is run on a given server instance. So, after the first authentication, they are
* saved in SharedPreferences and every subsequent run they are simply fetched from there.
*/
private void onButtonClick(final EditText editText) {
domain = validateDomain(editText.getText().toString());
/* Attempt to get client credentials from SharedPreferences, and if not present
* (such as in the case that the domain has never been accessed before)
* authenticate with the server and store the received credentials to use next
* time. */
String prefClientId = preferences.getString(domain + "/client_id", null);
String prefClientSecret = preferences.getString(domain + "/client_secret", null);
if (prefClientId != null && prefClientSecret != null) {
clientId = prefClientId;
clientSecret = prefClientSecret;
redirectUserToAuthorizeAndLogin(editText);
} else {
Callback<AppCredentials> callback = new Callback<AppCredentials>() {
@Override
public void onResponse(Call<AppCredentials> call, Response<AppCredentials> response) {
if (!response.isSuccessful()) {
editText.setError(getString(R.string.error_failed_app_registration));
Log.e(TAG, "App authentication failed. " + response.message());
return;
}
AppCredentials credentials = response.body();
clientId = credentials.clientId;
clientSecret = credentials.clientSecret;
preferences.edit().putString(domain + "/client_id", clientId).putString(domain + "/client_secret", clientSecret).apply();
redirectUserToAuthorizeAndLogin(editText);
}
@Override
public void onFailure(Call<AppCredentials> call, Throwable t) {
editText.setError(getString(R.string.error_failed_app_registration));
Log.e(TAG, Log.getStackTraceString(t));
}
};
try {
getApiFor(domain).authenticateApp(getString(R.string.app_name), getOauthRedirectUri(), OAUTH_SCOPES, getString(R.string.app_website)).enqueue(callback);
} catch (IllegalArgumentException e) {
editText.setError(getString(R.string.error_invalid_domain));
}
}
}
use of retrofit2.http.GET in project iNGAGE by davis123123.
the class UserRecentCommentHandler method enqueue.
// get all recent comments for each room, for the user
public void enqueue(String username) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging);
Retrofit retrofit = new Retrofit.Builder().client(httpClient.build()).addConverterFactory(GsonConverterFactory.create()).baseUrl(get_url).build();
Interface service = retrofit.create(Interface.class);
Call<ResponseBody> call = service.get(username);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
Log.i("STATE", "Retrofit response code: " + response.code());
if (response.isSuccessful()) {
Log.i("STATE", "Retrofit POST Success");
try {
serverResponse = response.body().string();
createCommentsList(serverResponse);
callBackData.notifyChange();
} catch (IOException e) {
e.printStackTrace();
}
} else {
Log.i("Retrofit Error Code:", String.valueOf(response.code()));
Log.i("Retrofit Error Body", response.errorBody().toString());
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Log.i("STATE", "Retrofit Failure");
}
});
}
use of retrofit2.http.GET in project instructure-android by instructure.
the class QuizStartFragment method setupCallbacks.
private void setupCallbacks() {
webViewClientCallback = new CanvasWebView.CanvasWebViewClientCallback() {
@Override
public void openMediaFromWebView(String mime, String url, String filename) {
openMedia(mime, url, filename);
}
@Override
public void onPageFinishedCallback(WebView webView, String url) {
}
@Override
public void onPageStartedCallback(WebView webView, String url) {
}
@Override
public boolean canRouteInternallyDelegate(String url) {
return RouterUtils.canRouteInternally(null, url, ApiPrefs.getDomain(), false);
}
@Override
public void routeInternallyCallback(String url) {
RouterUtils.canRouteInternally(getActivity(), url, ApiPrefs.getDomain(), true);
}
};
embeddedWebViewCallback = new CanvasWebView.CanvasEmbeddedWebViewCallback() {
@Override
public void launchInternalWebViewFragment(String url) {
InternalWebviewFragment.Companion.loadInternalWebView(getActivity(), getNavigation(), InternalWebviewFragment.Companion.createBundle(course, url, false));
}
@Override
public boolean shouldLaunchInternalWebViewFragment(String url) {
return true;
}
};
quizSubmissionTimeCanvasCallback = new StatusCallback<QuizSubmissionTime>() {
@Override
public void onResponse(@NonNull Response<QuizSubmissionTime> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (type == ApiType.CACHE)
return;
QuizStartFragment.this.quizSubmissionTime = quizSubmissionTime;
QuizManager.getQuizSubmissions(course, quiz.getId(), true, quizSubmissionResponseCanvasCallback);
}
};
quizSubmissionResponseCanvasCallback = new StatusCallback<QuizSubmissionResponse>() {
@Override
public void onResponse(@NonNull Response<QuizSubmissionResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (type == ApiType.CACHE)
return;
final QuizSubmissionResponse quizSubmissionResponse = response.body();
// since this is a student app, make sure they only have their own submissions (if they're siteadmin it'll be different)
final ArrayList<QuizSubmission> submissions = new ArrayList<>();
final User user = ApiPrefs.getUser();
if (user != null) {
for (QuizSubmission submission : quizSubmissionResponse.getQuizSubmissions()) {
if (submission.getUserId() == user.getId()) {
submissions.add(submission);
}
}
}
quizSubmissionResponse.setQuizSubmissions(submissions);
if (quizSubmissionResponse.getQuizSubmissions() == null || quizSubmissionResponse.getQuizSubmissions().size() == 0) {
// No quiz submissions, let the user start the quiz.
// They haven't turned it in yet, so don't show the turned-in view
quizTurnedInContainer.setVisibility(View.GONE);
shouldStartQuiz = true;
next.setVisibility(View.VISIBLE);
next.setEnabled(true);
} else {
// We should have at least 1 submission
quizSubmission = quizSubmissionResponse.getQuizSubmissions().get(quizSubmissionResponse.getQuizSubmissions().size() - 1);
next.setEnabled(true);
final boolean hasUnlimitedAttempts = quiz.getAllowedAttempts() == -1;
// Teacher can manually unlock a quiz for an individual student
final boolean teacherUnlockedQuizAttempts = quizSubmission.isManuallyUnlocked();
final boolean hasMoreAttemptsLeft = quizSubmission.getAttemptsLeft() > 0;
final boolean canTakeQuizAgain = hasUnlimitedAttempts | teacherUnlockedQuizAttempts | hasMoreAttemptsLeft;
if (quiz.getHideResults() == Quiz.HIDE_RESULTS_TYPE.ALWAYS && !canTakeQuizAgain) {
// Don't let the user see the questions if they've exceeded their attempts
next.setVisibility(View.GONE);
} else if (quiz.getHideResults() == Quiz.HIDE_RESULTS_TYPE.AFTER_LAST_ATTEMPT && !canTakeQuizAgain) {
// They can only see the results after their last attempt, and that hasn't happened yet
next.setVisibility(View.GONE);
}
// -1 allowed attempts == unlimited
if (quizSubmission.getFinishedAt() != null && !canTakeQuizAgain) {
// They've finished the quiz and they can't take it anymore; let them see results
next.setVisibility(View.VISIBLE);
next.setText(getString(R.string.viewQuestions));
shouldLetAnswer = false;
} else {
// They are allowed to take the quiz...
next.setVisibility(View.VISIBLE);
if (quizSubmission.getFinishedAt() != null) {
shouldStartQuiz = true;
next.setText(getString(R.string.takeQuizAgain));
} else {
// Let the user resume their quiz
next.setText(getString(R.string.resumeQuiz));
}
}
if (quizSubmission.getFinishedAt() != null) {
quizTurnedIn.setText(getString(R.string.turnedIn));
quizTurnedInDetails.setText(DateHelper.getDateTimeString(getActivity(), quizSubmission.getFinishedAt()));
// The user has turned in the quiz, let them see the results
viewResults.setVisibility(View.VISIBLE);
} else {
quizTurnedInContainer.setVisibility(View.GONE);
}
// Weird hack where if the time expires and the user hasn't submitted it doesn't let you start the quiz
if (quizSubmission.getWorkflowState() == QuizSubmission.WORKFLOW_STATE.UNTAKEN && (quizSubmission.getEndAt() != null && (quizSubmissionTime != null && quizSubmissionTime.getTimeLeft() > 0))) {
next.setEnabled(false);
// submit the quiz for them
QuizManager.submitQuiz(course, quizSubmission, true, new StatusCallback<QuizSubmissionResponse>() {
@Override
public void onResponse(@NonNull Response<QuizSubmissionResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (type == ApiType.CACHE)
return;
// the user has turned in the quiz, let them see the results
viewResults.setVisibility(View.VISIBLE);
next.setEnabled(true);
shouldStartQuiz = true;
next.setText(getString(R.string.takeQuizAgain));
QuizSubmissionResponse quizResponse = response.body();
// Since this is a student app, make sure they only have their own submissions (if they're siteadmin it'll be different)
final ArrayList<QuizSubmission> submissions = new ArrayList<>();
final User user = ApiPrefs.getUser();
if (user != null) {
for (QuizSubmission submission : quizResponse.getQuizSubmissions()) {
if (submission.getUserId() == user.getId()) {
submissions.add(submission);
}
}
}
quizResponse.setQuizSubmissions(submissions);
if (quizResponse.getQuizSubmissions() != null && quizResponse.getQuizSubmissions().size() > 0) {
quizSubmission = quizResponse.getQuizSubmissions().get(quizResponse.getQuizSubmissions().size() - 1);
}
}
});
}
// If the user can only see results once and they have seen it, don't let them view the questions
if (quiz.isOneTimeResults() && quizSubmission.hasSeenResults()) {
next.setVisibility(View.GONE);
}
if (quiz.isLockedForUser()) {
shouldStartQuiz = false;
next.setText(getString(R.string.assignmentLocked));
}
}
populateQuizInfo();
canvasLoading.setVisibility(View.GONE);
}
@Override
public void onFail(@Nullable Call<QuizSubmissionResponse> call, @NonNull Throwable error, @Nullable Response response) {
canvasLoading.setVisibility(View.GONE);
// on quizzes.
if (response != null && response.code() == 401) {
populateQuizInfo();
// there is a not authorized error, so don't let them start the quiz
next.setVisibility(View.GONE);
}
}
};
quizStartResponseCallback = new StatusCallback<QuizSubmissionResponse>() {
@Override
public void onResponse(@NonNull Response<QuizSubmissionResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (response.code() == 200 && type == ApiType.API) {
// We want to show the quiz here, but we need to get the quizSubmissionId first so our
// api call for the QuizQuestionsFragment knows which questions to get
StatusCallback<QuizSubmissionResponse> quizSubmissionResponseCallback = new StatusCallback<QuizSubmissionResponse>() {
@Override
public void onResponse(@NonNull Response<QuizSubmissionResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
QuizSubmissionResponse quizSubmissionResponse = response.body();
if (quizSubmissionResponse != null && quizSubmissionResponse.getQuizSubmissions() != null && quizSubmissionResponse.getQuizSubmissions().size() > 0) {
quizSubmission = quizSubmissionResponse.getQuizSubmissions().get(quizSubmissionResponse.getQuizSubmissions().size() - 1);
if (quizSubmission != null) {
showQuiz();
} else {
getLockedMessage();
}
}
}
};
QuizManager.getFirstPageQuizSubmissions(course, quiz.getId(), false, quizSubmissionResponseCallback);
}
}
@Override
public void onFail(@Nullable Call<QuizSubmissionResponse> call, @NonNull Throwable error, @Nullable Response response) {
if (response != null && response.code() == 403) {
// Forbidden
// Check to see if it's because of IP restriction or bad access code or either
getLockedMessage();
}
}
};
quizStartSessionCallback = new StatusCallback<ResponseBody>() {
};
}
Aggregations