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 java.lang.Object
    A builder for VRequest class.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Builder​(Request.Method method, java.lang.String url)
      Constructs an instance of builder.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T addHeader​(java.lang.String name, java.lang.String value)
      Adds header to be used
      T addHeaders​(java.util.Map<java.lang.String,​java.lang.String> headers)
      Add headers to be used
      VRequest build()
      Builds the request with the options specified.
      static VRequest.Builder delete​(java.lang.String url)
      Creates a new instance of builder with method type delete.
      static VRequest.Builder get​(java.lang.String url)
      Creates a new instance of builder with method type get.
      static VRequest.Builder head​(java.lang.String url)
      Creates a new instance of builder with method type head.
      static VRequest.Builder options​(java.lang.String url)
      Creates a new instance of builder with method type options.
      static VRequest.Builder post​(java.lang.String url)
      Creates a new instance of builder with method type post.
      static VRequest.Builder put​(java.lang.String url)
      Creates a new instance of builder with method type put.
      T removeHeader​(java.lang.String name)
      Remove a header from this request.
      T removeHeaders()
      Remove all headers from this request.
      T setBody​(java.lang.String body)
      Sets the request body to be used.
      T setProxy​(org.apache.http.HttpHost proxy)
      Sets the proxy to be used, this will override the proxy selected in Fetcher for this request.
      T setSleepScheduler​(SleepScheduler scheduler)
      Sets the sleep scheduler to be used, this will override the sleep scheduler defined in Crawler for this request.
      T setUrl​(java.lang.String url)
      Sets the url to be fetched.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Builder

        protected Builder​(Request.Method method,
                          java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.util.Map<java.lang.String,​java.lang.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​(java.lang.String name,
                                 java.lang.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​(java.lang.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.