It is recommended that your plugin delegate the management of it's downloads to the application; and it is in fact necessary to do so to benefit from the authentication mechanism of the GoodBarber API calls.

By using the download method, you can benefit from the application's automatic cache system. 

When you request access to a remote resource you may specify if you wish to receive a version of the resource that was previoulsy cached. 

Following a download method call, your plugin may receive one of the following callbacks:

- gbRequestDidFail ( tag, errorCode, errorMessage )
- gbRequestDidSuccessWithCache ( tag, data, src )
- gbRequestDidSuccess ( tag, data, src )

picture

1

Method : request

The request method simply allows you to request access to a remote resource.

You must specify the following parameters:
url: The URL of the resource you wish to access (must be URL encoded)
tag: a tag (integer) to identify your request
cache: YES if you wish to receive a cached version if there is one, via the callback gbRequestDidSuccessWithCache, otherwise NO
- method: (optional) the HTTP method will be used in the request (default value: GET)

You may call this method with POST parameters, that will also be passed on to the body of the request.

Example of the download of a JSON stream in GET with a request for a cached version, if there is one:
<a href="goodbarber://request?url=http%3A%2F%2Fwww.monsite.com%2F/monjson.com&tag=1&cache=YES">Télécharger le JSON</a>

Example of the download of an image in GET without callback for a cached version:
<a href="goodbarber://request?url=http%3A%2F%2Fwww.monsite.com%2F/monimage.jpg&tag=2&cache=NO">Télécharger l'image</a>


2

Request pathway

picture

3

Callback : gbRequestDidFail

The callback gbRequestDidFail is called if the request fails. It is strongly recommended to implement this callback method to correctly handle request fails.

The method must include three parameters:
tag : the tag (integer) defined at the call of the request
errorCode : 0 if there is a network problem, the HTTP error code otherwise
errorMessage : a description of the problem leading to the request failure


4

Callback : gbRequestDidSuccessWithCache

The callback gbRequestDidSuccessWithCache is called immediately before the beginning of the HTTP request if the called resource is present in the application's cache (and the request was called with the cache parameter set to YES).

The method to be implemented must contain three parameters:
tag: the tag (integer) defined at the request call
data: the raw data of the resource
src: the pathway to the resource in the file system


5

Callback : gbRequestDidSuccess

The callback gbRequestDidSuccess is called in case of a success of the HTTP request.

The method to be implemented must contain three paramters:
tag: the tag (integer) defined at the request call
data: the raw data of the resource
src: the pathway to the resource in the file system


Outros artigos