Search in sources :

Example 36 with POST

use of retrofit2.http.POST in project plaid by nickbutcher.

the class DesignerNewsStory method setupCommentField.

@NonNull
private View setupCommentField() {
    View enterCommentView = getLayoutInflater().inflate(R.layout.designer_news_enter_comment, commentsList, false);
    enterComment = (EditText) enterCommentView.findViewById(R.id.comment);
    postComment = (ImageButton) enterCommentView.findViewById(R.id.post_comment);
    postComment.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (designerNewsPrefs.isLoggedIn()) {
                if (TextUtils.isEmpty(enterComment.getText()))
                    return;
                enterComment.setEnabled(false);
                postComment.setEnabled(false);
                final Call<Comment> comment = designerNewsPrefs.getApi().comment(story.id, enterComment.getText().toString());
                comment.enqueue(new Callback<Comment>() {

                    @Override
                    public void onResponse(Call<Comment> call, Response<Comment> response) {
                        enterComment.getText().clear();
                        enterComment.setEnabled(true);
                        postComment.setEnabled(true);
                        commentsAdapter.addComment(response.body());
                    }

                    @Override
                    public void onFailure(Call<Comment> call, Throwable t) {
                        Toast.makeText(getApplicationContext(), "Failed to post comment :(", Toast.LENGTH_SHORT).show();
                        enterComment.setEnabled(true);
                        postComment.setEnabled(true);
                    }
                });
            } else {
                needsLogin(postComment, 0);
            }
            enterComment.clearFocus();
        }
    });
    enterComment.setOnFocusChangeListener(enterCommentFocus);
    return enterCommentView;
}
Also used : Response(retrofit2.Response) Call(retrofit2.Call) SharedElementCallback(android.app.SharedElementCallback) Callback(retrofit2.Callback) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) AuthorTextView(io.plaidapp.ui.widget.AuthorTextView) TextView(android.widget.TextView) PinnedOffsetView(io.plaidapp.ui.widget.PinnedOffsetView) RecyclerView(android.support.v7.widget.RecyclerView) NonNull(android.support.annotation.NonNull)

Example 37 with POST

use of retrofit2.http.POST 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");
        }
    });
}
Also used : OkHttpClient(okhttp3.OkHttpClient) IOException(java.io.IOException) ResponseBody(okhttp3.ResponseBody) Retrofit(retrofit2.Retrofit) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Example 38 with POST

use of retrofit2.http.POST in project instructure-android by instructure.

the class AddSubmissionFragment method setUpCallback.

// /////////////////////////////////////////////////////////////////////////
// CallBack
// /////////////////////////////////////////////////////////////////////////
public void setUpCallback() {
    canvasCallbackSubmission = new StatusCallback<Submission>() {

        @Override
        public void onResponse(@NonNull Response<Submission> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (!apiCheck()) {
                return;
            }
            Submission result = response.body();
            if (result.getBody() != null || result.getUrl() != null) {
                Toast.makeText(getActivity(), R.string.successPostingSubmission, Toast.LENGTH_LONG).show();
                // clear text fields because they are saved
                textSubmission.setText("");
                urlSubmission.setText("");
                // Send broadcast so list is updated.
                EventBus.getDefault().post(new FileUploadEvent(new FileUploadNotification(null, new ArrayList<Attachment>())));
                Navigation navigation = getNavigation();
                if (navigation != null)
                    navigation.popCurrentFragment();
            } else {
                Toast.makeText(getActivity(), R.string.errorPostingSubmission, Toast.LENGTH_LONG).show();
            }
        }
    };
    mLTIToolCallback = new StatusCallback<List<LTITool>>() {

        @Override
        public void onResponse(@NonNull Response<List<LTITool>> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            for (LTITool ltiTool : response.body()) {
                final String url = ltiTool.getUrl();
                if (url != null && url.contains("instructuremedia.com/lti/launch")) {
                    mArcUpload.setVisibility(View.VISIBLE);
                    mArcLTITool = ltiTool;
                    break;
                }
            }
            // check to see if we should automatically show the file upload dialog
            showFileUploadDialog();
        }

        @Override
        public void onFail(@Nullable Call<List<LTITool>> call, @NonNull Throwable error, @Nullable Response response) {
            // we don't want to show it if this failed due to there being no cache
            if (response != null && response.code() != 504) {
                showFileUploadDialog();
            }
        }
    };
}
Also used : Navigation(com.instructure.interactions.Navigation) Submission(com.instructure.canvasapi2.models.Submission) LTITool(com.instructure.canvasapi2.models.LTITool) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) ArrayList(java.util.ArrayList) FileUploadNotification(com.instructure.pandautils.utils.FileUploadNotification) Response(retrofit2.Response) ApiType(com.instructure.canvasapi2.utils.ApiType) FileUploadEvent(com.instructure.pandautils.utils.FileUploadEvent) List(java.util.List) ArrayList(java.util.ArrayList)

Example 39 with POST

use of retrofit2.http.POST in project autorest.java by Azure.

the class HeadersImpl method paramDatetimeRfc1123WithServiceResponseAsync.

/**
 * Send a post request with header values "scenario": "valid", "value": "Wed, 01 Jan 2010 12:34:56 GMT" or "scenario": "min", "value": "Mon, 01 Jan 0001 00:00:00 GMT".
 *
 * @param scenario Send a post request with header values "scenario": "valid" or "min"
 * @throws IllegalArgumentException thrown if parameters fail the validation
 * @return the {@link ServiceResponse} object if successful.
 */
public Observable<ServiceResponse<Void>> paramDatetimeRfc1123WithServiceResponseAsync(String scenario) {
    if (scenario == null) {
        throw new IllegalArgumentException("Parameter scenario is required and cannot be null.");
    }
    final DateTime value = null;
    DateTimeRfc1123 valueConverted = null;
    if (value != null) {
        valueConverted = new DateTimeRfc1123(value);
    }
    return service.paramDatetimeRfc1123(scenario, valueConverted).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Void>>>() {

        @Override
        public Observable<ServiceResponse<Void>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<Void> clientResponse = paramDatetimeRfc1123Delegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) ServiceResponse(com.microsoft.rest.ServiceResponse) DateTimeRfc1123(com.microsoft.rest.DateTimeRfc1123) DateTime(org.joda.time.DateTime) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody)

Example 40 with POST

use of retrofit2.http.POST in project autorest.java by Azure.

the class LRORetrysImpl method post202Retry200WithServiceResponseAsync.

/**
 * Long running post request, service returns a 500, then a 202 to the initial request, with 'Location' and 'Retry-After' headers, Polls return a 200 with a response body after success.
 *
 * @throws IllegalArgumentException thrown if parameters fail the validation
 * @return the observable for the request
 */
public Observable<ServiceResponseWithHeaders<Void, LRORetrysPost202Retry200Headers>> post202Retry200WithServiceResponseAsync() {
    final Product product = null;
    Observable<Response<ResponseBody>> observable = service.post202Retry200(product, this.client.acceptLanguage(), this.client.userAgent());
    return client.getAzureClient().getPostOrDeleteResultWithHeadersAsync(observable, new TypeToken<Void>() {
    }.getType(), LRORetrysPost202Retry200Headers.class);
}
Also used : Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) TypeToken(com.google.common.reflect.TypeToken) Product(fixtures.lro.models.Product)

Aggregations

ResponseBody (okhttp3.ResponseBody)40 Test (org.junit.Test)33 Request (okhttp3.Request)31 Response (retrofit2.Response)27 ServiceResponse (com.microsoft.rest.ServiceResponse)22 RequestBody (okhttp3.RequestBody)19 TypeToken (com.google.common.reflect.TypeToken)18 Product (fixtures.lro.models.Product)18 Buffer (okio.Buffer)14 MultipartBody (okhttp3.MultipartBody)13 Part (retrofit2.http.Part)10 OkHttpClient (okhttp3.OkHttpClient)8 Body (retrofit2.http.Body)8 HashMap (java.util.HashMap)7 LinkedHashMap (java.util.LinkedHashMap)7 Field (retrofit2.http.Field)6 FieldMap (retrofit2.http.FieldMap)6 PartMap (retrofit2.http.PartMap)6 List (java.util.List)5 Map (java.util.Map)5