Skip to content
sdepold edited this page Sep 13, 2010 · 11 revisions

Information

DaWanda offers a variety of numerous frameworks to request the DaWanda API. They combine the necessary queries and are supposed to make the development of applications easier. At the moment we offer libraries for JavaScript and PHP as well as a Ruby Gem with according functionality.

JavaScript-Framework

The Prototype-based JavaScript-framework communicates with the DaWanda-server according to the JSONP convention. Since Prototype does not support AJAX-requests on JSONP basis, the framework uses an extension from Dan Dean and Tobie Langel. Should the lacking support of Prototype be eliminated at some point in the future, the framework will be changed accordingly.

Structure of the Repositories

This repository contains the following relevant components:

/lib/javascript/v1/src/dawanda.js: Basic component; creates the requests for the API.
/lib/javascript/v1/lib/: Contains Prototype 1.6.1 as well as the JSONP extension.
/lib/javascript/v1/spec/: contains tests based on JSpec. spec.dom.html launches the tests.
/examples/javascript/: contains examples, which are using the JavaScript-framework

Basic Principles

If Prototype, its JSONP extension as well as the DaWanda JavaScript-framework have been included into a website, it is possible to create an object of the class DaWanda.API. The constructor expects an API-Key as well as a supporting/corresponding language as parameters.

var api = new DaWanda.API("api-key", "language");

Such an object supports the functions which have been described in the Wiki. Depending on the used function some mandatory parameters have to be passed. Furthermore, the last parameter may contain options. This could be for example the entries per page (per_page) or the number of pages (page). You may define callbacks for the case of a failure or success in the optional parameter hash.

The following example shows a query to the DaWanda API:

var username = "dawanda-merchandise";
api.getShopDetails(
  username, {
    onSuccess: function(data) {
      // evaluate data
    },
    onFailure: function(data) {
      // evaluate error
    }
  }
);

PHP-Framework

If requests are not supposed to be created asynchronous or on the client side, you may use this PHP-framework. It provides information on the server-side.

Structure of the Repositories

This repository contains the following relevant components:

/lib/php/v1/src/dawanda.php: basic component, which creates the API requests
/lib/php/v1/test/: contains tests based on PHPUnit
/examples/php/: contains examples which are using the PHP-framework

Basic Principles

If the DaWanda-PHP-framework has been included, it is possible to create an object of the class DaWandaAPI. The constructor expects an API-key as well as one of the supported languages.

include("lib/php/v1/src/dawanda.php");
$api = new DaWandaAPI("api-key", "language");

Such an object supports the functions described in the Wiki. Depending on the used function some mandatory parameters have to be passed. Since the requests happen synchronic, the return value of the function is already the answer of the DaWanda server. If an error occurs during the processing of the request, an exception will be throwed.

The following example demonstrates such a request to the DaWanda API:

$error = null;
$products = null;
	
try {
  $products = $api->getProductsForShop($_GET["username"], array("per_page" => 7));
} catch(Exception $e) {
  $error = "Username is invalid!";
}

Ruby-Framework

You may find further information concerning the Ruby-framework here: http://github.com/dawanda/dawanda-client.

Clone this wiki locally