Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unsplash-js

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unsplash-js - npm Package Compare versions

Comparing version 1.1.0 to 2.0.1

examples/node/app.js

210

dist/unsplash.js

@@ -93,5 +93,5 @@ (function webpackUniversalModuleDefinition(root, factory) {

var _curatedBatches = __webpack_require__(5);
var _collections = __webpack_require__(5);
var _curatedBatches2 = _interopRequireDefault(_curatedBatches);
var _collections2 = _interopRequireDefault(_collections);

@@ -124,3 +124,3 @@ var _stats = __webpack_require__(8);

this.categories = _categories2.default.bind(this)();
this.curatedBatches = _curatedBatches2.default.bind(this)();
this.collections = _collections2.default.bind(this)();
this.stats = _stats2.default.bind(this)();

@@ -170,4 +170,4 @@ }

exports.decode = exports.parse = __webpack_require__(12);
exports.encode = exports.stringify = __webpack_require__(13);
exports.decode = exports.parse = __webpack_require__(13);
exports.encode = exports.stringify = __webpack_require__(14);

@@ -221,4 +221,4 @@

redirect_uri: _this._callbackUrl,
code: code,
grant_type: "authorization_code"
grant_type: "authorization_code",
code: code
},

@@ -295,10 +295,13 @@ oauth: true

});
exports.default = curatedBatches;
function curatedBatches() {
exports.default = collections;
function collections() {
var _this = this;
return {
listCuratedBatches: function listCuratedBatches(page, perPage) {
var url = "/curated_batches";
listCollections: function listCollections() {
var page = arguments.length <= 0 || arguments[0] === undefined ? 1 : arguments[0];
var perPage = arguments.length <= 1 || arguments[1] === undefined ? 10 : arguments[1];
var url = "/collections";
var query = {

@@ -316,18 +319,62 @@ page: page,

curatedBatch: function curatedBatch(id) {
var url = "/curated_batches/" + id;
listCuratedCollections: function listCuratedCollections() {
var page = arguments.length <= 0 || arguments[0] === undefined ? 1 : arguments[0];
var perPage = arguments.length <= 1 || arguments[1] === undefined ? 10 : arguments[1];
var url = "/collections/curated";
var query = {
page: page,
per_page: perPage
};
return _this.request({
url: url,
method: "GET"
method: "GET",
query: query
});
},
curatedBatchPhotos: function curatedBatchPhotos(id) {
var url = "/curated_batches/" + id + "/photos";
getCollection: collection.bind(this, false),
getCuratedCollection: collection.bind(this, true),
getCuratedCollectionPhotos: collectionPhotos.bind(this, true),
getCollectionPhotos: collectionPhotos.bind(this, false),
createCollection: createUpdateCollection.bind(this, null),
updateCollection: createUpdateCollection.bind(this),
deleteCollection: function deleteCollection(id) {
var url = "/collections/" + id;
return _this.request({
url: url,
method: "GET"
method: "DELETE"
});
},
addPhotoToCollection: function addPhotoToCollection(collectionId, photoId) {
var url = "/collections/" + collectionId + "/add";
return _this.request({
url: url,
method: "POST",
body: {
photo_id: photoId
}
});
},
removePhotoFromCollection: function removePhotoFromCollection(collectionId, photoId) {
var url = "/collections/" + collectionId + "/remove";
return _this.request({
url: url,
method: "DELETE",
body: {
photo_id: photoId
}
});
}

@@ -337,2 +384,35 @@ };

function collection(isCurated, id) {
var url = isCurated ? "/collections/curated/" + id : "/collections/" + id;
return this.request({
url: url,
method: "GET"
});
}
function collectionPhotos(isCurated, id) {
var url = isCurated ? "/collections/curated/" + id + "/photos" : "/collections/" + id + "/photos";
return this.request({
url: url,
method: "GET"
});
}
function createUpdateCollection(id, title, description, isPrivate) {
var url = id ? "/collections/" + id : "/collections";
var body = {
title: title,
description: description,
"private": isPrivate
};
return this.request({
url: url,
method: id ? "PUT" : "POST",
body: body
});
}
/***/ },

@@ -465,2 +545,4 @@ /* 6 */

getRandomPhoto: function getRandomPhoto(width, height, q, username, featured, category) {
var cacheBuster = arguments.length <= 6 || arguments[6] === undefined ? new Date().getTime() : arguments[6];
var url = "/photos/random";

@@ -474,3 +556,4 @@

w: width,
h: height
h: height,
cacheBuster: cacheBuster // Avoid ajax response caching
};

@@ -631,3 +714,3 @@

exports.bodyToFormData = bodyToFormData;
exports.formUrlEncode = formUrlEncode;
exports.buildFetchOptions = buildFetchOptions;

@@ -637,11 +720,10 @@

var FormData = true ? window.FormData : require("form-data");
var _formUrlencoded = __webpack_require__(12);
function bodyToFormData(body) {
var postBody = new FormData();
Object.keys(body).forEach(function (key) {
postBody.append(key, body[key]);
});
var _formUrlencoded2 = _interopRequireDefault(_formUrlencoded);
return postBody;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function formUrlEncode(body) {
return (0, _formUrlencoded2.default)(body);
}

@@ -661,2 +743,6 @@

if (body) {
headers["Content-Type"] = "application/x-www-form-urlencoded";
}
if (query) {

@@ -671,3 +757,3 @@ url = decodeURIComponent(url + "?" + (0, _querystring.stringify)(query));

headers: headers,
body: method === "POST" && body ? bodyToFormData(body) : undefined
body: method !== "GET" && body ? formUrlEncode(body) : undefined
}

@@ -681,2 +767,70 @@ };

// Filename: formurlencoded.js
// Timestamp: 2016.01.18-15:36:37 (last modified)
// Author(s): Bumblehead (www.bumblehead.com), JBlashill (james@blashill.com)
//
// http://www.w3.org/TR/html5/forms.html#url-encoded-form-data
// input: {one:1,two:2} return: '[one]=1&[two]=2'
var formurlencoded = module.exports = function (data, opts) {
opts = typeof opts === 'object' ? opts : {};
function encode (value) {
return String(value)
.replace(/[^ !'()~\*]*/g, encodeURIComponent)
.replace(/ /g, '+')
.replace(/[!'()~\*]/g, function (ch) {
return '%' + ch.charCodeAt().toString(16).slice(-2).toUpperCase();
});
}
function keys (obj) {
var keys = Object.keys(obj);
return opts.sorted ? keys.sort() : keys;
}
function filterjoin (arr) {
return arr.filter(function (e) { return e; }).join('&');
}
function objnest (name, obj) {
return filterjoin(keys(obj).map(function (key) {
return nest(name + '[' + key + ']', obj[key]);
}));
}
function arrnest (name, arr) {
return filterjoin(arr.map(function (elem) {
return nest(name + '[]', elem);
}));
}
function nest (name, value) {
var type = typeof value,
f = null;
if (value === f) {
f = opts.ignorenull ? f : encode(name) + '=' + f;
} else if (/string|number|boolean/.test(type)) {
f = encode(name) + '=' + encode(value);
} else if (Array.isArray(value)) {
f = arrnest(name, value);
} else if (type === 'object') {
f = objnest(name, value);
}
return f;
}
return filterjoin(keys(data).map(function (key) {
return nest(key, data[key]);
}));
};
/***/ },
/* 13 */
/***/ function(module, exports) {
// Copyright Joyent, Inc. and other Node contributors.

@@ -765,3 +919,3 @@ //

/***/ },
/* 13 */
/* 14 */
/***/ function(module, exports) {

@@ -768,0 +922,0 @@

2

dist/unsplash.min.js

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Unsplash=t():e.Unsplash=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e){return e.json()}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();t.toJson=u;var a=r(1),s=r(11),c=r(10),l=r(3),d=n(l),f=r(6),h=n(f),p=r(9),_=n(p),m=r(7),b=n(m),v=r(4),y=n(v),g=r(5),T=n(g),O=r(8),q=n(O),U=(0,c.requireFetch)(),P=function(){function e(t){o(this,e),this._apiUrl=t.apiUrl||a.API_URL,this._apiVersion=t.apiVersion||a.API_VERSION,this._applicationId=t.applicationId,this._secret=t.secret,this._callbackUrl=t.callbackUrl,this._bearerToken=t.bearerToken,this.auth=d["default"].bind(this)(),this.currentUser=h["default"].bind(this)(),this.users=_["default"].bind(this)(),this.photos=b["default"].bind(this)(),this.categories=y["default"].bind(this)(),this.curatedBatches=T["default"].bind(this)(),this.stats=q["default"].bind(this)()}return i(e,[{key:"request",value:function(e){var t=s.buildFetchOptions.bind(this)(e),r=t.url,n=t.options;return U(r,n)}}]),e}();t["default"]=P},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.API_URL="https://api.unsplash.com",t.API_VERSION="v1",t.OAUTH_AUTHORIZE_URL="https://unsplash.com/oauth/authorize",t.OAUTH_TOKEN_URL="https://unsplash.com/oauth/token"},function(e,t,r){"use strict";t.decode=t.parse=r(12),t.encode=t.stringify=r(13)},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(){var e=this;return{getAuthenticationUrl:function(){var t=arguments.length<=0||void 0===arguments[0]?["public"]:arguments[0],r=i["default"].stringify({client_id:e._applicationId,redirect_uri:e._callbackUrl,response_type:"code",scope:t.length>1?t.join("+"):t.toString()});return decodeURIComponent(a.OAUTH_AUTHORIZE_URL+"?"+r)},userAuthentication:function(t){var r=a.OAUTH_TOKEN_URL;return e.request({url:r,method:"POST",body:{client_id:e._applicationId,client_secret:e._secret,redirect_uri:e._callbackUrl,code:t,grant_type:"authorization_code"},oauth:!0})},setBearerToken:function(t){t&&(e._bearerToken=t)}}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=o;var u=r(2),i=n(u),a=r(1)},function(e,t){"use strict";function r(){var e=this;return{listCategories:function(){var t="/categories";return e.request({url:t,method:"GET"})},category:function(t){var r="/categories/"+t;return e.request({url:r,method:"GET"})},categoryPhotos:function(t,r,n){var o="/categories/"+t+"/photos",u={page:r,per_page:n};return e.request({url:o,method:"GET",query:u})}}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r},function(e,t){"use strict";function r(){var e=this;return{listCuratedBatches:function(t,r){var n="/curated_batches",o={page:t,per_page:r};return e.request({url:n,method:"GET",query:o})},curatedBatch:function(t){var r="/curated_batches/"+t;return e.request({url:r,method:"GET"})},curatedBatchPhotos:function(t){var r="/curated_batches/"+t+"/photos";return e.request({url:r,method:"GET"})}}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r},function(e,t){"use strict";function r(){var e=this;return{profile:function(){var t="/me";return e.request({url:t,method:"GET"})},updateProfile:function(t){var r="/me",n=t.username,o=t.firstName,u=t.lastName,i=t.email,a=t.url,s=t.location,c=t.bio,l=t.instagramUsername,d={username:n,first_name:o,last_name:u,email:i,url:a,location:s,bio:c,instagram_username:l};return Object.keys(d).forEach(function(e){d[e]||delete d[e]}),e.request({url:r,method:"POST",body:d})}}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r},function(e,t){"use strict";function r(){var e=this;return{listPhotos:function(t,r){var n="/photos",o={page:t,per_page:r};return e.request({url:n,method:"GET",query:o})},searchPhotos:function(t){var r=arguments.length<=1||void 0===arguments[1]?[""]:arguments[1],n=arguments[2],o=arguments[3],u="/photos/search",i={query:t,category:r.length>1?r.join(","):r.toString(),page:n,per_page:o};return e.request({url:u,method:"GET",query:i})},getPhoto:function(t,r,n,o){var u="/photos/"+t,i={w:r,h:n,rect:o};return e.request({url:u,method:"GET",query:i})},getRandomPhoto:function(t,r,n,o,u,i){var a="/photos/random",s={category:i,featured:u,username:o,query:n,w:t,h:r};return e.request({url:a,method:"GET",query:s})},uploadPhoto:function(t){if(!e._bearerToken)throw new Error("Requires a bearerToken to be set.");var r="/photos";return e.request({url:r,method:"POST",body:{photo:t}})},likePhoto:function(t){if(!e._bearerToken)throw new Error("Requires a bearerToken to be set.");var r="/photos/"+t+"/like";return e.request({url:r,method:"POST"})},unlikePhoto:function(t){if(!e._bearerToken)throw new Error("Requires a bearerToken to be set.");var r="/photos/"+t+"/like";return e.request({url:r,method:"DELETE"})}}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r},function(e,t){"use strict";function r(){var e=this;return{total:function(){var t="/stats";return e.request({url:t,method:"GET"})}}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r},function(e,t){"use strict";function r(){var e=this;return{profile:function(t){var r="/users/"+t;return e.request({url:r,method:"GET"})},photos:function(t){var r="/users/"+t+"/photos";return e.request({url:r,method:"GET"})},likes:function(t,r,n){var o="/users/"+t+"/likes",u={page:r,per_page:n};return e.request({url:o,method:"GET",query:u})}}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r},function(e,t,r){"use strict";function n(){var e=!0;return e?window.fetch:r(!function(){var e=new Error('Cannot find module "node-fetch"');throw e.code="MODULE_NOT_FOUND",e}())}Object.defineProperty(t,"__esModule",{value:!0}),t.requireFetch=n},function(e,t,r){"use strict";function n(e){var t=new a;return Object.keys(e).forEach(function(r){t.append(r,e[r])}),t}function o(e){var t=e.method,r=e.query,o=e.oauth,a=e.body,s=o===!0?e.url:""+this._apiUrl+e.url,c=u({},e.headers,{"Accept-Version":this._apiVersion,Authorization:this._bearerToken?"Bearer "+this._bearerToken:"Client-ID "+this._applicationId});return r&&(s=decodeURIComponent(s+"?"+(0,i.stringify)(r))),{url:s,options:{method:t,headers:c,body:"POST"===t&&a?n(a):void 0}}}Object.defineProperty(t,"__esModule",{value:!0});var u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e};t.bodyToFormData=n,t.buildFetchOptions=o;var i=r(2),a=window.FormData},function(e,t){"use strict";function r(e,t){return Object.prototype.hasOwnProperty.call(e,t)}e.exports=function(e,t,n,o){t=t||"&",n=n||"=";var u={};if("string"!=typeof e||0===e.length)return u;var i=/\+/g;e=e.split(t);var a=1e3;o&&"number"==typeof o.maxKeys&&(a=o.maxKeys);var s=e.length;a>0&&s>a&&(s=a);for(var c=0;s>c;++c){var l,d,f,h,p=e[c].replace(i,"%20"),_=p.indexOf(n);_>=0?(l=p.substr(0,_),d=p.substr(_+1)):(l=p,d=""),f=decodeURIComponent(l),h=decodeURIComponent(d),r(u,f)?Array.isArray(u[f])?u[f].push(h):u[f]=[u[f],h]:u[f]=h}return u}},function(e,t){"use strict";var r=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}};e.exports=function(e,t,n,o){return t=t||"&",n=n||"=",null===e&&(e=void 0),"object"==typeof e?Object.keys(e).map(function(o){var u=encodeURIComponent(r(o))+n;return Array.isArray(e[o])?e[o].map(function(e){return u+encodeURIComponent(r(e))}).join(t):u+encodeURIComponent(r(e[o]))}).join(t):o?encodeURIComponent(r(o))+n+encodeURIComponent(r(e)):""}}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Unsplash=t():e.Unsplash=t()}(this,function(){return function(e){function t(o){if(r[o])return r[o].exports;var n=r[o]={exports:{},id:o,loaded:!1};return e[o].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";function o(e){return e&&e.__esModule?e:{"default":e}}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e){return e.json()}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,r,o){return r&&e(t.prototype,r),o&&e(t,o),t}}();t.toJson=u;var s=r(1),a=r(11),c=r(10),l=r(3),d=o(l),f=r(6),h=o(f),p=r(9),v=o(p),_=r(7),b=o(_),m=r(4),y=o(m),g=r(5),T=o(g),q=r(8),O=o(q),E=(0,c.requireFetch)(),U=function(){function e(t){n(this,e),this._apiUrl=t.apiUrl||s.API_URL,this._apiVersion=t.apiVersion||s.API_VERSION,this._applicationId=t.applicationId,this._secret=t.secret,this._callbackUrl=t.callbackUrl,this._bearerToken=t.bearerToken,this.auth=d["default"].bind(this)(),this.currentUser=h["default"].bind(this)(),this.users=v["default"].bind(this)(),this.photos=b["default"].bind(this)(),this.categories=y["default"].bind(this)(),this.collections=T["default"].bind(this)(),this.stats=O["default"].bind(this)()}return i(e,[{key:"request",value:function(e){var t=a.buildFetchOptions.bind(this)(e),r=t.url,o=t.options;return E(r,o)}}]),e}();t["default"]=U},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.API_URL="https://api.unsplash.com",t.API_VERSION="v1",t.OAUTH_AUTHORIZE_URL="https://unsplash.com/oauth/authorize",t.OAUTH_TOKEN_URL="https://unsplash.com/oauth/token"},function(e,t,r){"use strict";t.decode=t.parse=r(13),t.encode=t.stringify=r(14)},function(e,t,r){"use strict";function o(e){return e&&e.__esModule?e:{"default":e}}function n(){var e=this;return{getAuthenticationUrl:function(){var t=arguments.length<=0||void 0===arguments[0]?["public"]:arguments[0],r=i["default"].stringify({client_id:e._applicationId,redirect_uri:e._callbackUrl,response_type:"code",scope:t.length>1?t.join("+"):t.toString()});return decodeURIComponent(s.OAUTH_AUTHORIZE_URL+"?"+r)},userAuthentication:function(t){var r=s.OAUTH_TOKEN_URL;return e.request({url:r,method:"POST",body:{client_id:e._applicationId,client_secret:e._secret,redirect_uri:e._callbackUrl,grant_type:"authorization_code",code:t},oauth:!0})},setBearerToken:function(t){t&&(e._bearerToken=t)}}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=n;var u=r(2),i=o(u),s=r(1)},function(e,t){"use strict";function r(){var e=this;return{listCategories:function(){var t="/categories";return e.request({url:t,method:"GET"})},category:function(t){var r="/categories/"+t;return e.request({url:r,method:"GET"})},categoryPhotos:function(t,r,o){var n="/categories/"+t+"/photos",u={page:r,per_page:o};return e.request({url:n,method:"GET",query:u})}}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r},function(e,t){"use strict";function r(){var e=this;return{listCollections:function(){var t=arguments.length<=0||void 0===arguments[0]?1:arguments[0],r=arguments.length<=1||void 0===arguments[1]?10:arguments[1],o="/collections",n={page:t,per_page:r};return e.request({url:o,method:"GET",query:n})},listCuratedCollections:function(){var t=arguments.length<=0||void 0===arguments[0]?1:arguments[0],r=arguments.length<=1||void 0===arguments[1]?10:arguments[1],o="/collections/curated",n={page:t,per_page:r};return e.request({url:o,method:"GET",query:n})},getCollection:o.bind(this,!1),getCuratedCollection:o.bind(this,!0),getCuratedCollectionPhotos:n.bind(this,!0),getCollectionPhotos:n.bind(this,!1),createCollection:u.bind(this,null),updateCollection:u.bind(this),deleteCollection:function(t){var r="/collections/"+t;return e.request({url:r,method:"DELETE"})},addPhotoToCollection:function(t,r){var o="/collections/"+t+"/add";return e.request({url:o,method:"POST",body:{photo_id:r}})},removePhotoFromCollection:function(t,r){var o="/collections/"+t+"/remove";return e.request({url:o,method:"DELETE",body:{photo_id:r}})}}}function o(e,t){var r=e?"/collections/curated/"+t:"/collections/"+t;return this.request({url:r,method:"GET"})}function n(e,t){var r=e?"/collections/curated/"+t+"/photos":"/collections/"+t+"/photos";return this.request({url:r,method:"GET"})}function u(e,t,r,o){var n=e?"/collections/"+e:"/collections",u={title:t,description:r,"private":o};return this.request({url:n,method:e?"PUT":"POST",body:u})}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r},function(e,t){"use strict";function r(){var e=this;return{profile:function(){var t="/me";return e.request({url:t,method:"GET"})},updateProfile:function(t){var r="/me",o=t.username,n=t.firstName,u=t.lastName,i=t.email,s=t.url,a=t.location,c=t.bio,l=t.instagramUsername,d={username:o,first_name:n,last_name:u,email:i,url:s,location:a,bio:c,instagram_username:l};return Object.keys(d).forEach(function(e){d[e]||delete d[e]}),e.request({url:r,method:"POST",body:d})}}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r},function(e,t){"use strict";function r(){var e=this;return{listPhotos:function(t,r){var o="/photos",n={page:t,per_page:r};return e.request({url:o,method:"GET",query:n})},searchPhotos:function(t){var r=arguments.length<=1||void 0===arguments[1]?[""]:arguments[1],o=arguments[2],n=arguments[3],u="/photos/search",i={query:t,category:r.length>1?r.join(","):r.toString(),page:o,per_page:n};return e.request({url:u,method:"GET",query:i})},getPhoto:function(t,r,o,n){var u="/photos/"+t,i={w:r,h:o,rect:n};return e.request({url:u,method:"GET",query:i})},getRandomPhoto:function(t,r,o,n,u,i){var s=arguments.length<=6||void 0===arguments[6]?(new Date).getTime():arguments[6],a="/photos/random",c={category:i,featured:u,username:n,query:o,w:t,h:r,cacheBuster:s};return e.request({url:a,method:"GET",query:c})},uploadPhoto:function(t){if(!e._bearerToken)throw new Error("Requires a bearerToken to be set.");var r="/photos";return e.request({url:r,method:"POST",body:{photo:t}})},likePhoto:function(t){if(!e._bearerToken)throw new Error("Requires a bearerToken to be set.");var r="/photos/"+t+"/like";return e.request({url:r,method:"POST"})},unlikePhoto:function(t){if(!e._bearerToken)throw new Error("Requires a bearerToken to be set.");var r="/photos/"+t+"/like";return e.request({url:r,method:"DELETE"})}}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r},function(e,t){"use strict";function r(){var e=this;return{total:function(){var t="/stats";return e.request({url:t,method:"GET"})}}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r},function(e,t){"use strict";function r(){var e=this;return{profile:function(t){var r="/users/"+t;return e.request({url:r,method:"GET"})},photos:function(t){var r="/users/"+t+"/photos";return e.request({url:r,method:"GET"})},likes:function(t,r,o){var n="/users/"+t+"/likes",u={page:r,per_page:o};return e.request({url:n,method:"GET",query:u})}}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r},function(e,t,r){"use strict";function o(){var e=!0;return e?window.fetch:r(!function(){var e=new Error('Cannot find module "node-fetch"');throw e.code="MODULE_NOT_FOUND",e}())}Object.defineProperty(t,"__esModule",{value:!0}),t.requireFetch=o},function(e,t,r){"use strict";function o(e){return e&&e.__esModule?e:{"default":e}}function n(e){return(0,c["default"])(e)}function u(e){var t=e.method,r=e.query,o=e.oauth,u=e.body,a=o===!0?e.url:""+this._apiUrl+e.url,c=i({},e.headers,{"Accept-Version":this._apiVersion,Authorization:this._bearerToken?"Bearer "+this._bearerToken:"Client-ID "+this._applicationId});return u&&(c["Content-Type"]="application/x-www-form-urlencoded"),r&&(a=decodeURIComponent(a+"?"+(0,s.stringify)(r))),{url:a,options:{method:t,headers:c,body:"GET"!==t&&u?n(u):void 0}}}Object.defineProperty(t,"__esModule",{value:!0});var i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e};t.formUrlEncode=n,t.buildFetchOptions=u;var s=r(2),a=r(12),c=o(a)},function(e,t){e.exports=function(e,t){function r(e){return String(e).replace(/[^ !'()~\*]*/g,encodeURIComponent).replace(/ /g,"+").replace(/[!'()~\*]/g,function(e){return"%"+e.charCodeAt().toString(16).slice(-2).toUpperCase()})}function o(e){var r=Object.keys(e);return t.sorted?r.sort():r}function n(e){return e.filter(function(e){return e}).join("&")}function u(e,t){return n(o(t).map(function(r){return s(e+"["+r+"]",t[r])}))}function i(e,t){return n(t.map(function(t){return s(e+"[]",t)}))}function s(e,o){var n=typeof o,s=null;return o===s?s=t.ignorenull?s:r(e)+"="+s:/string|number|boolean/.test(n)?s=r(e)+"="+r(o):Array.isArray(o)?s=i(e,o):"object"===n&&(s=u(e,o)),s}return t="object"==typeof t?t:{},n(o(e).map(function(t){return s(t,e[t])}))}},function(e,t){"use strict";function r(e,t){return Object.prototype.hasOwnProperty.call(e,t)}e.exports=function(e,t,o,n){t=t||"&",o=o||"=";var u={};if("string"!=typeof e||0===e.length)return u;var i=/\+/g;e=e.split(t);var s=1e3;n&&"number"==typeof n.maxKeys&&(s=n.maxKeys);var a=e.length;s>0&&a>s&&(a=s);for(var c=0;a>c;++c){var l,d,f,h,p=e[c].replace(i,"%20"),v=p.indexOf(o);v>=0?(l=p.substr(0,v),d=p.substr(v+1)):(l=p,d=""),f=decodeURIComponent(l),h=decodeURIComponent(d),r(u,f)?Array.isArray(u[f])?u[f].push(h):u[f]=[u[f],h]:u[f]=h}return u}},function(e,t){"use strict";var r=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}};e.exports=function(e,t,o,n){return t=t||"&",o=o||"=",null===e&&(e=void 0),"object"==typeof e?Object.keys(e).map(function(n){var u=encodeURIComponent(r(n))+o;return Array.isArray(e[n])?e[n].map(function(e){return u+encodeURIComponent(r(e))}).join(t):u+encodeURIComponent(r(e[n]))}).join(t):n?encodeURIComponent(r(n))+o+encodeURIComponent(r(e)):""}}])});

@@ -43,4 +43,4 @@ "use strict";

redirect_uri: _this._callbackUrl,
code: code,
grant_type: "authorization_code"
grant_type: "authorization_code",
code: code
},

@@ -47,0 +47,0 @@ oauth: true

@@ -11,5 +11,18 @@ "use strict";

return {
listCuratedBatches: function listCuratedBatches(page, perPage) {
var url = "/curated_batches";
listCollections: function listCollections(page, perPage) {
var url = "/collections";
var query = {
page: page,
per_page: perPage
};
return _this.request({
url: url,
method: "GET",
query: query
});
},
listCuratedCollections: function listCuratedCollections(page, perPage) {
var url = "/collections/curated";
var query = {

@@ -27,4 +40,4 @@ page: page,

curatedBatch: function curatedBatch(id) {
var url = "/curated_batches/" + id;
getCollection: function getCollection(id) {
var url = "/collections/" + id;

@@ -37,11 +50,75 @@ return _this.request({

curatedBatchPhotos: function curatedBatchPhotos(id) {
var url = "/curated_batches/" + id + "/photos";
getCollectionPhotos: function getCollectionPhotos(id) {
return collectionPhotos.bind(_this)(id);
},
getCuratedCollectionPhotos: function getCuratedCollectionPhotos(id) {
return collectionPhotos.bind(_this)(id, true);
},
createCollection: function createCollection(id, title, description, isPrivate) {
return createUpdateCollection.bind(_this)(title, description, isPrivate);
},
updateCollection: function updateCollection(id, title, description, isPrivate) {
return createUpdateCollection.bind(_this)(title, description, isPrivate, id);
},
deleteCollection: function deleteCollection(id) {
var url = "/collections/" + id;
return _this.request({
url: url,
method: "GET"
method: "DELETE"
});
},
addPhotoToCollection: function addPhotoToCollection(collectionId, photoId) {
var url = "/collections/" + collectionId + "/add";
return _this.request({
url: url,
method: "POST",
body: {
photo_id: photoId
}
});
},
removePhotoFromCollection: function removePhotoFromCollection(collectionId, photoId) {
var url = "/collections/" + collectionId + "/remove";
return _this.request({
url: url,
method: "DELETE",
body: {
photo_id: photoId
}
});
}
};
}
function collectionPhotos(id, isCurated) {
var url = isCurated ? "/collections/curated/" + id + "/photos" : "/collections/" + id + "/photos";
return this.request({
url: url,
method: "GET"
});
}
function createUpdateCollection(title, description, isPrivate, id) {
var url = id ? "/collections/" + id : "/collections";
var body = {
title: title,
description: description,
"private": isPrivate
};
return this.request({
url: url,
method: id ? "PUT" : "POST",
body: body
});
}

@@ -64,2 +64,4 @@ "use strict";

getRandomPhoto: function getRandomPhoto(width, height, q, username, featured, category) {
var cacheBuster = arguments.length <= 6 || arguments[6] === undefined ? new Date().getTime() : arguments[6];
var url = "/photos/random";

@@ -73,3 +75,4 @@

w: width,
h: height
h: height,
cacheBuster: cacheBuster // Avoid ajax response caching
};

@@ -76,0 +79,0 @@

@@ -37,5 +37,5 @@ "use strict";

var _curatedBatches = require("./methods/curatedBatches");
var _collections = require("./methods/collections");
var _curatedBatches2 = _interopRequireDefault(_curatedBatches);
var _collections2 = _interopRequireDefault(_collections);

@@ -68,3 +68,3 @@ var _stats = require("./methods/stats");

this.categories = _categories2.default.bind(this)();
this.curatedBatches = _curatedBatches2.default.bind(this)();
this.collections = _collections2.default.bind(this)();
this.stats = _stats2.default.bind(this)();

@@ -71,0 +71,0 @@ }

@@ -9,3 +9,3 @@ "use strict";

exports.bodyToFormData = bodyToFormData;
exports.formUrlEncode = formUrlEncode;
exports.buildFetchOptions = buildFetchOptions;

@@ -15,11 +15,10 @@

var FormData = process.browser ? window.FormData : require("form-data");
var _formUrlencoded = require("form-urlencoded");
function bodyToFormData(body) {
var postBody = new FormData();
Object.keys(body).forEach(function (key) {
postBody.append(key, body[key]);
});
var _formUrlencoded2 = _interopRequireDefault(_formUrlencoded);
return postBody;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function formUrlEncode(body) {
return (0, _formUrlencoded2.default)(body);
}

@@ -39,2 +38,6 @@

if (body) {
headers["Content-Type"] = "application/x-www-form-urlencoded";
}
if (query) {

@@ -49,5 +52,5 @@ url = decodeURIComponent(url + "?" + (0, _querystring.stringify)(query));

headers: headers,
body: method === "POST" && body ? bodyToFormData(body) : undefined
body: method !== "GET" && body ? formUrlEncode(body) : undefined
}
};
}
{
"name": "unsplash-js",
"version": "1.1.0",
"version": "2.0.1",
"description": "A Universal JavaScript wrapper for the Unsplash API",

@@ -15,5 +15,7 @@ "main": "lib/unsplash.js",

"flow": "flow status",
"test": "npm run lint && npm run flow && mocha --compilers js:babel-core/register --recursive",
"test:ci": "npm run lint && npm run flow && npm run test:coverage",
"test": "npm run lint && npm run flow && npm run test:node && npm run test:browser",
"test:browser": "karma start",
"test:ci": "npm run lint && npm run flow && npm run test:browser && npm run test:coverage",
"test:coverage": "babel-node ./node_modules/.bin/isparta cover _mocha",
"test:node": "mocha --compilers js:babel-core/register --recursive",
"test:watch": "npm test -- --watch"

@@ -40,23 +42,31 @@ },

"devDependencies": {
"babel": "^6.3.26",
"babel-cli": "^6.4.0",
"babel-core": "^6.4.0",
"babel": "6.3.26",
"babel-cli": "6.4.0",
"babel-core": "6.4.0",
"babel-eslint": "5.0.0-beta10",
"babel-loader": "^6.2.1",
"babel-plugin-transform-class-properties": "^6.4.0",
"babel-plugin-transform-flow-strip-types": "^6.4.0",
"babel-plugin-transform-object-assign": "^6.3.13",
"babel-preset-es2015": "^6.3.13",
"babel-loader": "6.2.1",
"babel-plugin-transform-class-properties": "6.4.0",
"babel-plugin-transform-flow-strip-types": "6.4.0",
"babel-plugin-transform-object-assign": "6.3.13",
"babel-preset-es2015": "6.3.13",
"coveralls": "2.11.4",
"eslint": "^1.10.2",
"eslint": "1.10.2",
"expect": "1.12.2",
"flow-bin": "^0.20.1",
"isparta": "^4.0.0",
"istanbul": "^0.4.2",
"flow-bin": "0.20.1",
"isparta": "4.0.0",
"istanbul": "0.4.2",
"karma": "0.13.21",
"karma-browserstack-launcher": "0.1.10",
"karma-chrome-launcher": "0.2.2",
"karma-firefox-launcher": "0.1.7",
"karma-mocha": "0.2.2",
"karma-safari-launcher": "0.1.1",
"karma-sourcemap-loader": "0.3.7",
"karma-webpack": "1.7.0",
"mocha": "2.3.3",
"mockery": "1.4.0",
"webpack": "^1.12.13"
"webpack": "1.12.14"
},
"dependencies": {
"form-data": "0.2.0",
"form-urlencoded": "1.2.0",
"node-fetch": "1.3.3",

@@ -63,0 +73,0 @@ "querystring": "0.2.0"

@@ -21,2 +21,3 @@ # Unsplash

- [Helpers](https://github.com/naoufal/unsplash-js#helpers)
- [Shoutouts](https://github.com/naoufal/unsplash-js#shoutouts)
- [License](https://github.com/naoufal/unsplash-js#license)

@@ -110,3 +111,3 @@

- [Categories](https://github.com/naoufal/unsplash-js#categories)
- [Curated Batches](https://github.com/naoufal/unsplash-js#curated-batches)
- [Collections](https://github.com/naoufal/unsplash-js#collections)
- [Stats](https://github.com/naoufal/unsplash-js#stats)

@@ -345,3 +346,3 @@

### photos.getRandomPhoto(category, featured, username, query, width, height)
### photos.getRandomPhoto(width, height, query, username, featured, category)
Retrieve a single random photo, given optional filters.

@@ -353,8 +354,8 @@

|---|---|---|
|__`category`__|_Array<number>_|Optional|
|__`featured`__|_boolean_|Optional|
|__`username`__|_string_|Optional|
|__`query`__|_string_|Optional|
|__`width`__|_number_|Optional|
|__`height`__|_number_|Optional|
|__`query`__|_string_|Optional|
|__`username`__|_string_|Optional|
|__`featured`__|_boolean_|Optional|
|__`category`__|_Array<number>_|Optional|

@@ -489,14 +490,17 @@ __Example__

<div id="curated-batches" />
<div id="collections" />
### curatedBatches.listCuratedBatches()
Get a single page from the list of all curated batches.
### collections.listCollections(page, perPage)
Get a single page from the list of all collections.
__Arguments__
_N/A_
| Argument | Type | Opt/Required |
|---|---|---|
|__`page`__|_number_|Optional|
|__`perPage`__|_number_|Optional|
__Example__
```js
unsplash.curatedBatches.listCuratedBatches()
unsplash.collections.listCollections(1, 10)
.then(toJson)

@@ -509,4 +513,4 @@ .then(json => {

### curatedBatches.curatedBatch(id)
Retrieve a single batch.
### collections.listCuratedCollections(page, perPage)
Get a single page from the list of curated collections.

@@ -517,7 +521,8 @@ __Arguments__

|---|---|---|
|__`id`__|_string_|Required|
|__`page`__|_number_|Optional|
|__`perPage`__|_number_|Optional|
__Example__
```js
unsplash.curatedBatches.curatedBatch(88)
unsplash.collections.listCuratedCollections(1, 10)
.then(toJson)

@@ -530,4 +535,4 @@ .then(json => {

### curatedBatches.curatedBatchPhotos(id)
Retrieve a single batch’s ten photos.
### collections.getCollection(id)
Retrieve a single collection. To view a user’s private collections, the `read_collections` scope is required.

@@ -538,7 +543,8 @@ __Arguments__

|---|---|---|
|__`id`__|_string_|Required|
|__`id`__|_number_|Required|
__Example__
```js
unsplash.curatedBatches.curatedBatchPhotos(88)
unsplash.collections.getCollection(123456)
.then(toJson)

@@ -551,2 +557,124 @@ .then(json => {

### collections.getCuratedCollection(id)
Or, for a curated collection:
__Arguments__
| Argument | Type | Opt/Required |
|---|---|---|
|__`id`__|_number_|Required|
__Example__
```js
unsplash.collections.getCuratedCollection(88)
.then(toJson)
.then(json => {
// Your code
});
```
---
### collections.getCollectionPhotos(id)
Retrieve a collection’s photos.
__Arguments__
| Argument | Type | Opt/Required |
|---|---|---|
|__`id`__|_number_|Required|
__Example__
```js
unsplash.collections.getCollectionPhotos(123456)
.then(toJson)
.then(json => {
// Your code
});
```
---
### collections.getCuratedCollectionPhotos(id)
Or, for a curated collection:
__Arguments__
| Argument | Type | Opt/Required |
|---|---|---|
|__`id`__|_number_|Required|
__Example__
```js
unsplash.collections.getCuratedCollectionPhotos(88)
.then(toJson)
.then(json => {
// Your code
});
```
---
### collections.createCollection(title, description, private)
Create a new collection. This requires the `write_collections` scope.
__Arguments__
| Argument | Type | Opt/Required |
|---|---|---|
|__`title`__|_string_|Required|
|__`description`__|_string_|Optional|
|__`private`__|_boolean_|Optional|
__Example__
```js
unsplash.collections.createCollection("Birds", "Wild birds from 'round the world", true)
.then(toJson)
.then(json => {
// Your code
});
```
---
### collections.updateCollection(title, description, private)
Update an existing collection belonging to the logged-in user. This requires the `write_collections` scope.
__Arguments__
| Argument | Type | Opt/Required |
|---|---|---|
|__`title`__|_string_|Optional|
|__`description`__|_string_|Optional|
|__`private`__|_boolean_|Optional|
__Example__
```js
unsplash.collections.updateCollection("Wild Birds", "Wild birds from around the world", false)
.then(toJson)
.then(json => {
// Your code
});
```
---
### collections.deleteCollection(id)
Delete a collection belonging to the logged-in user. This requires the `write_collections` scope.
__Arguments__
| Argument | Type | Opt/Required |
|---|---|---|
|__`id`__|_number_|Required|
__Example__
```js
unsplash.collections.deleteCollection(88)
.then(toJson)
.then(json => {
// Your code
});
```
---
<div id="stats" />

@@ -598,2 +726,6 @@

## Shoutouts
- Shoutout to all the [contributors](https://github.com/naoufal/unsplash-js/graphs/contributors) for lending a helping hand.
- Shoutout to [BrowserStack](https://www.browserstack.com/) for letting us use their service to run automated browser tests.
## License

@@ -600,0 +732,0 @@ Copyright (c) 2015, [Naoufal Kadhom](http://naoufal.com)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc