Skip to content

Commit

Permalink
add saved_locations endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
pleary committed Jul 29, 2024
1 parent 32b4d20 commit 4bef592
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 24 deletions.
123 changes: 103 additions & 20 deletions build/inaturalistjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
};

/***/ }),
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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); }
Expand All @@ -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);
Expand All @@ -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); }
Expand Down Expand Up @@ -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); }
Expand All @@ -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); }
Expand Down Expand Up @@ -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); }
Expand All @@ -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);
Expand All @@ -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); }
Expand Down Expand Up @@ -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); }
Expand All @@ -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); }
Expand Down Expand Up @@ -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); }
Expand Down
20 changes: 20 additions & 0 deletions lib/endpoints/saved_locations.js
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 2 additions & 0 deletions lib/inaturalistjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" ),
Expand All @@ -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" ),
Expand Down
13 changes: 13 additions & 0 deletions lib/models/saved_location.js
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/endpoints/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } );
Expand Down
Loading

0 comments on commit 4bef592

Please sign in to comment.