Skip to content

Commit c9dea7c

Browse files
committed
rename taxon_identifications to exemplar_identifications
1 parent 2fb5732 commit c9dea7c

File tree

8 files changed

+299
-227
lines changed

8 files changed

+299
-227
lines changed

build/inaturalistjs.js

Lines changed: 181 additions & 176 deletions
Large diffs are not rendered by default.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const iNaturalistAPI = require( "../inaturalist_api" );
2+
const ExemplarIdentification = require( "../models/exemplar_identification" );
3+
4+
const exemplarIdentifications = class exemplarIdentifications {
5+
static search( params, opts = { } ) {
6+
return iNaturalistAPI.get( "exemplar_identifications", params, { ...opts, useAuth: true } )
7+
.then( ExemplarIdentification.typifyResultsResponse );
8+
}
9+
10+
static vote( params, options ) {
11+
let endpoint = "votes/vote/exemplar_identification/:id";
12+
if ( iNaturalistAPI.apiURL && iNaturalistAPI.apiURL.match( /\/v2/ ) ) {
13+
endpoint = "exemplar_identifications/:id/vote";
14+
}
15+
return iNaturalistAPI.post( endpoint, params, options );
16+
}
17+
18+
static unvote( params, options ) {
19+
let endpoint = "votes/unvote/exemplar_identification/:id";
20+
if ( iNaturalistAPI.apiURL && iNaturalistAPI.apiURL.match( /\/v2/ ) ) {
21+
endpoint = "exemplar_identifications/:id/vote";
22+
}
23+
return iNaturalistAPI.delete( endpoint, params, options );
24+
}
25+
};
26+
27+
module.exports = exemplarIdentifications;

lib/endpoints/identifications.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,6 @@ const identifications = class identifications {
9191
return iNaturalistAPI.get( "identifications/categories", params, opts );
9292
}
9393

94-
static vote( params, options ) {
95-
let endpoint = "votes/vote/exemplar_identification/:id";
96-
if ( iNaturalistAPI.apiURL && iNaturalistAPI.apiURL.match( /\/v2/ ) ) {
97-
endpoint = "identifications/:id/vote";
98-
}
99-
return iNaturalistAPI.post( endpoint, params, options )
100-
.then( Identification.typifyInstanceResponse );
101-
}
102-
103-
static unvote( params, options ) {
104-
let endpoint = "votes/unvote/exemplar_identification/:id";
105-
if ( iNaturalistAPI.apiURL && iNaturalistAPI.apiURL.match( /\/v2/ ) ) {
106-
endpoint = "identifications/:id/vote";
107-
}
108-
return iNaturalistAPI.delete( endpoint, params, options );
109-
}
110-
11194
static nominate( params, options ) {
11295
return iNaturalistAPI.post( "identifications/:id/nominate", params, options );
11396
}

lib/endpoints/taxon_identifications.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/inaturalistjs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
comments: require( "./endpoints/comments" ),
1212
computervision: require( "./endpoints/computervision" ),
1313
controlled_terms: require( "./endpoints/controlled_terms" ),
14+
exemplar_identifications: require( "./endpoints/exemplar_identifications" ),
1415
flags: require( "./endpoints/flags" ),
1516
identifications: require( "./endpoints/identifications" ),
1617
messages: require( "./endpoints/messages" ),
@@ -32,13 +33,13 @@ module.exports = {
3233
sounds: require( "./endpoints/sounds" ),
3334
taxa: require( "./endpoints/taxa" ),
3435
taxon_id_summaries: require( "./endpoints/taxon_id_summaries" ),
35-
taxon_identifications: require( "./endpoints/taxon_identifications" ),
3636
taxon_name_priorities: require( "./endpoints/taxon_name_priorities" ),
3737
translations: require( "./endpoints/translations" ),
3838
users: require( "./endpoints/users" ),
3939
Annotation: require( "./models/annotation" ),
4040
Comment: require( "./models/comment" ),
4141
ControlledTerm: require( "./models/controlled_term" ),
42+
ExemplarIdentification: require( "./models/exemplar_identification" ),
4243
Flag: require( "./models/flag" ),
4344
Identification: require( "./models/identification" ),
4445
Observation: require( "./models/observation" ),
@@ -53,7 +54,6 @@ module.exports = {
5354
Site: require( "./models/site" ),
5455
Sound: require( "./models/sound" ),
5556
Taxon: require( "./models/taxon" ),
56-
TaxonIdentification: require( "./models/taxon_identification" ),
5757
User: require( "./models/user" ),
5858
FileUpload: require( "./models/file_upload" )
5959
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const Model = require( "./model" );
2+
const Identification = require( "./identification" );
3+
const Observation = require( "./observation" );
4+
5+
const ExemplarIdentification = class ExemplarIdentification extends Model {
6+
constructor( attrs ) {
7+
super( attrs );
8+
if ( this.identification ) {
9+
this.identification = new Identification( this.identification );
10+
if ( this.identification.observation ) {
11+
this.identification.observation = new Observation( this.identification.observation );
12+
}
13+
}
14+
}
15+
16+
static typifyInstanceResponse( response ) {
17+
return super.typifyInstanceResponse( response, ExemplarIdentification );
18+
}
19+
20+
static typifyResultsResponse( response ) {
21+
return super.typifyResultsResponse( response, ExemplarIdentification );
22+
}
23+
};
24+
25+
module.exports = ExemplarIdentification;

lib/models/taxon_identification.js

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const { expect } = require( "chai" );
2+
const nock = require( "nock" );
3+
const exemplarIdentifications = require( "../../lib/endpoints/exemplar_identifications" );
4+
const testHelper = require( "../../lib/test_helper" );
5+
6+
describe( "ExemplarIdentifications", ( ) => {
7+
describe( "search", ( ) => {
8+
it( "fetches exemplar_identifications", done => {
9+
nock( "http://localhost:4000" )
10+
.get( "/v1/exemplar_identifications" )
11+
.reply( 200, [{ id: 1 }] );
12+
exemplarIdentifications.search( { } ).then( results => {
13+
expect( results[0].id ).to.eq( 1 );
14+
done( );
15+
} );
16+
} );
17+
} );
18+
19+
describe( "vote", ( ) => {
20+
it( "posts to /votes/vote/exemplar_identification/:id", done => {
21+
nock( "http://localhost:3000" )
22+
.post( "/votes/vote/exemplar_identification/1" )
23+
.reply( 200, { id: 1 } );
24+
exemplarIdentifications.vote( { id: 1 } ).then( ( ) => {
25+
done( );
26+
} );
27+
} );
28+
describe( "v2", ( ) => {
29+
beforeEach( testHelper.v1ToV2 );
30+
afterEach( testHelper.v2ToV1 );
31+
it( "posts to /exemplar_identifications/:id/vote", done => {
32+
nock( "http://localhost:4000" )
33+
.post( "/v2/exemplar_identifications/1/vote" )
34+
.reply( 200, { id: 1 } );
35+
exemplarIdentifications.vote( { id: 1 } ).then( ( ) => {
36+
done( );
37+
} );
38+
} );
39+
} );
40+
} );
41+
42+
describe( "unvote", ( ) => {
43+
it( "deletes to /votes/unvote/exemplar_identification/:id", done => {
44+
nock( "http://localhost:3000" )
45+
.delete( "/votes/unvote/exemplar_identification/1" )
46+
.reply( 200, { id: 1 } );
47+
exemplarIdentifications.unvote( { id: 1 } ).then( ( ) => {
48+
done( );
49+
} );
50+
} );
51+
describe( "v2", ( ) => {
52+
beforeEach( testHelper.v1ToV2 );
53+
afterEach( testHelper.v2ToV1 );
54+
it( "deletes to /exemplar_identifications/:id/vote", done => {
55+
nock( "http://localhost:4000" )
56+
.delete( "/v2/exemplar_identifications/1/vote" )
57+
.reply( 200, { id: 1 } );
58+
exemplarIdentifications.unvote( { id: 1 } ).then( ( ) => {
59+
done( );
60+
} );
61+
} );
62+
} );
63+
} );
64+
} );

0 commit comments

Comments
 (0)