1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.christianschenk.bibsonomy.export;
20
21 import java.util.List;
22
23 import org.bibsonomy.model.Bookmark;
24 import org.bibsonomy.model.Post;
25 import org.bibsonomy.model.Resource;
26 import org.bibsonomy.rest.client.Bibsonomy;
27 import org.bibsonomy.rest.client.exception.ErrorPerformingRequestException;
28 import org.bibsonomy.rest.client.queries.get.GetPostsQuery;
29
30
31
32
33
34
35 public class BibSonomyClient {
36
37 private final String username;
38 private final String apikey;
39 private final int MAX_POSTS = Integer.MAX_VALUE;
40
41 public BibSonomyClient(final String username, final String apikey) {
42 this.username = username;
43 this.apikey = apikey;
44 }
45
46 public List<Post<? extends Resource>> getAllBookmarksFromBibSonomy() {
47 final Bibsonomy client = new Bibsonomy(this.username, this.apikey);
48 client.setApiURL("http://www.bibsonomy.org/api/users/" + this.username);
49
50 final GetPostsQuery gpq = new GetPostsQuery(0, this.MAX_POSTS);
51 gpq.setResourceType(Bookmark.class);
52
53 try {
54 client.executeQuery(gpq);
55
56 if (gpq.getHttpStatusCode() != 200) {
57 throw new ErrorPerformingRequestException("HTTP status code: " + gpq.getHttpStatusCode() + " " + gpq.getError());
58 }
59
60 return gpq.getResult();
61 } catch (final ErrorPerformingRequestException ex) {
62 throw new RuntimeException("Couldn't fetch bookmarks from BibSonomy", ex);
63 }
64 }
65 }