diff --git a/build/inaturalistjs.js b/build/inaturalistjs.js index 8c7a0f3..75281ad 100644 --- a/build/inaturalistjs.js +++ b/build/inaturalistjs.js @@ -30,13 +30,14 @@ module.exports = { project_users: __webpack_require__(49), provider_authorizations: __webpack_require__(51), relationships: __webpack_require__(53), - search: __webpack_require__(55), - sites: __webpack_require__(56), - sounds: __webpack_require__(58), - taxa: __webpack_require__(59), - taxon_name_priorities: __webpack_require__(60), - translations: __webpack_require__(62), - users: __webpack_require__(63), + saved_locations: __webpack_require__(55), + search: __webpack_require__(57), + sites: __webpack_require__(58), + sounds: __webpack_require__(60), + taxa: __webpack_require__(61), + taxon_name_priorities: __webpack_require__(62), + translations: __webpack_require__(64), + users: __webpack_require__(65), Annotation: __webpack_require__(12), Comment: __webpack_require__(19), ControlledTerm: __webpack_require__(29), @@ -50,11 +51,12 @@ module.exports = { Project: __webpack_require__(40), ProjectUser: __webpack_require__(50), ProviderAuthorization: __webpack_require__(52), - Site: __webpack_require__(57), + SavedLocation: __webpack_require__(56), + Site: __webpack_require__(59), Sound: __webpack_require__(26), Taxon: __webpack_require__(22), User: __webpack_require__(24), - FileUpload: __webpack_require__(64) + FileUpload: __webpack_require__(66) }; /***/ }), @@ -4403,6 +4405,87 @@ module.exports = Relationship; /* 55 */ /***/ (function(module, __unused_webpack_exports, __webpack_require__) { +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } +function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } +function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } +function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } +function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } +function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } +function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } +function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } +function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } +var iNaturalistAPI = __webpack_require__(1); +var SavedLocation = __webpack_require__(56); +var savedLocations = /*#__PURE__*/function () { + function savedLocations() { + _classCallCheck(this, savedLocations); + } + return _createClass(savedLocations, null, [{ + key: "search", + value: function search(params) { + var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + return iNaturalistAPI.get("saved_locations", params, _objectSpread(_objectSpread({}, opts), {}, { + useAuth: true + })).then(SavedLocation.typifyResultsResponse); + } + }, { + key: "create", + value: function create(params, options) { + return iNaturalistAPI.post("saved_locations", params, options).then(SavedLocation.typifyInstanceResponse); + } + }, { + key: "delete", + value: function _delete(params, options) { + return iNaturalistAPI["delete"]("saved_locations/:id", params, options); + } + }]); +}(); +module.exports = savedLocations; + +/***/ }), +/* 56 */ +/***/ (function(module, __unused_webpack_exports, __webpack_require__) { + +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } +function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } +function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } +function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } +function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } +function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } +function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } +function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } +function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } +function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } +function _get() { return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { var p = _superPropBase(e, t); if (p) { var n = Object.getOwnPropertyDescriptor(p, t); return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; } }, _get.apply(null, arguments); } +function _superPropBase(t, o) { for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));); return t; } +function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } +function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } +function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } +var Model = __webpack_require__(10); +var SavedLocation = /*#__PURE__*/function (_Model) { + function SavedLocation() { + _classCallCheck(this, SavedLocation); + return _callSuper(this, SavedLocation, arguments); + } + _inherits(SavedLocation, _Model); + return _createClass(SavedLocation, null, [{ + key: "typifyResultsResponse", + value: function typifyResultsResponse(response) { + return _get(_getPrototypeOf(SavedLocation), "typifyResultsResponse", this).call(this, response, SavedLocation); + } + }, { + key: "typifyInstanceResponse", + value: function typifyInstanceResponse(response) { + return _get(_getPrototypeOf(SavedLocation), "typifyInstanceResponse", this).call(this, response, SavedLocation); + } + }]); +}(Model); +module.exports = SavedLocation; + +/***/ }), +/* 57 */ +/***/ (function(module, __unused_webpack_exports, __webpack_require__) { + function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } @@ -4455,7 +4538,7 @@ var search = /*#__PURE__*/function () { module.exports = search.index; /***/ }), -/* 56 */ +/* 58 */ /***/ (function(module, __unused_webpack_exports, __webpack_require__) { function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -4465,7 +4548,7 @@ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var iNaturalistAPI = __webpack_require__(1); -var Site = __webpack_require__(57); +var Site = __webpack_require__(59); var sites = /*#__PURE__*/function () { function sites() { _classCallCheck(this, sites); @@ -4490,7 +4573,7 @@ var sites = /*#__PURE__*/function () { module.exports = sites; /***/ }), -/* 57 */ +/* 59 */ /***/ (function(module, __unused_webpack_exports, __webpack_require__) { function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -4525,7 +4608,7 @@ var Site = /*#__PURE__*/function (_Model) { module.exports = Site; /***/ }), -/* 58 */ +/* 60 */ /***/ (function(module, __unused_webpack_exports, __webpack_require__) { function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -4549,7 +4632,7 @@ var sounds = /*#__PURE__*/function () { module.exports = sounds; /***/ }), -/* 59 */ +/* 61 */ /***/ (function(module, __unused_webpack_exports, __webpack_require__) { function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -4638,7 +4721,7 @@ var taxa = /*#__PURE__*/function () { module.exports = taxa; /***/ }), -/* 60 */ +/* 62 */ /***/ (function(module, __unused_webpack_exports, __webpack_require__) { function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -4648,7 +4731,7 @@ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var iNaturalistAPI = __webpack_require__(1); -var TaxonNamePriority = __webpack_require__(61); +var TaxonNamePriority = __webpack_require__(63); var taxonNamePriorities = /*#__PURE__*/function () { function taxonNamePriorities() { _classCallCheck(this, taxonNamePriorities); @@ -4673,7 +4756,7 @@ var taxonNamePriorities = /*#__PURE__*/function () { module.exports = taxonNamePriorities; /***/ }), -/* 61 */ +/* 63 */ /***/ (function(module, __unused_webpack_exports, __webpack_require__) { function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -4708,7 +4791,7 @@ var TaxonNamePriority = /*#__PURE__*/function (_Model) { module.exports = TaxonNamePriority; /***/ }), -/* 62 */ +/* 64 */ /***/ (function(module, __unused_webpack_exports, __webpack_require__) { function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -4734,7 +4817,7 @@ var translations = /*#__PURE__*/function () { module.exports = translations; /***/ }), -/* 63 */ +/* 65 */ /***/ (function(module, __unused_webpack_exports, __webpack_require__) { function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -4855,7 +4938,7 @@ var users = /*#__PURE__*/function () { module.exports = users; /***/ }), -/* 64 */ +/* 66 */ /***/ (function(module) { function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } diff --git a/lib/endpoints/saved_locations.js b/lib/endpoints/saved_locations.js new file mode 100644 index 0000000..6e7ee1b --- /dev/null +++ b/lib/endpoints/saved_locations.js @@ -0,0 +1,20 @@ +const iNaturalistAPI = require( "../inaturalist_api" ); +const SavedLocation = require( "../models/saved_location" ); + +const savedLocations = class savedLocations { + static search( params, opts = { } ) { + return iNaturalistAPI.get( "saved_locations", params, { ...opts, useAuth: true } ) + .then( SavedLocation.typifyResultsResponse ); + } + + static create( params, options ) { + return iNaturalistAPI.post( "saved_locations", params, options ) + .then( SavedLocation.typifyInstanceResponse ); + } + + static delete( params, options ) { + return iNaturalistAPI.delete( "saved_locations/:id", params, options ); + } +}; + +module.exports = savedLocations; diff --git a/lib/inaturalistjs.js b/lib/inaturalistjs.js index 844f5c5..6b1a55e 100644 --- a/lib/inaturalistjs.js +++ b/lib/inaturalistjs.js @@ -26,6 +26,7 @@ module.exports = { project_users: require( "./endpoints/project_users" ), provider_authorizations: require( "./endpoints/provider_authorizations" ), relationships: require( "./endpoints/relationships" ), + saved_locations: require( "./endpoints/saved_locations" ), search: require( "./endpoints/search" ), sites: require( "./endpoints/sites" ), sounds: require( "./endpoints/sounds" ), @@ -46,6 +47,7 @@ module.exports = { Project: require( "./models/project" ), ProjectUser: require( "./models/project_user" ), ProviderAuthorization: require( "./models/provider_authorization" ), + SavedLocation: require( "./models/saved_location" ), Site: require( "./models/site" ), Sound: require( "./models/sound" ), Taxon: require( "./models/taxon" ), diff --git a/lib/models/saved_location.js b/lib/models/saved_location.js new file mode 100644 index 0000000..8066051 --- /dev/null +++ b/lib/models/saved_location.js @@ -0,0 +1,13 @@ +const Model = require( "./model" ); + +const SavedLocation = class SavedLocation extends Model { + static typifyResultsResponse( response ) { + return super.typifyResultsResponse( response, SavedLocation ); + } + + static typifyInstanceResponse( response ) { + return super.typifyInstanceResponse( response, SavedLocation ); + } +}; + +module.exports = SavedLocation; diff --git a/package-lock.json b/package-lock.json index fa0b050..6062722 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2991,9 +2991,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001641", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001641.tgz", - "integrity": "sha512-Phv5thgl67bHYo1TtMY/MurjkHhV4EDaCosezRXgZ8jzA/Ub+wjxAvbGvjoFENStinwi5kCyOYV3mi5tOGykwA==", + "version": "1.0.30001643", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001643.tgz", + "integrity": "sha512-ERgWGNleEilSrHM6iUz/zJNSQTP8Mr21wDWpdgvRwcTXGAq6jMtOUPP4dqFPTdKqZ2wKTdtB+uucZ3MRpAUSmg==", "dev": true, "funding": [ { diff --git a/test/endpoints/comments.js b/test/endpoints/comments.js index 3e795f0..403f738 100644 --- a/test/endpoints/comments.js +++ b/test/endpoints/comments.js @@ -13,7 +13,7 @@ describe( "Comments", ( ) => { } ); } ); - it( "adds an authorization ready for the api_token", done => { + it( "adds an authorization header for the api_token", done => { nock( "http://localhost:3000", { reqheaders: { Authorization: "key" } } ) .post( "/comments", { body: "testbody" } ) .reply( 200, { id: 1 } ); diff --git a/test/endpoints/saved_locations.js b/test/endpoints/saved_locations.js new file mode 100644 index 0000000..c67c062 --- /dev/null +++ b/test/endpoints/saved_locations.js @@ -0,0 +1,71 @@ +const { expect } = require( "chai" ); +const nock = require( "nock" ); +const savedLocations = require( "../../lib/endpoints/saved_locations" ); + +describe( "SavedLocations", ( ) => { + const savedLocation = { + latitude: 1.1, + longitude: 2.2, + title: "SavedLocation", + positional_accuracy: 33, + geoprivacy: "open" + }; + describe( "search", ( ) => { + it( "fetches saved locations", done => { + nock( "http://localhost:4000" ) + .get( "/v1/saved_locations" ) + .reply( 200, [{ id: 1 }] ); + savedLocations.search( ).then( results => { + expect( results[0].id ).to.eq( 1 ); + done( ); + } ); + } ); + } ); + + describe( "create", ( ) => { + it( "posts to /saved_locations", done => { + nock( "http://localhost:3000" ) + .post( "/saved_locations", savedLocation ) + .reply( 200, { id: 1 } ); + savedLocations.create( savedLocation ).then( ( ) => { + done( ); + } ); + } ); + + it( "adds an authorization header for the api_token", done => { + nock( "http://localhost:3000", { reqheaders: { Authorization: "key" } } ) + .post( "/saved_locations", savedLocation ) + .reply( 200, { id: 1 } ); + savedLocations.create( savedLocation, { api_token: "key" } ).then( ( ) => { + done( ); + } ); + } ); + + it( "does nothing with empty params", done => { + nock( "http://localhost:3000" ) + .post( "/saved_locations", { } ) + .reply( 200, { id: 1 } ); + savedLocations.create( ).then( ( ) => { + done( ); + } ); + } ); + } ); + + describe( "delete", ( ) => { + it( "deletes to /saved_locations", done => { + nock( "http://localhost:3000" ) + .delete( "/saved_locations/1" ) + .reply( 200, { id: 1 } ); + savedLocations.delete( { id: 1 } ).then( ( ) => { + done( ); + } ); + } ); + + it( "throws errors", done => { + savedLocations.delete( { any: "thing" } ).catch( e => { + expect( e.message ).to.eq( "id required" ); + done( ); + } ); + } ); + } ); +} );