Line 0
Link Here
|
0 |
- |
1 |
if ( typeof KOHA == "undefined" || !KOHA ) { |
|
|
2 |
var KOHA = {}; |
3 |
} |
4 |
|
5 |
KOHA.OverDrive = ( function() { |
6 |
var proxy_base_url = '/cgi-bin/koha/svc/overdrive_proxy'; |
7 |
var library_base_url = 'http://api.overdrive.com/v1/libraries/'; |
8 |
return { |
9 |
Get: function( url, params, callback ) { |
10 |
$.ajax( { |
11 |
type: 'GET', |
12 |
url: url.replace( /https?:\/\/api.overdrive.com\/v1/, proxy_base_url ), |
13 |
dataType: 'json', |
14 |
data: params, |
15 |
error: function( xhr, error ) { |
16 |
try { |
17 |
callback( JSON.parse( xhr.responseText )); |
18 |
} catch ( e ) { |
19 |
callback( {error: xhr.responseText || true} ); |
20 |
} |
21 |
}, |
22 |
success: callback |
23 |
} ); |
24 |
}, |
25 |
GetCollectionURL: function( library_id, callback ) { |
26 |
if ( KOHA.OverDrive.collection_url ) { |
27 |
callback( KOHA.OverDrive.collection_url ); |
28 |
return; |
29 |
} |
30 |
|
31 |
KOHA.OverDrive.Get( |
32 |
library_base_url + library_id, |
33 |
{}, |
34 |
function ( data ) { |
35 |
if ( data.error ) { |
36 |
callback( data ); |
37 |
return; |
38 |
} |
39 |
|
40 |
KOHA.OverDrive.collection_url = data.links.products.href; |
41 |
|
42 |
callback( data.links.products.href ); |
43 |
} |
44 |
); |
45 |
}, |
46 |
Search: function( library_id, q, limit, offset, callback ) { |
47 |
KOHA.OverDrive.GetCollectionURL( library_id, function( data ) { |
48 |
if ( data.error ) { |
49 |
callback( data ); |
50 |
return; |
51 |
} |
52 |
|
53 |
KOHA.OverDrive.Get( |
54 |
data, |
55 |
{q: q, limit: limit, offset: offset}, |
56 |
callback |
57 |
); |
58 |
} ); |
59 |
} |
60 |
}; |
61 |
} )(); |