Skip to content

Commit c739c2c

Browse files
feat: ID Summaries endpoints
1 parent 8b7defb commit c739c2c

File tree

6 files changed

+265
-11
lines changed

6 files changed

+265
-11
lines changed

build/inaturalistjs.js

Lines changed: 111 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ module.exports = {
3535
sites: __webpack_require__(58),
3636
sounds: __webpack_require__(60),
3737
taxa: __webpack_require__(61),
38-
taxon_name_priorities: __webpack_require__(62),
39-
translations: __webpack_require__(64),
40-
users: __webpack_require__(65),
38+
taxon_id_summaries: __webpack_require__(62),
39+
taxon_name_priorities: __webpack_require__(64),
40+
translations: __webpack_require__(66),
41+
users: __webpack_require__(67),
4142
Annotation: __webpack_require__(12),
4243
Comment: __webpack_require__(19),
4344
ControlledTerm: __webpack_require__(29),
@@ -56,7 +57,7 @@ module.exports = {
5657
Sound: __webpack_require__(26),
5758
Taxon: __webpack_require__(22),
5859
User: __webpack_require__(24),
59-
FileUpload: __webpack_require__(66)
60+
FileUpload: __webpack_require__(68)
6061
};
6162

6263
/***/ }),
@@ -493,7 +494,7 @@ var iNaturalistAPI = /*#__PURE__*/function () {
493494
var interpolatedRoute = route;
494495
var remainingParams = _objectSpread({}, params);
495496
var interpolatedParams = {};
496-
var matches = route.match(/(:[a-z]+)(?=\/|$)/g);
497+
var matches = route.match(/(:[a-z0-9_]+)(?=\/|$)/gi);
497498
if (matches) {
498499
matches.forEach(function (sym) {
499500
if (err) {
@@ -4781,7 +4782,107 @@ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r),
47814782
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
47824783
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); }
47834784
var iNaturalistAPI = __webpack_require__(1);
4784-
var TaxonNamePriority = __webpack_require__(63);
4785+
var TaxonIdSummary = __webpack_require__(63);
4786+
var taxonIdSummaries = /*#__PURE__*/function () {
4787+
function taxonIdSummaries() {
4788+
_classCallCheck(this, taxonIdSummaries);
4789+
}
4790+
return _createClass(taxonIdSummaries, null, [{
4791+
key: "fetch",
4792+
value: function fetch(ids, params) {
4793+
return iNaturalistAPI.fetch("taxon_id_summaries", ids, params).then(TaxonIdSummary.typifyResultsResponse);
4794+
}
4795+
}, {
4796+
key: "search",
4797+
value: function search(params, options) {
4798+
return iNaturalistAPI.get("taxon_id_summaries", params, options).then(TaxonIdSummary.typifyResultsResponse);
4799+
}
4800+
}, {
4801+
key: "summaryQualityMetrics",
4802+
value: function summaryQualityMetrics(params, options) {
4803+
return iNaturalistAPI.get("taxon_id_summaries/:uuid/id_summaries/:id/quality_metrics", params, options);
4804+
}
4805+
}, {
4806+
key: "setSummaryQualityMetric",
4807+
value: function setSummaryQualityMetric(params, options) {
4808+
return iNaturalistAPI.post("taxon_id_summaries/:uuid/id_summaries/:id/quality/:metric", params, options);
4809+
}
4810+
}, {
4811+
key: "deleteSummaryQualityMetric",
4812+
value: function deleteSummaryQualityMetric(params, options) {
4813+
return iNaturalistAPI["delete"]("taxon_id_summaries/:uuid/id_summaries/:id/quality/:metric", params, options);
4814+
}
4815+
}, {
4816+
key: "referenceQualityMetrics",
4817+
value: function referenceQualityMetrics(params, options) {
4818+
return iNaturalistAPI.get("taxon_id_summaries/:uuid/id_summaries/:id/references/:reference_id/quality_metrics", params, options);
4819+
}
4820+
}, {
4821+
key: "setReferenceQualityMetric",
4822+
value: function setReferenceQualityMetric(params, options) {
4823+
return iNaturalistAPI.post("taxon_id_summaries/:uuid/id_summaries/:id/references/:reference_id/quality/:metric", params, options);
4824+
}
4825+
}, {
4826+
key: "deleteReferenceQualityMetric",
4827+
value: function deleteReferenceQualityMetric(params, options) {
4828+
return iNaturalistAPI["delete"]("taxon_id_summaries/:uuid/id_summaries/:id/references/:reference_id/quality/:metric", params, options);
4829+
}
4830+
}]);
4831+
}();
4832+
module.exports = taxonIdSummaries;
4833+
4834+
/***/ }),
4835+
/* 63 */
4836+
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
4837+
4838+
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); }
4839+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
4840+
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); } }
4841+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
4842+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
4843+
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); }
4844+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
4845+
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); }
4846+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
4847+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
4848+
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); }
4849+
function _superPropBase(t, o) { for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));); return t; }
4850+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
4851+
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); }
4852+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
4853+
var Model = __webpack_require__(10);
4854+
var TaxonIdSummary = /*#__PURE__*/function (_Model) {
4855+
function TaxonIdSummary() {
4856+
_classCallCheck(this, TaxonIdSummary);
4857+
return _callSuper(this, TaxonIdSummary, arguments);
4858+
}
4859+
_inherits(TaxonIdSummary, _Model);
4860+
return _createClass(TaxonIdSummary, null, [{
4861+
key: "typifyResultsResponse",
4862+
value: function typifyResultsResponse(response) {
4863+
return _get(_getPrototypeOf(TaxonIdSummary), "typifyResultsResponse", this).call(this, response, TaxonIdSummary);
4864+
}
4865+
}, {
4866+
key: "typifyInstanceResponse",
4867+
value: function typifyInstanceResponse(response) {
4868+
return _get(_getPrototypeOf(TaxonIdSummary), "typifyInstanceResponse", this).call(this, response, TaxonIdSummary);
4869+
}
4870+
}]);
4871+
}(Model);
4872+
module.exports = TaxonIdSummary;
4873+
4874+
/***/ }),
4875+
/* 64 */
4876+
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
4877+
4878+
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); }
4879+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
4880+
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); } }
4881+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
4882+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
4883+
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); }
4884+
var iNaturalistAPI = __webpack_require__(1);
4885+
var TaxonNamePriority = __webpack_require__(65);
47854886
var taxonNamePriorities = /*#__PURE__*/function () {
47864887
function taxonNamePriorities() {
47874888
_classCallCheck(this, taxonNamePriorities);
@@ -4806,7 +4907,7 @@ var taxonNamePriorities = /*#__PURE__*/function () {
48064907
module.exports = taxonNamePriorities;
48074908

48084909
/***/ }),
4809-
/* 63 */
4910+
/* 65 */
48104911
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
48114912

48124913
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); }
@@ -4841,7 +4942,7 @@ var TaxonNamePriority = /*#__PURE__*/function (_Model) {
48414942
module.exports = TaxonNamePriority;
48424943

48434944
/***/ }),
4844-
/* 64 */
4945+
/* 66 */
48454946
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
48464947

48474948
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); }
@@ -4867,7 +4968,7 @@ var translations = /*#__PURE__*/function () {
48674968
module.exports = translations;
48684969

48694970
/***/ }),
4870-
/* 65 */
4971+
/* 67 */
48714972
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
48724973

48734974
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); }
@@ -4997,7 +5098,7 @@ var users = /*#__PURE__*/function () {
49975098
module.exports = users;
49985099

49995100
/***/ }),
5000-
/* 66 */
5101+
/* 68 */
50015102
/***/ (function(module) {
50025103

50035104
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); }
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const iNaturalistAPI = require( "../inaturalist_api" );
2+
const TaxonIdSummary = require( "../models/taxon_id_summary" );
3+
4+
const taxonIdSummaries = class taxonIdSummaries {
5+
static fetch( ids, params ) {
6+
return iNaturalistAPI.fetch( "taxon_id_summaries", ids, params )
7+
.then( TaxonIdSummary.typifyResultsResponse );
8+
}
9+
10+
static search( params, options ) {
11+
return iNaturalistAPI.get( "taxon_id_summaries", params, options )
12+
.then( TaxonIdSummary.typifyResultsResponse );
13+
}
14+
15+
static summaryQualityMetrics( params, options ) {
16+
return iNaturalistAPI.get(
17+
"taxon_id_summaries/:uuid/id_summaries/:id/quality_metrics",
18+
params,
19+
options
20+
);
21+
}
22+
23+
static setSummaryQualityMetric( params, options ) {
24+
return iNaturalistAPI.post(
25+
"taxon_id_summaries/:uuid/id_summaries/:id/quality/:metric",
26+
params,
27+
options
28+
);
29+
}
30+
31+
static deleteSummaryQualityMetric( params, options ) {
32+
return iNaturalistAPI.delete(
33+
"taxon_id_summaries/:uuid/id_summaries/:id/quality/:metric",
34+
params,
35+
options
36+
);
37+
}
38+
39+
static referenceQualityMetrics( params, options ) {
40+
return iNaturalistAPI.get(
41+
"taxon_id_summaries/:uuid/id_summaries/:id/references/:reference_id/quality_metrics",
42+
params,
43+
options
44+
);
45+
}
46+
47+
static setReferenceQualityMetric( params, options ) {
48+
return iNaturalistAPI.post(
49+
"taxon_id_summaries/:uuid/id_summaries/:id/references/:reference_id/quality/:metric",
50+
params,
51+
options
52+
);
53+
}
54+
55+
static deleteReferenceQualityMetric( params, options ) {
56+
return iNaturalistAPI.delete(
57+
"taxon_id_summaries/:uuid/id_summaries/:id/references/:reference_id/quality/:metric",
58+
params,
59+
options
60+
);
61+
}
62+
};
63+
64+
module.exports = taxonIdSummaries;

lib/inaturalist_api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ const iNaturalistAPI = class iNaturalistAPI {
392392
let interpolatedRoute = route;
393393
const remainingParams = { ...params };
394394
const interpolatedParams = {};
395-
const matches = route.match( /(:[a-z]+)(?=\/|$)/g );
395+
const matches = route.match( /(:[a-z0-9_]+)(?=\/|$)/gi );
396396
if ( matches ) {
397397
matches.forEach( sym => {
398398
if ( err ) { return; }

lib/inaturalistjs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = {
3131
sites: require( "./endpoints/sites" ),
3232
sounds: require( "./endpoints/sounds" ),
3333
taxa: require( "./endpoints/taxa" ),
34+
taxon_id_summaries: require( "./endpoints/taxon_id_summaries" ),
3435
taxon_name_priorities: require( "./endpoints/taxon_name_priorities" ),
3536
translations: require( "./endpoints/translations" ),
3637
users: require( "./endpoints/users" ),

lib/models/taxon_id_summary.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const Model = require( "./model" );
2+
3+
const TaxonIdSummary = class TaxonIdSummary extends Model {
4+
static typifyResultsResponse( response ) {
5+
return super.typifyResultsResponse( response, TaxonIdSummary );
6+
}
7+
8+
static typifyInstanceResponse( response ) {
9+
return super.typifyInstanceResponse( response, TaxonIdSummary );
10+
}
11+
};
12+
13+
module.exports = TaxonIdSummary;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
require( "cross-fetch/polyfill" );
2+
require( "../initialize" );
3+
const nock = require( "nock" );
4+
const taxonIdSummaries = require( "../../lib/endpoints/taxon_id_summaries" );
5+
const testHelper = require( "../../lib/test_helper" );
6+
7+
describe( "taxonIdSummaries quality metrics", ( ) => {
8+
const uuid = "123e4567-e89b-12d3-a456-426614174000";
9+
10+
beforeEach( testHelper.v1ToV2 );
11+
afterEach( testHelper.v2ToV1 );
12+
13+
it( "gets summary quality metrics", ( ) => {
14+
nock( "http://localhost:4000" )
15+
.get( `/v2/taxon_id_summaries/${uuid}/id_summaries/1/quality_metrics` )
16+
.reply( 200, testHelper.mockResponse( "quality metrics" ) );
17+
return taxonIdSummaries.summaryQualityMetrics( { uuid, id: 1 } );
18+
} );
19+
20+
it( "sets summary quality metrics", ( ) => {
21+
nock( "http://localhost:4000" )
22+
.post( `/v2/taxon_id_summaries/${uuid}/id_summaries/1/quality/wild`, { agree: true } )
23+
.reply( 200, { results: [] } );
24+
return taxonIdSummaries.setSummaryQualityMetric(
25+
{
26+
uuid, id: 1, metric: "wild", agree: true
27+
}
28+
);
29+
} );
30+
31+
it( "deletes summary quality metrics", ( ) => {
32+
nock( "http://localhost:4000" )
33+
.delete( `/v2/taxon_id_summaries/${uuid}/id_summaries/1/quality/wild` )
34+
.reply( 200, { } );
35+
return taxonIdSummaries.deleteSummaryQualityMetric(
36+
{ uuid, id: 1, metric: "wild" }
37+
);
38+
} );
39+
40+
it( "gets reference quality metrics", ( ) => {
41+
nock( "http://localhost:4000" )
42+
.get( `/v2/taxon_id_summaries/${uuid}/id_summaries/1/references/2/quality_metrics` )
43+
.reply( 200, testHelper.mockResponse( "reference quality metrics" ) );
44+
return taxonIdSummaries.referenceQualityMetrics(
45+
{ uuid, id: 1, reference_id: 2 }
46+
);
47+
} );
48+
49+
it( "sets reference quality metrics", ( ) => {
50+
nock( "http://localhost:4000" )
51+
.post(
52+
`/v2/taxon_id_summaries/${uuid}/id_summaries/1/references/2/quality/wild`,
53+
{ agree: false }
54+
)
55+
.reply( 200, { results: [] } );
56+
return taxonIdSummaries.setReferenceQualityMetric(
57+
{
58+
uuid, id: 1, reference_id: 2, metric: "wild", agree: false
59+
}
60+
);
61+
} );
62+
63+
it( "deletes reference quality metrics", ( ) => {
64+
nock( "http://localhost:4000" )
65+
.delete(
66+
`/v2/taxon_id_summaries/${uuid}/id_summaries/1/references/2/quality/wild`
67+
)
68+
.reply( 200, { } );
69+
return taxonIdSummaries.deleteReferenceQualityMetric(
70+
{
71+
uuid, id: 1, reference_id: 2, metric: "wild"
72+
}
73+
);
74+
} );
75+
} );

0 commit comments

Comments
 (0)