use of retrofit2.http.GET in project instructure-android by instructure.
the class ZendeskDialogStyled method generateTicketInfo.
private void generateTicketInfo(@Nullable List<Enrollment> enrollments) {
String comment = descriptionEditText.getText().toString();
String subject = subjectEditText.getText().toString();
if (comment.isEmpty() || subject.isEmpty()) {
Toast.makeText(getContext(), R.string.empty_feedback, Toast.LENGTH_LONG).show();
return;
}
// contact the user
if (fromLogin) {
if (emailAddressEditText.getText() != null) {
User user = new User();
user.setPrimaryEmail(emailAddressEditText.getText().toString());
ApiPrefs.setUser(user);
}
}
final User user = ApiPrefs.getUser();
// If a user has an email, otherwise this will be the login ID
String email = "";
if (user != null) {
if (user.getPrimaryEmail() == null) {
email = user.getLoginId();
} else {
email = user.getPrimaryEmail();
}
}
String domain = ApiPrefs.getDomain();
if (domain.isEmpty()) {
domain = DEFAULT_DOMAIN;
}
// add device info to comment
// try to get the version number and version code
PackageInfo pInfo = null;
String versionName = "";
int versionCode = 0;
try {
pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
versionName = pInfo.versionName;
versionCode = pInfo.versionCode;
} catch (PackageManager.NameNotFoundException e) {
// Do nothing
}
String deviceInfo = "";
deviceInfo += getString(R.string.device) + " " + Build.MANUFACTURER + " " + Build.MODEL + "\n" + getString(R.string.osVersion) + " " + Build.VERSION.RELEASE + "\n" + getString(R.string.versionNum) + ": " + versionName + " " + versionCode + "\n" + getString(R.string.zendesk_severityText) + " " + getUserSeveritySelectionTag() + "\n" + getString(R.string.utils_installDate) + " " + getInstallDateString() + "\n\n";
comment = deviceInfo + comment;
String enrollmentTypes = "";
if (enrollments != null) {
for (Enrollment enrollment : enrollments) {
// we don't want a ton of duplicates, so check it
if (!enrollmentTypes.contains(enrollment.getType())) {
enrollmentTypes += enrollment.getType() + ",";
}
}
// remove last comma if necessary
if (enrollmentTypes.endsWith(",") && enrollmentTypes.length() > 1) {
enrollmentTypes = enrollmentTypes.substring(0, enrollmentTypes.length() - 1);
}
}
String becomeUserUrl = "";
if (user != null && user.getId() > 0L) {
becomeUserUrl = domain + "?become_user_id=" + user.getId();
}
String name = "";
if (user != null && user.getName() != null) {
name = user.getName();
}
if (mUseDefaultDomain) {
ErrorReportManager.postGenericErrorReport(subject, domain, email, comment, getUserSeveritySelectionTag(), name, enrollmentTypes, becomeUserUrl, new StatusCallback<ErrorReportResult>() {
@Override
public void onResponse(@NonNull Response<ErrorReportResult> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
resetCachedUser();
if (type.isAPI()) {
resultListener.onTicketPost();
}
}
@Override
public void onFail(@Nullable Call<ErrorReportResult> call, @NonNull Throwable error, @Nullable Response response) {
resetCachedUser();
resultListener.onTicketError();
}
@Override
public void onFinished(ApiType type) {
dismiss();
}
});
} else {
ErrorReportManager.postErrorReport(subject, domain, email, comment, getUserSeveritySelectionTag(), name, enrollmentTypes, becomeUserUrl, new StatusCallback<ErrorReportResult>() {
@Override
public void onResponse(@NonNull Response<ErrorReportResult> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
resetCachedUser();
if (type.isAPI()) {
resultListener.onTicketPost();
}
}
@Override
public void onFail(@Nullable Call<ErrorReportResult> call, @NonNull Throwable error, @Nullable Response response) {
resetCachedUser();
resultListener.onTicketError();
}
@Override
public void onFinished(ApiType type) {
dismiss();
}
});
}
}
use of retrofit2.http.GET in project instructure-android by instructure.
the class PollSessionListFragment method setupCallbacks.
@Override
public void setupCallbacks() {
pollSessionCallback = new StatusCallback<PollSessionResponse>() {
@Override
public void onResponse(@NonNull Response<PollSessionResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (getActivity() == null || type.isCache())
return;
List<PollSession> pollSessions = response.body().getPollSessions();
sessionNextUrl = linkHeaders.nextUrl;
if (pollSessions != null) {
for (PollSession pollSession : pollSessions) {
addItem(pollSession);
SectionManager.getSection(pollSession.getCourse_id(), pollSession.getCourse_section_id(), sectionCallback, true);
}
}
}
@Override
public void onFinished(ApiType type) {
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setRefreshing(false);
}
}
};
sectionCallback = new StatusCallback<Section>() {
@Override
public void onResponse(@NonNull Response<Section> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (getActivity() == null || type.isCache())
return;
sectionMap.put(response.body().getId(), response.body());
notifyDataSetChanged();
}
};
pollChoiceCallback = new StatusCallback<PollChoiceResponse>() {
@Override
public void onResponse(@NonNull Response<PollChoiceResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (getActivity() == null || type.isCache())
return;
List<PollChoice> pollChoices = response.body().getPollChoices();
if (pollChoices != null) {
pollChoiceArrayList.addAll(pollChoices);
}
// or generate the CSV, depending on which action they selected
if (!StatusCallback.moreCallsExist(linkHeaders)) {
if (fromGenerateCSV) {
// generate a map from the array list of poll choices
for (PollChoice choice : pollChoiceArrayList) {
pollChoiceMap.put(choice.getId(), choice);
}
generateCSV();
} else {
AddQuestionFragment addQuestionFragment = new AddQuestionFragment();
// populate the current data with the bundle
Bundle bundle = new Bundle();
bundle.putParcelable(Constants.POLL_BUNDLE, poll);
bundle.putParcelableArrayList(Constants.POLL_CHOICES, pollChoiceArrayList);
addQuestionFragment.setArguments(bundle);
((FragmentManagerActivity) getActivity()).swapFragments(addQuestionFragment, AddQuestionFragment.class.getSimpleName(), R.anim.slide_in_from_bottom, 0, 0, R.anim.slide_out_to_bottom);
}
} else {
// otherwise, get the next group of poll choices.
PollsManager.getNextPagePollChoices(linkHeaders.nextUrl, pollChoiceCallback, false);
}
}
@Override
public void onFinished(ApiType type) {
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setRefreshing(false);
}
}
};
responseCanvasCallback = new StatusCallback<ResponseBody>() {
@Override
public void onFail(@Nullable Call<ResponseBody> call, @NonNull Throwable error, @Nullable Response response) {
AppMsg.makeText(getActivity(), getString(R.string.errorDeletingPollSession), AppMsg.STYLE_ERROR).show();
// we didn't actually delete anything, but we removed the item from the list to make the animation smoother, so now
// lets get the poll sessions again
reloadData();
}
};
}
use of retrofit2.http.GET in project instructure-android by instructure.
the class QuestionListFragment method setupCallbacks.
@Override
public void setupCallbacks() {
pollCallback = new StatusCallback<PollResponse>() {
@Override
public void onResponse(@NonNull Response<PollResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (getActivity() == null || type.isCache())
return;
nextUrl = linkHeaders.nextUrl;
if (response.body().getPolls().size() == 0) {
displayEmptyState();
} else {
List<Poll> polls = response.body().getPolls();
for (Poll poll : polls) {
// add all the polls to a list. we'll use the list later to populate the
// different groups after we get some session information about each poll
pollList.add(poll);
PollsManager.getFirstPagePollSessions(poll.getId(), pollSessionCallback, true);
}
}
}
@Override
public void onFinished(ApiType type) {
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setRefreshing(false);
}
}
};
responseCanvasCallback = new StatusCallback<ResponseBody>() {
@Override
public void onResponse(@NonNull Response<ResponseBody> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (response.code() == 204) {
if (pollToDelete != null) {
// reset it so we don't try to remove it from the list again
pollToDelete = null;
}
}
}
@Override
public void onFail(@Nullable Call<ResponseBody> call, @NonNull Throwable error, @Nullable Response response) {
AppMsg.makeText(getActivity(), getString(R.string.errorDeletingPoll), AppMsg.STYLE_ERROR).show();
// we didn't actually delete anything, but we removed the item from the list to make the animation smoother, so now
// lets get the polls again
reloadData();
}
};
pollSessionCallback = new StatusCallback<PollSessionResponse>() {
@Override
public void onResponse(@NonNull Response<PollSessionResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (getActivity() == null || type.isCache())
return;
List<PollSession> pollSessions = response.body().getPollSessions();
for (PollSession session : pollSessions) {
if (session.is_published()) {
openSessions.put(session.getPoll_id(), session);
// we only care about there being one active poll session
break;
} else {
closedSessions.put(session.getPoll_id(), session);
}
}
// and add it to the "active" group
for (Poll poll : pollList) {
if (openSessions.containsKey(poll.getId())) {
removeItem(poll);
addItem(getString(R.string.active), poll);
} else // if the poll doesn't have an open session or any closed sessions, it is still in the draft state
if (!closedSessions.containsKey(poll.getId())) {
removeItem(poll);
addItem(getString(R.string.draft), poll);
} else {
removeItem(poll);
addItem(getString(R.string.inactive), poll);
}
}
expandAllGroups();
if (linkHeaders.nextUrl != null) {
PollsManager.getNextPagePollSessions(linkHeaders.nextUrl, pollSessionCallback, true);
}
notifyDataSetChanged();
}
@Override
public void onFinished(ApiType type) {
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setRefreshing(false);
}
}
};
pollChoiceCallback = new StatusCallback<PollChoiceResponse>() {
@Override
public void onResponse(@NonNull Response<PollChoiceResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (getActivity() == null || type.isCache())
return;
List<PollChoice> pollChoices = response.body().getPollChoices();
if (pollChoices != null) {
pollChoiceArrayList.addAll(pollChoices);
}
// or generate the CSV, depending on which action they selected
if (!StatusCallback.moreCallsExist(linkHeaders)) {
AddQuestionFragment addQuestionFragment = new AddQuestionFragment();
// populate the current data with the bundle
Bundle bundle = new Bundle();
bundle.putParcelable(Constants.POLL_BUNDLE, selectedPoll);
bundle.putParcelableArrayList(Constants.POLL_CHOICES, pollChoiceArrayList);
addQuestionFragment.setArguments(bundle);
((FragmentManagerActivity) getActivity()).swapFragments(addQuestionFragment, AddQuestionFragment.class.getSimpleName());
} else {
// otherwise, get the next group of poll choices.
PollsManager.getNextPagePollChoices(linkHeaders.nextUrl, pollChoiceCallback, true);
}
}
@Override
public void onFinished(ApiType type) {
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setRefreshing(false);
}
}
};
}
use of retrofit2.http.GET in project autorest-clientruntime-for-java by Azure.
the class UserAgentTests method customUserAgentTests.
@Test
public void customUserAgentTests() throws Exception {
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder().addInterceptor(new UserAgentInterceptor().withUserAgent("Awesome")).addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
String header = chain.request().header("User-Agent");
Assert.assertEquals("Awesome", header);
return new Response.Builder().request(chain.request()).code(200).protocol(Protocol.HTTP_1_1).build();
}
});
ServiceClient serviceClient = new ServiceClient("http://localhost", clientBuilder, new Retrofit.Builder()) {
};
Response response = serviceClient.httpClient().newCall(new Request.Builder().get().url("http://localhost").build()).execute();
Assert.assertEquals(200, response.code());
}
use of retrofit2.http.GET in project autorest-clientruntime-for-java by Azure.
the class ServiceResponseBuilder method build.
@SuppressWarnings("unchecked")
@Override
public ServiceResponse<T> build(Response<ResponseBody> response) throws IOException {
if (response == null) {
return null;
}
int statusCode = response.code();
ResponseBody responseBody;
if (response.isSuccessful()) {
responseBody = response.body();
} else {
responseBody = response.errorBody();
}
if (responseTypes.containsKey(statusCode)) {
return new ServiceResponse<>((T) buildBody(statusCode, responseBody), response);
} else if (response.isSuccessful() && responseTypes.size() == 1) {
return new ServiceResponse<>((T) buildBody(statusCode, responseBody), response);
} else if (!throwOnGet404 && "GET".equals(response.raw().request().method()) && statusCode == 404) {
return new ServiceResponse<>(null, response);
} else {
try {
String responseContent = "";
if (responseBody != null) {
responseContent = responseBody.source().buffer().clone().readUtf8();
}
throw exceptionType.getConstructor(String.class, Response.class, (Class<?>) responseTypes.get(0)).newInstance("Status code " + statusCode + ", " + responseContent, response, buildBody(statusCode, responseBody));
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new IOException("Status code " + statusCode + ", but an instance of " + exceptionType.getCanonicalName() + " cannot be created.", e);
}
}
}
Aggregations