mirror of
https://github.com/Hopiu/RandomWallpaperGnome3.git
synced 2026-03-16 22:20:24 +00:00
update unsplash source adapter to correspond to new unsplash API guidelines
This commit is contained in:
parent
a1f6838168
commit
d03caa0246
1 changed files with 21 additions and 12 deletions
|
|
@ -37,7 +37,7 @@ let BaseAdapter = new Lang.Class({
|
|||
fileName: function (uri) {
|
||||
let base = decodeURIComponent(uri);
|
||||
base = base.substring(base.lastIndexOf('/') + 1);
|
||||
if(base.indexOf('?') >= 0) {
|
||||
if (base.indexOf('?') >= 0) {
|
||||
base = base.substr(0, base.indexOf('?'));
|
||||
}
|
||||
return base;
|
||||
|
|
@ -114,27 +114,36 @@ let UnsplashAdapter = new Lang.Class({
|
|||
|
||||
this._readOptionsFromSettings();
|
||||
let optionsString = this._generateOptionsString();
|
||||
let url = 'https://api.unsplash.com/photos/random?' + optionsString;
|
||||
url += 'client_id=64daf439e9b579dd566620c0b07022706522d87b255d06dd01d5470b7f193b8d';
|
||||
let clientParam = 'client_id=2e4e49adee7dcaf75515d383086909e1ed5f0b08db60becf8ec58bc63cbc418a';
|
||||
|
||||
let url = 'https://api.unsplash.com/photos/random?' + optionsString + clientParam;
|
||||
url = encodeURI(url);
|
||||
|
||||
let message = Soup.Message.new('GET', url);
|
||||
|
||||
let utmParameters = '?utm_source=RandomWallpaperGnome3&utm_medium=referral&utm_campaign=api-credit';
|
||||
let utmParameters = 'utm_source=RandomWallpaperGnome3&utm_medium=referral&utm_campaign=api-credit';
|
||||
|
||||
session.queue_message(message, (session, message) => {
|
||||
let data = JSON.parse(message.response_body.data);
|
||||
|
||||
let imageUrl = encodeURI(data.links.download + utmParameters);
|
||||
let authorName = data.user.name;
|
||||
let authorUrl = encodeURI(data.user.links.html);
|
||||
|
||||
if (callback) {
|
||||
let historyEntry = new HistoryModule.HistoryEntry(authorName, this.sourceName, encodeURI(imageUrl));
|
||||
historyEntry.source.sourceUrl = encodeURI(this.sourceUrl + utmParameters);
|
||||
historyEntry.source.authorUrl = encodeURI(authorUrl + utmParameters);
|
||||
callback(historyEntry);
|
||||
}
|
||||
let downloadLocation = data.links.download_location + '?' + clientParam;
|
||||
let downloadMessage = Soup.Message.new('GET', downloadLocation);
|
||||
|
||||
session.queue_message(downloadMessage, (session, message) => {
|
||||
let downloadData = JSON.parse(message.response_body.data);
|
||||
|
||||
let imageUrl = encodeURI(downloadData.url + '&' + utmParameters);
|
||||
|
||||
if (callback) {
|
||||
let historyEntry = new HistoryModule.HistoryEntry(authorName, this.sourceName, encodeURI(imageUrl));
|
||||
historyEntry.source.sourceUrl = encodeURI(this.sourceUrl + '?' + utmParameters);
|
||||
historyEntry.source.authorUrl = encodeURI(authorUrl + '?' + utmParameters);
|
||||
callback(historyEntry);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
|
|
@ -296,7 +305,7 @@ let GenericJsonAdapter = new Lang.Class({
|
|||
let response = JSON.parse(message.response_body.data);
|
||||
let JSONPath = this._settings.get("generic-json-response-path", "string");
|
||||
let imageUrl = this._jsonPathParser.access(response, JSONPath);
|
||||
imageUrl = this._settings.get("generic-json-url-prefix", "string")+imageUrl;
|
||||
imageUrl = this._settings.get("generic-json-url-prefix", "string") + imageUrl;
|
||||
|
||||
if (callback) {
|
||||
let historyEntry = new HistoryModule.HistoryEntry(null, 'Generic JSON Source', imageUrl);
|
||||
|
|
|
|||
Loading…
Reference in a new issue