Use API version 2

This commit is contained in:
Dan Stillman 2013-03-12 19:57:47 -04:00
parent e86cda2440
commit fe3ad1883d
3 changed files with 11 additions and 6 deletions

View file

@ -40,6 +40,7 @@ Zotero.HTTP = new function() {
* <li>cookieSandbox - The sandbox from which cookies should be taken</li>
* <li>debug - Log response text and status code</li>
* <li>dontCache - If set, specifies that the request should not be fulfilled from the cache</li>
* <li>headers - HTTP headers to include in the request</li>
* <li>responseType - The type of the response. See XHR 2 documentation for legal values</li>
* <li>responseCharset - The charset the response should be interpreted as</li>
* <li>successCodes - HTTP status codes that are considered successful</li>

View file

@ -27,6 +27,9 @@
Zotero.Sync.Storage.ZFS = (function () {
var _rootURI;
var _userURI;
var _headers = {
"Zotero-API-Version" : ZOTERO_CONFIG.API_VERSION
};
var _cachedCredentials = false;
/**
@ -38,7 +41,7 @@ Zotero.Sync.Storage.ZFS = (function () {
function getStorageFileInfo(item) {
var funcName = "Zotero.Sync.Storage.ZFS.getStorageFileInfo()";
return Zotero.HTTP.promise("GET", getItemInfoURI(item), { successCodes: [200, 404] })
return Zotero.HTTP.promise("GET", getItemInfoURI(item), { successCodes: [200, 404], headers: _headers })
.then(function (req) {
if (req.status == 404) {
return false;
@ -232,7 +235,7 @@ Zotero.Sync.Storage.ZFS = (function () {
body += "&zip=1";
}
return Zotero.HTTP.promise("POST", uri, { body: body, debug: true })
return Zotero.HTTP.promise("POST", uri, { body: body, headers: _headers, debug: true })
.then(function (req) {
if (!req.responseXML) {
throw new Error("Invalid response retrieving file upload parameters");
@ -508,7 +511,7 @@ Zotero.Sync.Storage.ZFS = (function () {
var body = "update=" + uploadKey + "&mtime=" + item.attachmentModificationTime;
// Register upload on server
return Zotero.HTTP.promise("POST", uri, { body: body, successCodes: [204] })
return Zotero.HTTP.promise("POST", uri, { body: body, headers: _headers, successCodes: [204] })
.then(function (req) {
updateItemFileInfo(item);
return {
@ -886,7 +889,7 @@ Zotero.Sync.Storage.ZFS = (function () {
})
.then(function () {
return Zotero.HTTP.promise("GET", lastSyncURI,
{ debug: true, successCodes: [200, 404] });
{ headers: _headers, successCodes: [200, 404], debug: true });
})
.then(function (req) {
// Not yet synced
@ -929,7 +932,7 @@ Zotero.Sync.Storage.ZFS = (function () {
var lastSyncURI = this._getLastSyncURI(libraryID);
return Zotero.HTTP.promise("POST", lastSyncURI, { debug: true, successCodes: [200, 404] })
return Zotero.HTTP.promise("POST", lastSyncURI, { headers: _headers, successCodes: [200, 404], debug: true })
.then(function (req) {
// Not yet synced
//
@ -987,7 +990,7 @@ Zotero.Sync.Storage.ZFS = (function () {
// TODO: move to root uri
uri.spec += "?auth=1";
return Zotero.HTTP.promise("GET", uri).
return Zotero.HTTP.promise("GET", uri, { headers: _headers }).
then(function (req) {
Zotero.debug("Credentials are cached");
_cachedCredentials = true;

View file

@ -33,6 +33,7 @@ const ZOTERO_CONFIG = {
WWW_BASE_URL: 'http://www.zotero.org/',
SYNC_URL: 'https://sync.zotero.org/',
API_URL: 'https://api.zotero.org/',
API_VERSION: 2,
PREF_BRANCH: 'extensions.zotero.',
BOOKMARKLET_URL: 'https://www.zotero.org/bookmarklet/',
VERSION: "3.1a1.SOURCE"