Search in sources :

Example 1 with Request

use of com.mopub.volley.Request in project prebid-mobile-android by prebid.

the class AdServerTest method processMoPubRequest.

private void processMoPubRequest(Request request) {
    Networking.getRequestQueue(mContext).removeRequestFinishedListener(mMoPubRequestFinishedListener);
    try {
        String url = request.getUrl();
        if (!TextUtils.isEmpty(url) && request.getBody() != null) {
            ByteArrayInputStream postBodyStream = new ByteArrayInputStream(request.getBody());
            String postBody = IOUtil.getStringFromStream(postBodyStream);
            postBodyStream.close();
            checkRequestForKeywords(url, postBody);
            OkHttpClient client = new OkHttpClient.Builder().build();
            RequestBody body = RequestBody.create(MediaType.parse(request.getBodyContentType()), postBody);
            okhttp3.Request httpRequest = new okhttp3.Request.Builder().url(url).post(body).build();
            client.newCall(httpRequest).enqueue(new Callback() {

                @Override
                public void onFailure(Call call, IOException e) {
                    Log.e(TAG, e.getMessage());
                    invokeContainsPrebidCreative(false);
                }

                @Override
                public void onResponse(Call call, Response response) throws IOException {
                    if (response.body() != null) {
                        InputStream inputStream = response.body().byteStream();
                        mAdServerResponse = IOUtil.getStringFromStream(inputStream);
                        inputStream.close();
                        checkResponseForPrebidCreative();
                    } else {
                        invokeContainsPrebidCreative(false);
                    }
                }
            });
        }
    } catch (Exception exception) {
        Log.e(TAG, exception.getMessage());
    }
}
Also used : Call(okhttp3.Call) OkHttpClient(okhttp3.OkHttpClient) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PublisherAdRequest(com.google.android.gms.ads.doubleclick.PublisherAdRequest) Request(com.mopub.volley.Request) IOException(java.io.IOException) IOException(java.io.IOException) Response(okhttp3.Response) Callback(okhttp3.Callback) ByteArrayInputStream(java.io.ByteArrayInputStream) RequestBody(okhttp3.RequestBody)

Example 2 with Request

use of com.mopub.volley.Request in project prebid-mobile-android by prebid.

the class SdkTest method processMoPubRequest.

private void processMoPubRequest(Request request) {
    Networking.getRequestQueue(mContext).removeRequestFinishedListener(mMoPubRequestFinishedListener);
    try {
        String url = request.getUrl();
        if (!TextUtils.isEmpty(url) && request.getBody() != null) {
            ByteArrayInputStream postBodyStream = new ByteArrayInputStream(request.getBody());
            String postBody = IOUtil.getStringFromStream(postBodyStream);
            postBodyStream.close();
            OkHttpClient client = new OkHttpClient.Builder().build();
            RequestBody body = RequestBody.create(MediaType.parse(request.getBodyContentType()), postBody);
            okhttp3.Request httpRequest = new okhttp3.Request.Builder().url(url).post(body).build();
            client.newCall(httpRequest).enqueue(new Callback() {

                @Override
                public void onFailure(Call call, IOException e) {
                    Log.e(TAG, e.getMessage());
                    invokeContainsPrebidCreative(false);
                }

                @Override
                public void onResponse(Call call, Response response) throws IOException {
                    if (response.body() != null) {
                        InputStream inputStream = response.body().byteStream();
                        mAdServerResponse = IOUtil.getStringFromStream(inputStream);
                        inputStream.close();
                        checkResponseForPrebidCreative();
                    } else {
                        invokeContainsPrebidCreative(false);
                    }
                }
            });
            mContext.runOnUiThread(() -> {
                if (mListener != null) {
                    mListener.requestSentToAdServer(url, postBody);
                }
            });
        }
    } catch (Exception exception) {
        Log.e(TAG, exception.getMessage());
    }
}
Also used : Call(okhttp3.Call) OkHttpClient(okhttp3.OkHttpClient) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PublisherAdRequest(com.google.android.gms.ads.doubleclick.PublisherAdRequest) Request(com.mopub.volley.Request) IOException(java.io.IOException) IOException(java.io.IOException) Response(okhttp3.Response) Callback(okhttp3.Callback) ByteArrayInputStream(java.io.ByteArrayInputStream) RequestBody(okhttp3.RequestBody)

Aggregations

PublisherAdRequest (com.google.android.gms.ads.doubleclick.PublisherAdRequest)2 Request (com.mopub.volley.Request)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Call (okhttp3.Call)2 Callback (okhttp3.Callback)2 OkHttpClient (okhttp3.OkHttpClient)2 RequestBody (okhttp3.RequestBody)2 Response (okhttp3.Response)2