Class VRequest.Builder<T extends VRequest.Builder<T>>

  • Type Parameters:
    T - An class that extends builder
    Enclosing class:
    VRequest

    public static class VRequest.Builder<T extends VRequest.Builder<T>>
    extends Object
    A builder for VRequest class.
    • Constructor Detail

      • Builder

        protected Builder​(Request.Method method,
                          String url)
        Constructs an instance of builder.
        Parameters:
        method - The method for this request
        url - The url for this request
    • Method Detail

      • get

        public static VRequest.Builder get​(String url)
        Creates a new instance of builder with method type get.
        Parameters:
        url - url to fetch.
        Returns:
        an instance of builder.
      • post

        public static VRequest.Builder post​(String url)
        Creates a new instance of builder with method type post.
        Parameters:
        url - url to fetch.
        Returns:
        an instance of builder.
      • head

        public static VRequest.Builder head​(String url)
        Creates a new instance of builder with method type head.
        Parameters:
        url - url to fetch.
        Returns:
        an instance of builder.
      • put

        public static VRequest.Builder put​(String url)
        Creates a new instance of builder with method type put.
        Parameters:
        url - url to fetch.
        Returns:
        an instance of builder.
      • delete

        public static VRequest.Builder delete​(String url)
        Creates a new instance of builder with method type delete.
        Parameters:
        url - url to fetch.
        Returns:
        an instance of builder.
      • options

        public static VRequest.Builder options​(String url)
        Creates a new instance of builder with method type options.
        Parameters:
        url - url to fetch.
        Returns:
        an instance of builder.
      • setBody

        public final T setBody​(String body)
        Sets the request body to be used.
        Parameters:
        body - request body
        Returns:
        this
      • setSleepScheduler

        public final T setSleepScheduler​(SleepScheduler scheduler)
        Sets the sleep scheduler to be used, this will override the sleep scheduler defined in Crawler for this request. Defaults to none.
        Parameters:
        scheduler - sleep scheduler to be used.
        Returns:
        this
      • setProxy

        public final T setProxy​(org.apache.http.HttpHost proxy)
        Sets the proxy to be used, this will override the proxy selected in Fetcher for this request. Defaults to none.
        Parameters:
        proxy - proxy to be used.
        Returns:
        this
      • removeHeader

        public final T removeHeader​(String name)
        Remove a header from this request.
        Parameters:
        name - The key of the header to remove
        Returns:
        this
      • removeHeaders

        public final T removeHeaders()
        Remove all headers from this request.
        Returns:
        this
      • addHeaders

        public final T addHeaders​(Map<String,​String> headers)
        Add headers to be used

        This will merge with headers set in Crawler class. If a same key is found, this will override that header in Crawler class.

        Parameters:
        headers - request headers
        Returns:
        this
      • addHeader

        public final T addHeader​(String name,
                                 String value)
        Adds header to be used

        This will merge with headers set in Crawler class. If a same key is found, this will override that header in Crawler class.

        Parameters:
        name - name/key of the header
        value - value of the header
        Returns:
        this
      • setUrl

        public final T setUrl​(String url)
        Sets the url to be fetched.
        Parameters:
        url - url to fetch.
        Returns:
        this
      • build

        public VRequest build()
        Builds the request with the options specified.
        Returns:
        an instance of Request.