All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aaronbedra.web.request.WebRequester Maven / Gradle / Ivy

package com.aaronbedra.web.request;

import com.aaronbedra.web.types.Hostname;
import com.jnape.palatable.lambda.monad.MonadRec;
import okhttp3.HttpUrl;
import okhttp3.Request;
import okhttp3.Response;

import java.util.List;

public final class WebRequester, CookieType> {
    private final Hostname hostname;
    private final RestClient restClient;

    private WebRequester(
            Hostname hostname,
            RestClient restClient) {

        this.hostname = hostname;
        this.restClient = restClient;
    }

    public static , CookieType> WebRequester webRequester(
            Hostname hostname,
            RestClient restClient) {

        return new WebRequester<>(hostname, restClient);
    }

    public MonadRec requestHttp() {
        return restClient.request(buildRequest(getHttpUrl()));
    }

    public MonadRec requestHttps() {
        return restClient.request(buildRequest(getHttpsUrl()));
    }

    public List getCookies(HttpUrl url) {
        return restClient.getCookies(url);
    }

    public HttpUrl getHttpUrl() {
        return new HttpUrl
                .Builder()
                .scheme("http")
                .host(hostname.getValue())
                .build();
    }

    public HttpUrl getHttpsUrl() {
        return new HttpUrl
                .Builder()
                .scheme("https")
                .host(hostname.getValue())
                .build();
    }

    private Request buildRequest(HttpUrl url) {
        return new Request.Builder().url(url).build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy