bobik
Class BobikClient

java.lang.Object
  extended by bobik.BobikClient

public class BobikClient
extends java.lang.Object

Provides programmatic interface to Bobik API. Download this SDK from Bobik SDK on GitHub
Format of request and response objects is explained in detail at Bobik API Docs

Example:

 BobikClient bobik = new BobikClient("YOUR_AUTH_KEY");

    JSONObject request = new JSONObject();
    for (String url : new String[]{"amazon.com", "google.com"})
        request.accumulate("urls", url);
    for (String query : new String[]{"//a/@href", "return $('.logo').length"})
        request.accumulate("queries", query);

    Job job = bobik.scrape(request, new JobListener() {
        public void onSuccess(JSONObject scraped_data) {
            System.out.println("Received data: " + scraped_data);
        }

        public void onProgress(float currentProgress) {
            System.out.println("Current progress is " + currentProgress*100 + "%");
        }

        public void onErrors(Collection<String> errors){
            for (String s : errors)
                System.err.println("Error for job " + job.id() + ": " + s);
        }
    });

    // Block to prevent the thread from exiting along with the unfinished scraping job.
    // Not needed if the thread will remain active regardless.
    job.waitForCompletion();
 
 

Author:
Eugene Mirkin, Ashwath Murthy

Constructor Summary
BobikClient(java.lang.String authToken)
           
 
Method Summary
 java.lang.String getAuthToken()
           
 int getTimeoutMs()
           
 Job scrape(JSONObject request, JobListener listener)
          Kicks off an asynchronous scraping job and returns a proxy object.
 void setAuthToken(java.lang.String authToken)
           
 void setTimeoutMs(int timeoutMs)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BobikClient

public BobikClient(java.lang.String authToken)
Parameters:
authToken -
Method Detail

scrape

public Job scrape(JSONObject request,
                  JobListener listener)
           throws BobikException,
                  java.io.IOException,
                  JSONException,
                  java.util.concurrent.ExecutionException,
                  java.lang.InterruptedException
Kicks off an asynchronous scraping job and returns a proxy object. This proxy is only for added convenience of monitoring/cancelling the job. The listener you pass as a parameter does all this and more already.

Parameters:
request - The scraping request, built in accordance with http://usebobik.com/api/docs#func_ref
listener - An object encapsulating various useful callbacks
Returns:
proxy to monitor/abort the scraping job
Throws:
BobikException - thrown on all Bobik-specific errors
java.io.IOException - thrown on network problems
JSONException - not common, thrown on surprise JSON parsing errors
java.util.concurrent.ExecutionException - not common, thrown if there's a client-level error during the scheduling of threads
java.lang.InterruptedException - not common, thrown if there's a client-level error during the scheduling of threads

getAuthToken

public java.lang.String getAuthToken()

setAuthToken

public void setAuthToken(java.lang.String authToken)

getTimeoutMs

public int getTimeoutMs()

setTimeoutMs

public void setTimeoutMs(int timeoutMs)