├── README.md ├── pom.xml └── src └── main └── java └── ru └── blizzed └── discogsdb ├── DiscogsAuthData.java ├── DiscogsDBApi.java ├── DiscogsDBApiCaller.java ├── DiscogsDBCallException.java ├── DiscogsDBCaller.java ├── DiscogsDBErrorException.java ├── model ├── CommunityReleaseRating.java ├── Currency.java ├── Error.java ├── Image.java ├── Page.java ├── PaginatedResult.java ├── SearchPage.java ├── Type.java ├── artist │ ├── Artist.java │ ├── ArtistRelease.java │ └── Member.java ├── label │ ├── Label.java │ └── LabelRelease.java ├── release │ ├── Community.java │ ├── Company.java │ ├── Contributor.java │ ├── ExtraArtist.java │ ├── Format.java │ ├── Identifier.java │ ├── Label.java │ ├── MasterRelease.java │ ├── Rating.java │ ├── Release.java │ ├── SimpleArtist.java │ ├── Submitter.java │ ├── Track.java │ ├── UserReleaseRating.java │ ├── Version.java │ └── Video.java └── search │ ├── BaseSearchResult.java │ └── ReleaseSearchResult.java └── params ├── DiscogsDBParams.java ├── EnumParam.java ├── Param.java ├── ParamsConverter.java ├── SortOrderParam.java ├── SortParam.java └── TypeParam.java /README.md: -------------------------------------------------------------------------------- 1 | # DiscogsDB 2 | Simple Java library for [Discogs's Database][doc] API 3 | 4 | **DiscogsDB** provides easy access to all available methods of Discogs's Database API. 5 | Can be useful for grabbing data of artists, releases, labels, etc. 6 | 7 | * Contains Java object wrappers for any API response 8 | * Supports paginated result response (search or lists with many objects) 9 | * Convenient request builders 10 | 11 | Full list of methods available in [Discogs's Database Documentation][doc] 12 | 13 | ## Installing 14 | 15 | #### Maven 16 | 17 | In your pom.xml inside the *\* tag 18 | ```xml 19 | 20 | ... 21 | 22 | ru.blizzed 23 | discogsdb 24 | 1.0.3 25 | 26 | 27 | ``` 28 | 29 | #### Gradle 30 | 31 | In your build.gradle file inside the *dependencies* section 32 | 33 | * Gradle 3.0 and above 34 | ``` 35 | dependencies { 36 | ... 37 | implementation 'ru.blizzed:discogsdb:1.0.3' 38 | } 39 | ``` 40 | 41 | * Below 3.0 42 | ``` 43 | dependencies { 44 | ... 45 | compile 'ru.blizzed:discogsdb:1.0.3' 46 | } 47 | ``` 48 | 49 | ## Usage 50 | 51 | #### Initialization 52 | 53 | * You're not going to use `search` method 54 | 55 | ```java 56 | DiscogsDBApi.initialize(); 57 | ``` 58 | 59 | * You are planned to use `search` method 60 | 61 | ```java 62 | DiscogsDBApi.initialize(new DiscogsAuthData("your-consumer-key", "your-consumer-secret")); 63 | ``` 64 | 65 | #### Building and executing requests 66 | 67 | All methods of Discogs's Database API are available in `DiscogsDBApi` class after initialization. 68 | You can pass any params to the call – just take a look at static class `DiscogsDBParams` that 69 | contains completed instances of all parameters. 70 | 71 | Imagine that you need to check if user's input artist name is correct. Then you need to 72 | learn an artist's ID first. 73 | 74 | ```java 75 | String userInput = "KoЯn"; 76 | ``` 77 | 78 | ```java 79 | Page page = DiscogsDBApi.searchArtist( 80 | DiscogsDBParams.QUERY.of(userInput) 81 | ).execute(); 82 | ``` 83 | 84 | or the same but with a set of params 85 | 86 | ```java 87 | Page page = DiscogsDBApi.searchArtist( 88 | DiscogsDBParams.QUERY.of(userInput), 89 | DiscogsDBParams.COUNTRY.of("Russia") 90 | ).execute(); 91 | ``` 92 | 93 | ```java 94 | long kornId = page.getContent().get(0).getId(); // Congrats! 95 | ``` 96 | 97 | 98 | #### Callbacks 99 | That's nice! Now you have Korn's ID in Discogs so you can get all their name variations. 100 | You can receive callbacks in two ways: 101 | 102 | * Catching exceptions 103 | ```java 104 | try { 105 | DiscogsDBApi.getArtist(kornId).execute().getNameVariations().forEach(System.out::println); 106 | } catch (DiscogsDBCallException | DiscogsDBErrorException e) { 107 | // Handle error 108 | } 109 | ``` 110 | * With listener 111 | ```java 112 | DiscogsDBApi.getArtist(kornId).execute(new DiscogsDBCaller.Listener() { 113 | @Override 114 | public void onComplete(Artist result, DiscogsDBCaller caller) { 115 | result.getNameVariations().forEach(System.out::println); 116 | } 117 | @Override 118 | public void onError(Error error, DiscogsDBCaller caller) { 119 | /* This method triggers you when API has been called but response contains an error */ 120 | // Handle Api Error 121 | } 122 | @Override 123 | public void onFailure(DiscogsDBCallException e, DiscogsDBCaller caller) { 124 | /* This method triggers you when call to API cannot be established. E.g. no internet connection */ 125 | // Handle Failure 126 | } 127 | }); 128 | ``` 129 | **Tip:** you can override not all callback methods 130 | 131 | #### Requests cancelling 132 | It goes without saying that you can also cancel request immediately if needs 133 | ```java 134 | caller.cancel(); 135 | ``` 136 | 137 | ## License 138 | 139 | ``` 140 | Copyright (c) 2017 BlizzedRu (Ivan Vlasov) 141 | 142 | Licensed under the Apache License, Version 2.0 (the "License"); 143 | you may not use this file except in compliance with the License. 144 | You may obtain a copy of the License at 145 | 146 | http://www.apache.org/licenses/LICENSE-2.0 147 | 148 | Unless required by applicable law or agreed to in writing, software 149 | distributed under the License is distributed on an "AS IS" BASIS, 150 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 151 | See the License for the specific language governing permissions and 152 | limitations under the License. 153 | ``` 154 | 155 | [doc]: http://www.discogs.com/developers/#page:database -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 4.0.0 22 | 23 | ru.blizzed 24 | discogsdb 25 | 1.0.3 26 | jar 27 | DiscogsDB 28 | Simple Java library for Discogs's Database API 29 | https://github.com/BlizzedRu/DiscogsDB 30 | 31 | 32 | 1.8 33 | 1.8 34 | 35 | 36 | 37 | 38 | Apache License, Version 2.0 39 | http://www.apache.org/licenses/LICENSE-2.0.txt 40 | repo 41 | 42 | 43 | 44 | 45 | scm:git:https://github.com/BlizzedRu/DiscogsDB.git 46 | scm:git:https://github.com/BlizzedRu/DiscogsDB.git 47 | Prepare release 48 | https://github.com/BlizzedRu/DiscogsDB 49 | 50 | 51 | 52 | 53 | ossrh 54 | https://oss.sonatype.org/content/repositories/snapshots 55 | 56 | 57 | ossrh 58 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 59 | 60 | 61 | 62 | 63 | 64 | 65 | org.apache.maven.plugins 66 | maven-source-plugin 67 | 2.2.1 68 | 69 | 70 | attach-sources 71 | 72 | jar-no-fork 73 | 74 | 75 | 76 | 77 | 78 | org.apache.maven.plugins 79 | maven-javadoc-plugin 80 | 2.9.1 81 | 82 | 83 | attach-javadocs 84 | 85 | jar 86 | 87 | 88 | 89 | 90 | 91 | org.apache.maven.plugins 92 | maven-gpg-plugin 93 | 1.5 94 | 95 | ${gpg.passphrase} 96 | ${gpg.home} 97 | 98 | 99 | 100 | sign-artifacts 101 | verify 102 | 103 | sign 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | BlizzedRu 114 | Ivan Vlasov 115 | me@blizzed.ru 116 | http://blizzed.ru 117 | Europe/Moscow 118 | 119 | 120 | 121 | 122 | 123 | com.squareup.retrofit2 124 | retrofit 125 | 2.3.0 126 | 127 | 128 | 129 | com.squareup.retrofit2 130 | converter-gson 131 | 2.3.0 132 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /src/main/java/ru/blizzed/discogsdb/DiscogsAuthData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 BlizzedRu (Ivan Vlasov) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package ru.blizzed.discogsdb; 18 | 19 | public class DiscogsAuthData { 20 | private String consumerKey; 21 | private String consumerSecret; 22 | 23 | public DiscogsAuthData(String consumerKey, String consumerSecret) { 24 | this.consumerKey = consumerKey; 25 | this.consumerSecret = consumerSecret; 26 | } 27 | 28 | public String getConsumerKey() { 29 | return consumerKey; 30 | } 31 | 32 | public void setConsumerKey(String consumerKey) { 33 | this.consumerKey = consumerKey; 34 | } 35 | 36 | public String getConsumerSecret() { 37 | return consumerSecret; 38 | } 39 | 40 | public void setConsumerSecret(String consumerSecret) { 41 | this.consumerSecret = consumerSecret; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/ru/blizzed/discogsdb/DiscogsDBApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 BlizzedRu (Ivan Vlasov) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package ru.blizzed.discogsdb; 18 | 19 | import okhttp3.HttpUrl; 20 | import okhttp3.OkHttpClient; 21 | import okhttp3.Request; 22 | import okhttp3.ResponseBody; 23 | import retrofit2.Converter; 24 | import retrofit2.Retrofit; 25 | import retrofit2.converter.gson.GsonConverterFactory; 26 | import ru.blizzed.discogsdb.model.*; 27 | import ru.blizzed.discogsdb.model.Error; 28 | import ru.blizzed.discogsdb.model.artist.Artist; 29 | import ru.blizzed.discogsdb.model.artist.ArtistRelease; 30 | import ru.blizzed.discogsdb.model.label.Label; 31 | import ru.blizzed.discogsdb.model.label.LabelRelease; 32 | import ru.blizzed.discogsdb.model.release.MasterRelease; 33 | import ru.blizzed.discogsdb.model.release.Release; 34 | import ru.blizzed.discogsdb.model.release.UserReleaseRating; 35 | import ru.blizzed.discogsdb.model.release.Version; 36 | import ru.blizzed.discogsdb.model.search.BaseSearchResult; 37 | import ru.blizzed.discogsdb.model.search.ReleaseSearchResult; 38 | import ru.blizzed.discogsdb.params.Param; 39 | import ru.blizzed.discogsdb.params.ParamsConverter; 40 | 41 | import java.io.IOException; 42 | import java.lang.annotation.Annotation; 43 | 44 | public class DiscogsDBApi { 45 | 46 | private static final String ROOT_URL = "https://api.discogs.com/"; 47 | 48 | private static DiscogsDBApi instance; 49 | 50 | private DiscogsAuthData authData; 51 | private DiscogsDBApiCaller caller; 52 | private Retrofit retrofit; 53 | 54 | private DiscogsDBApi(DiscogsAuthData authData) { 55 | this.authData = authData; 56 | 57 | Retrofit.Builder builder = new Retrofit.Builder() 58 | .baseUrl(ROOT_URL) 59 | .addConverterFactory(GsonConverterFactory.create()); 60 | 61 | if (authData != null) { 62 | OkHttpClient httpClient = new OkHttpClient.Builder() 63 | .addInterceptor((chain -> { 64 | Request request = chain.request(); 65 | HttpUrl url = request.url().newBuilder() 66 | .addQueryParameter("key", authData.getConsumerKey()) 67 | .addQueryParameter("secret", authData.getConsumerSecret()) 68 | .build(); 69 | request = request.newBuilder().url(url).build(); 70 | return chain.proceed(request); 71 | })) 72 | .build(); 73 | 74 | builder.client(httpClient); 75 | } 76 | 77 | retrofit = builder.build(); 78 | caller = retrofit.create(DiscogsDBApiCaller.class); 79 | } 80 | 81 | public static DiscogsDBApi getInstance() { 82 | checkInit(); 83 | return instance; 84 | } 85 | 86 | public static void initialize(DiscogsAuthData discogsAuthData) { 87 | if (instance == null) 88 | instance = new DiscogsDBApi(discogsAuthData); 89 | } 90 | 91 | public static void initialize() { 92 | initialize(null); 93 | } 94 | 95 | /** 96 | * Checks if you (or someone else) initialized DiscogsDBApi 97 | * 98 | * @return true if DiscogsDBApi is initialized 99 | */ 100 | public static boolean isInitialized() { 101 | return instance != null; 102 | } 103 | 104 | 105 | /** Methods **/ 106 | 107 | public static DiscogsDBCaller getRelease(long releaseId) { 108 | return new DiscogsDBCaller<>(getCaller().getRelease(releaseId)); 109 | } 110 | 111 | public static DiscogsDBCaller getRelease(long releaseId, Currency currency) { 112 | return new DiscogsDBCaller<>(getCaller().getRelease(releaseId, currency.name())); 113 | } 114 | 115 | public static DiscogsDBCaller getUserReleaseRating(long releaseId, String username) { 116 | return new DiscogsDBCaller<>(getCaller().getUserReleaseRating(releaseId, username)); 117 | } 118 | 119 | public static DiscogsDBCaller getCommunityReleaseRating(long releaseId) { 120 | return new DiscogsDBCaller<>(getCaller().getCommunityReleaseRating(releaseId)); 121 | } 122 | 123 | public static DiscogsDBCaller getMasterRelease(long masterId) { 124 | return new DiscogsDBCaller<>(getCaller().getMasterRelease(masterId)); 125 | } 126 | 127 | public static DiscogsDBCaller> getMasterReleaseVersions(long releaseId, Param... params) { 128 | return new DiscogsDBCaller<>(getCaller().getMasterReleaseVersions(releaseId, ParamsConverter.asMap(params))); 129 | } 130 | 131 | public static DiscogsDBCaller getArtist(long artistId) { 132 | return new DiscogsDBCaller<>(getCaller().getArtist(artistId)); 133 | } 134 | 135 | public static DiscogsDBCaller> getArtistReleases(long artistId, Param... params) { 136 | return new DiscogsDBCaller<>(getCaller().getArtistReleases(artistId, ParamsConverter.asMap(params))); 137 | } 138 | 139 | public static DiscogsDBCaller