/
IndexHerbariorum.java
88 lines (75 loc) · 2.07 KB
/
IndexHerbariorum.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package org.gbif.registry.collections.sync;
import lombok.Data;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;
import retrofit2.http.GET;
import java.io.IOException;
import java.util.List;
/**
* Lightweight IndexHerbariorum client.
*/
class IndexHerbariorum {
static List<IndexHerbariorum.Institution> institutions() throws IOException {
return newClient().listInstitutions().execute().body().getData();
}
private static API newClient() {
Retrofit retrofit = new Retrofit.Builder()
//.baseUrl("http://sweetgum.nybg.org/science/api/v1/") // TODO: Parameterize
.baseUrl("http://labs.gbif.org/") // go easy on them...
.addConverterFactory(JacksonConverterFactory.create())
.build();
return retrofit.create(API.class);
}
private interface API {
@GET("institutions")
Call<InstitutionWrapper> listInstitutions();
}
@Data
private static class InstitutionWrapper {
private Meta meta;
private List<Institution> data;
@Data
private static class Meta {
private int hits;
private int code;
}
}
@Data
static class Institution {
private String irn;
private String organization;
private String code;
private String division;
private String department;
private long specimenTotal;
private Address address;
private Contact contact;
private Location location;
private String dateModified;
@Data
static class Address {
private String physicalStreet;
private String physicalCity;
private String physicalState;
private String physicalZipCode;
private String physicalCountry;
private String postalStreet;
private String postalCity;
private String postalState;
private String postalZipCode;
private String postalCountry;
}
@Data
static class Contact {
private String phone;
private String email;
private String webUrl;
}
@Data
static class Location {
private Double lat;
private Double lon;
}
}
}