API Docs for:
Show:

Bobik Class

Defined in: public/sdk/bobik.js:1

Copyright (c) 2012 Bobik Inc Version: 1.0 Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php

Download this SDK from: http://usebobik.com/sdk

Javascript client library for interacting with Bobik REST API

var bobik = new Bobik("YOUR_AUTH_TOKEN");
bobik.scrape({
    urls: ['amazon.com', 'zynga.com', 'http://finance.google.com/', 'http://shopping.yahoo.com'],
    queries:  ["//th", "//img/@src", "return document.title", "return $('script').length", "#logo", ".logo"]
  }, function (scraped_data) {
    if (!scraped_data) {
      console.log("Data is unavailable");
      return;
    }
    for (var url in scraped_data)
      console.log("Results from " + url + ": " + scraped_data[url]);
});

Bobik Javascript API is designed for asynchronous use, which provides better user experience and performance. If you use Bobik on server side, you can either make use of the callback paramer in the JSON request or build a synchronous wrapper similar to this SDK, which is fairly straightforward.

Constructor

Bobik

(
  • auth_token
  • timeout_ms
  • disable_debug_mode
)

Parameters:

  • auth_token String

    Authorization token

  • timeout_ms Integer

    How long to wait for the scraping job to complete (default is 30000 ms)

  • disable_debug_mode Boolean

    If set, disables debug messages that SDK prints into the console

Example:

var bobik_client = new Bobik("XXX", 60000, true);

Note that you don't need to pass 'auth_token' with every request if you use the Bobik object.

Methods

call_api

(
  • http_method
  • data
  • on_success
  • on_error
)

The base function for all Bobik-related AJAX requests

Parameters:

  • http_method String

    post/get

  • data Object

    The JSON request object (see API Docs for details)

  • on_success Function

    A handler function for receiving data (function(data)). Default handler just prints data to the console.

  • on_error Function

    A handler function for errors (function(error)). Default handler just prints data to the console.

log

(
  • data
)

A simple function that logs all progress messages Feel free to override this function (e.g. bobik_client.log = my_custom_logger_func)

Parameters:

  • data Object

    Any data that you want to log

progress

(
  • job_id
  • current_progress
)

Called whenever progress information is available. Feel free to override this function (e.g. bobik_client.progress = my_custom_func)

Parameters:

  • job_id String

    Job id

  • current_progress Function

    A value between 0 and 1 that indicates the job's progress

scrape

(
  • request
  • handler
)

Scrapes a list of urls using the given queries and makes a callback upon success

Parameters:

  • request Object

    The JSON request object (see API Docs for details)

  • handler Function

    An asynchronous callback to receive the scraped data (function(data))

wait_and_check

(
  • job_id
  • on_finished_callback
)
protected

Call this function to wait for a job to complete

Parameters:

  • job_id String

    Job id

  • on_finished_callback Function

    Function to be called upon expiration of timeout_ms or when results are ready

Properties

auth_token

String

Authorization token

debug

Boolean

Controls whether debug messages are printed to the console

Default: true

timeout_ms

String

How long to wait for the scraping job to complete (default is 30000 ms)

Default: 30000