added updateById

This commit is contained in:
skilion 2015-09-05 21:23:43 +02:00
parent 3357a013f7
commit 60a5b799f9

View file

@ -161,7 +161,7 @@ final class OneDriveApi
} }
// https://dev.onedrive.com/items/upload_put.htm // https://dev.onedrive.com/items/upload_put.htm
auto simpleUpload(string localPath, const(char)[] remotePath, const(char)[] eTag = null) JSONValue simpleUpload(string localPath, const(char)[] remotePath, const(char)[] eTag = null)
{ {
checkAccessTokenExpired(); checkAccessTokenExpired();
char[] url = itemByPathUrl ~ remotePath ~ ":/content"; char[] url = itemByPathUrl ~ remotePath ~ ":/content";
@ -178,6 +178,20 @@ final class OneDriveApi
return parseJSON(content); return parseJSON(content);
} }
// https://dev.onedrive.com/items/update.htm
JSONValue updateById(const(char)[] id, JSONValue data, const(char)[] eTag = null)
{
checkAccessTokenExpired();
char[] url = itemByIdUrl ~ id;
if (eTag) http.addRequestHeader("If-Match", eTag);
http.addRequestHeader("Content-Type", "application/json");
auto result = patch(url, data.toString());
http.clearRequestHeaders();
// remove the headers
setAccessToken(accessToken);
return result;
}
private void redeemToken(const(char)[] authCode) private void redeemToken(const(char)[] authCode)
{ {
string postData = "client_id=" ~ clientId ~ "&redirect_url=" ~ redirectUrl ~ "&client_secret=" ~ clientSecret; string postData = "client_id=" ~ clientId ~ "&redirect_url=" ~ redirectUrl ~ "&client_secret=" ~ clientSecret;
@ -215,12 +229,17 @@ final class OneDriveApi
newToken(); newToken();
} }
} }
private auto get(const(char)[] url) private auto get(const(char)[] url)
{ {
return parseJSON(.get(url, http)); return parseJSON(.get(url, http));
} }
private auto patch(T)(const(char)[] url, const(T)[] patchData)
{
return parseJSON(.patch(url, patchData, http));
}
private auto post(T)(const(char)[] url, const(T)[] postData) private auto post(T)(const(char)[] url, const(T)[] postData)
{ {
return parseJSON(.post(url, postData, http)); return parseJSON(.post(url, postData, http));