Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
291 changes: 201 additions & 90 deletions build/inaturalistjs.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions lib/endpoints/exemplar_identifications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const iNaturalistAPI = require( "../inaturalist_api" );
const ExemplarIdentification = require( "../models/exemplar_identification" );

const exemplarIdentifications = class exemplarIdentifications {
static search( params, opts = { } ) {
return iNaturalistAPI.get( "exemplar_identifications", params, { ...opts, useAuth: true } )
.then( ExemplarIdentification.typifyResultsResponse );
}

static vote( params, options ) {
let endpoint = "votes/vote/exemplar_identification/:id";
if ( iNaturalistAPI.apiURL && iNaturalistAPI.apiURL.match( /\/v2/ ) ) {
endpoint = "exemplar_identifications/:id/vote";
}
return iNaturalistAPI.post( endpoint, params, options );
}

static unvote( params, options ) {
let endpoint = "votes/unvote/exemplar_identification/:id";
if ( iNaturalistAPI.apiURL && iNaturalistAPI.apiURL.match( /\/v2/ ) ) {
endpoint = "exemplar_identifications/:id/vote";
}
return iNaturalistAPI.delete( endpoint, params, options );
}
};

module.exports = exemplarIdentifications;
8 changes: 8 additions & 0 deletions lib/endpoints/identifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ const identifications = class identifications {
static categories( params, opts = { } ) {
return iNaturalistAPI.get( "identifications/categories", params, opts );
}

static nominate( params, options ) {
return iNaturalistAPI.post( "identifications/:id/nominate", params, options );
}

static unnominate( params, options ) {
return iNaturalistAPI.delete( "identifications/:id/unnominate", params, options );
}
};

module.exports = identifications;
2 changes: 2 additions & 0 deletions lib/inaturalistjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
comments: require( "./endpoints/comments" ),
computervision: require( "./endpoints/computervision" ),
controlled_terms: require( "./endpoints/controlled_terms" ),
exemplar_identifications: require( "./endpoints/exemplar_identifications" ),
flags: require( "./endpoints/flags" ),
identifications: require( "./endpoints/identifications" ),
messages: require( "./endpoints/messages" ),
Expand Down Expand Up @@ -38,6 +39,7 @@ module.exports = {
Annotation: require( "./models/annotation" ),
Comment: require( "./models/comment" ),
ControlledTerm: require( "./models/controlled_term" ),
ExemplarIdentification: require( "./models/exemplar_identification" ),
Flag: require( "./models/flag" ),
Identification: require( "./models/identification" ),
Observation: require( "./models/observation" ),
Expand Down
25 changes: 25 additions & 0 deletions lib/models/exemplar_identification.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const Model = require( "./model" );
const Identification = require( "./identification" );
const Observation = require( "./observation" );

const ExemplarIdentification = class ExemplarIdentification extends Model {
constructor( attrs ) {
super( attrs );
if ( this.identification ) {
this.identification = new Identification( this.identification );
if ( this.identification.observation ) {
this.identification.observation = new Observation( this.identification.observation );
}
}
}

static typifyInstanceResponse( response ) {
return super.typifyInstanceResponse( response, ExemplarIdentification );
}

static typifyResultsResponse( response ) {
return super.typifyResultsResponse( response, ExemplarIdentification );
}
};

module.exports = ExemplarIdentification;
64 changes: 64 additions & 0 deletions test/endpoints/exemplar_identifications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const { expect } = require( "chai" );
const nock = require( "nock" );
const exemplarIdentifications = require( "../../lib/endpoints/exemplar_identifications" );
const testHelper = require( "../../lib/test_helper" );

describe( "ExemplarIdentifications", ( ) => {
describe( "search", ( ) => {
it( "fetches exemplar_identifications", done => {
nock( "http://localhost:4000" )
.get( "/v1/exemplar_identifications" )
.reply( 200, [{ id: 1 }] );
exemplarIdentifications.search( { } ).then( results => {
expect( results[0].id ).to.eq( 1 );
done( );
} );
} );
} );

describe( "vote", ( ) => {
it( "posts to /votes/vote/exemplar_identification/:id", done => {
nock( "http://localhost:3000" )
.post( "/votes/vote/exemplar_identification/1" )
.reply( 200, { id: 1 } );
exemplarIdentifications.vote( { id: 1 } ).then( ( ) => {
done( );
} );
} );
describe( "v2", ( ) => {
beforeEach( testHelper.v1ToV2 );
afterEach( testHelper.v2ToV1 );
it( "posts to /exemplar_identifications/:id/vote", done => {
nock( "http://localhost:4000" )
.post( "/v2/exemplar_identifications/1/vote" )
.reply( 200, { id: 1 } );
exemplarIdentifications.vote( { id: 1 } ).then( ( ) => {
done( );
} );
} );
} );
} );

describe( "unvote", ( ) => {
it( "deletes to /votes/unvote/exemplar_identification/:id", done => {
nock( "http://localhost:3000" )
.delete( "/votes/unvote/exemplar_identification/1" )
.reply( 200, { id: 1 } );
exemplarIdentifications.unvote( { id: 1 } ).then( ( ) => {
done( );
} );
} );
describe( "v2", ( ) => {
beforeEach( testHelper.v1ToV2 );
afterEach( testHelper.v2ToV1 );
it( "deletes to /exemplar_identifications/:id/vote", done => {
nock( "http://localhost:4000" )
.delete( "/v2/exemplar_identifications/1/vote" )
.reply( 200, { id: 1 } );
exemplarIdentifications.unvote( { id: 1 } ).then( ( ) => {
done( );
} );
} );
} );
} );
} );