├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── MarvelApiClient ├── build.gradle └── src │ ├── main │ └── java │ │ └── com │ │ └── karumi │ │ └── marvelapiclient │ │ ├── AuthHashGenerator.java │ │ ├── AuthInterceptor.java │ │ ├── CharacterApiClient.java │ │ ├── CharacterApiRest.java │ │ ├── ComicApiClient.java │ │ ├── ComicApiRest.java │ │ ├── MarvelApiClient.java │ │ ├── MarvelApiConfig.java │ │ ├── MarvelApiException.java │ │ ├── MarvelAuthApiException.java │ │ ├── MarvelError.java │ │ ├── SeriesApiClient.java │ │ ├── SeriesApiRest.java │ │ ├── TimeProvider.java │ │ ├── model │ │ ├── CharacterDto.java │ │ ├── CharacterResourceDto.java │ │ ├── CharactersDto.java │ │ ├── CharactersQuery.java │ │ ├── ComicDto.java │ │ ├── ComicResourceDto.java │ │ ├── ComicsDto.java │ │ ├── ComicsQuery.java │ │ ├── CreatorResourceDto.java │ │ ├── EventResourceDto.java │ │ ├── Format.java │ │ ├── MarvelCollection.java │ │ ├── MarvelDate.java │ │ ├── MarvelImage.java │ │ ├── MarvelPrice.java │ │ ├── MarvelResourceDto.java │ │ ├── MarvelResources.java │ │ ├── MarvelResponse.java │ │ ├── MarvelUrl.java │ │ ├── OrderBy.java │ │ ├── SerieResourceDto.java │ │ ├── SeriesCollectionDto.java │ │ ├── SeriesDto.java │ │ ├── SeriesQuery.java │ │ ├── StoryResourceDto.java │ │ └── TextObject.java │ │ └── utils │ │ └── DateUtil.java │ └── test │ ├── java │ └── com │ │ └── karumi │ │ └── marvelapiclient │ │ ├── ApiClientTest.java │ │ ├── AuthHashGeneratorTest.java │ │ ├── CharacterApiClientTest.java │ │ ├── ComicApiClientTest.java │ │ ├── MarvelApiConfigTest.java │ │ ├── SeriesApiClientTest.java │ │ ├── extensions │ │ └── FileExtensions.java │ │ └── model │ │ └── CharactersQueryTest.java │ └── resources │ ├── getCharacter.json │ ├── getCharacters.json │ ├── getComic.json │ ├── getComics.json │ ├── getSeries.json │ └── getSeriesCollection.json ├── README.md ├── _config.yml ├── build.gradle ├── config └── checkstyle │ └── checkstyle.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── sample ├── build.gradle └── src │ └── main │ └── java │ └── com │ └── karumi │ └── marvelapiclient │ └── sample │ └── MarveApiClientDemo.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | /*/build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | *.iml 29 | .idea 30 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | script: 4 | ./gradlew checkstyle assemble test -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing 2 | ============ 3 | 4 | :+1::tada: First off, thanks for taking the time to contribute! :tada::+1: 5 | 6 | If you would like to contribute code to this repository you can do so through GitHub by 7 | forking the repository and sending a pull request or opening an issue. 8 | 9 | When submitting code, please make every effort to follow existing conventions 10 | and style in order to keep the code as readable as possible. Please also make 11 | sure your code compiles, passes the tests and the checkstyle configured for this repository. 12 | 13 | 14 | Some tips that will help you to contribute to this repository: 15 | 16 | * Write clean code and test it. 17 | * Follow the repository code style. 18 | * Write good commit messages. 19 | * Do not send pull requests without checking if the project build is OK in Travis-CI. 20 | * Review if your changes affects the repository documentation and update it. 21 | * Describe the PR content and don't hesitate to add comments to explain us why you've added or changed something. 22 | 23 | Code of conduct 24 | --------------- 25 | 26 | As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. 27 | 28 | We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. 29 | 30 | Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct. 31 | 32 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team. 33 | 34 | This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. 35 | 36 | Instances of abusive, harassing, or otherwise unacceptable behavior can be reported by emailing hello@karumi.com. 37 | 38 | This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org/version/1/3/0/), version 1.3.0, available at [http://contributor-covenant.org/version/1/3/0/](http://contributor-covenant.org/version/1/3/0/). -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /MarvelApiClient/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | apply plugin: 'java' 17 | apply plugin: 'maven' 18 | apply plugin: 'signing' 19 | 20 | sourceCompatibility = 1.7 21 | 22 | repositories { 23 | mavenCentral() 24 | } 25 | 26 | def isReleaseBuild() { 27 | return VERSION_NAME.contains("SNAPSHOT") == false 28 | } 29 | 30 | def getRepositoryUsername() { 31 | return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "" 32 | } 33 | 34 | def getRepositoryPassword() { 35 | return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : "" 36 | } 37 | 38 | signing { 39 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } 40 | sign configurations.archives 41 | } 42 | 43 | task javadocJar(type: Jar) { 44 | classifier = 'javadoc' 45 | from javadoc 46 | } 47 | 48 | task sourcesJar(type: Jar) { 49 | classifier = 'sources' 50 | from sourceSets.main.allSource 51 | } 52 | 53 | artifacts { 54 | archives javadocJar, sourcesJar 55 | } 56 | 57 | uploadArchives { 58 | repositories { 59 | mavenDeployer { 60 | // POM signature 61 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } 62 | // Target repository 63 | repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { 64 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) 65 | } 66 | 67 | pom.groupId = GROUP 68 | pom.artifactId = POM_ARTIFACT_ID 69 | pom.version = VERSION_NAME 70 | 71 | pom.project { 72 | name POM_NAME 73 | description POM_DESCRIPTION 74 | packaging POM_PACKAGING 75 | url POM_URL 76 | 77 | scm { 78 | connection POM_SCM_CONNECTION 79 | developerConnection POM_SCM_DEV_CONNECTION 80 | url POM_SCM_URL 81 | } 82 | 83 | licenses { 84 | license { 85 | name POM_LICENCE_NAME 86 | url POM_LICENCE_URL 87 | distribution POM_LICENCE_DIST 88 | } 89 | } 90 | 91 | developers { 92 | developer { 93 | id = POM_DEVELOPER_ID 94 | name = POM_DEVELOPER_NAME 95 | } 96 | } 97 | } 98 | } 99 | } 100 | } 101 | 102 | sourceSets { 103 | test { 104 | output.resourcesDir = "build/classes/test/resources" 105 | } 106 | } 107 | 108 | dependencies { 109 | def okHttpVersion = "3.6.0" 110 | def retrofitVersion = "2.2.0" 111 | 112 | testCompile group: 'junit', name: 'junit', version: '4.12' 113 | testCompile "org.mockito:mockito-all:1.9.5" 114 | testCompile "com.squareup.okhttp:mockwebserver:2.7.5" 115 | testCompile "commons-io:commons-io:2.5" 116 | 117 | compile "com.squareup.okhttp3:okhttp:$okHttpVersion" 118 | compile "com.squareup.okhttp3:logging-interceptor:$okHttpVersion" 119 | compile "com.squareup.retrofit2:retrofit:$retrofitVersion" 120 | compile "com.squareup.retrofit2:converter-gson:$retrofitVersion" 121 | compile "com.google.code.gson:gson:2.8.0" 122 | } 123 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/AuthHashGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient; 17 | 18 | import java.security.MessageDigest; 19 | import java.security.NoSuchAlgorithmException; 20 | 21 | class AuthHashGenerator { 22 | String generateHash(String timestamp, String publicKey, String privateKey) 23 | throws MarvelApiException { 24 | try { 25 | String value = timestamp + privateKey + publicKey; 26 | MessageDigest md5Encoder = MessageDigest.getInstance("MD5"); 27 | byte[] md5Bytes = md5Encoder.digest(value.getBytes()); 28 | 29 | StringBuilder md5 = new StringBuilder(); 30 | for (int i = 0; i < md5Bytes.length; ++i) { 31 | md5.append(Integer.toHexString((md5Bytes[i] & 0xFF) | 0x100).substring(1, 3)); 32 | } 33 | return md5.toString(); 34 | }catch (NoSuchAlgorithmException e) { 35 | throw new MarvelApiException("cannot generate the api key", e); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/AuthInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient; 17 | 18 | import java.io.IOException; 19 | import okhttp3.HttpUrl; 20 | import okhttp3.Interceptor; 21 | import okhttp3.Request; 22 | import okhttp3.Response; 23 | 24 | class AuthInterceptor implements Interceptor { 25 | private static final String TIMESTAMP_KEY = "ts"; 26 | private static final String HASH_KEY = "hash"; 27 | private static final String APIKEY_KEY = "apikey"; 28 | 29 | private final String publicKey; 30 | private final String privateKey; 31 | private final TimeProvider timeProvider; 32 | private final AuthHashGenerator authHashGenerator = new AuthHashGenerator(); 33 | 34 | AuthInterceptor(String publicKey, String privateKey, TimeProvider timeProvider) { 35 | this.publicKey = publicKey; 36 | this.privateKey = privateKey; 37 | this.timeProvider = timeProvider; 38 | } 39 | 40 | @Override public Response intercept(Chain chain) throws IOException { 41 | String timestamp = String.valueOf(timeProvider.currentTimeMillis()); 42 | String hash = null; 43 | try { 44 | hash = authHashGenerator.generateHash(timestamp, publicKey, privateKey); 45 | } catch (MarvelApiException e) { 46 | e.printStackTrace(); 47 | } 48 | Request request = chain.request(); 49 | HttpUrl url = request.url() 50 | .newBuilder() 51 | .addQueryParameter(TIMESTAMP_KEY, timestamp) 52 | .addQueryParameter(APIKEY_KEY, publicKey) 53 | .addQueryParameter(HASH_KEY, hash) 54 | .build(); 55 | request = request.newBuilder().url(url).build(); 56 | return chain.proceed(request); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/CharacterApiClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient; 17 | 18 | import com.karumi.marvelapiclient.model.CharacterDto; 19 | import com.karumi.marvelapiclient.model.CharactersDto; 20 | import com.karumi.marvelapiclient.model.CharactersQuery; 21 | import com.karumi.marvelapiclient.model.MarvelResponse; 22 | import java.util.Map; 23 | import retrofit2.Call; 24 | 25 | /** 26 | * Retrieves Character information given a {@link CharactersQuery} or some simple params like the 27 | * character id. A valid {@link MarvelApiConfig} is needed. 28 | */ 29 | public final class CharacterApiClient extends MarvelApiClient { 30 | 31 | public CharacterApiClient(MarvelApiConfig marvelApiConfig) { 32 | super(marvelApiConfig); 33 | } 34 | 35 | public MarvelResponse getAll(int offset, int limit) throws MarvelApiException { 36 | CharactersQuery query = 37 | CharactersQuery.Builder.create().withOffset(offset).withLimit(limit).build(); 38 | return getAll(query); 39 | } 40 | 41 | public MarvelResponse getAll(CharactersQuery charactersQuery) 42 | throws MarvelApiException { 43 | CharacterApiRest api = getApi(CharacterApiRest.class); 44 | 45 | Map queryAsMap = charactersQuery.toMap(); 46 | Call> call = api.getCharacters(queryAsMap); 47 | return execute(call); 48 | } 49 | 50 | public MarvelResponse getCharacter(String characterId) throws MarvelApiException { 51 | if (characterId == null || characterId.isEmpty()) { 52 | throw new IllegalArgumentException("The CharacterId must not be null or empty"); 53 | } 54 | CharacterApiRest api = getApi(CharacterApiRest.class); 55 | 56 | Call> call = api.getCharacter(characterId); 57 | MarvelResponse characters = execute(call); 58 | CharactersDto charactersDto = characters.getResponse(); 59 | if (charactersDto != null && charactersDto.getCount() > 0) { 60 | CharacterDto characterDto = charactersDto.getCharacters().get(0); 61 | MarvelResponse characterResponse = new MarvelResponse<>(characters); 62 | characterResponse.setResponse(characterDto); 63 | return characterResponse; 64 | } else { 65 | throw new MarvelApiException("Character not found", null); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/CharacterApiRest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient; 17 | 18 | import com.karumi.marvelapiclient.model.CharactersDto; 19 | import com.karumi.marvelapiclient.model.MarvelResponse; 20 | import java.util.Map; 21 | import retrofit2.Call; 22 | import retrofit2.http.GET; 23 | import retrofit2.http.Path; 24 | import retrofit2.http.QueryMap; 25 | 26 | public interface CharacterApiRest { 27 | @GET("characters") Call> getCharacters( 28 | @QueryMap Map characterFilter); 29 | 30 | @GET("characters/{id}") Call> getCharacter( 31 | @Path("id") String characterId); 32 | } 33 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/ComicApiClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient; 17 | 18 | import com.karumi.marvelapiclient.model.ComicDto; 19 | import com.karumi.marvelapiclient.model.ComicsDto; 20 | import com.karumi.marvelapiclient.model.ComicsQuery; 21 | import com.karumi.marvelapiclient.model.MarvelResponse; 22 | import java.util.Map; 23 | import retrofit2.Call; 24 | 25 | /** 26 | * Retrieves Comics information given a {@link ComicsQuery} or some simple params like the 27 | * character id. A valid {@link MarvelApiConfig} is needed. 28 | */ 29 | public final class ComicApiClient extends MarvelApiClient { 30 | 31 | public ComicApiClient(MarvelApiConfig marvelApiConfig) { 32 | super(marvelApiConfig); 33 | } 34 | 35 | public MarvelResponse getAll(int offset, int limit) throws MarvelApiException { 36 | ComicsQuery query = ComicsQuery.Builder.create().withOffset(offset).withLimit(limit).build(); 37 | return getAll(query); 38 | } 39 | 40 | public MarvelResponse getAll(ComicsQuery comicsQuery) throws MarvelApiException { 41 | ComicApiRest api = getApi(ComicApiRest.class); 42 | 43 | Map queryAsMap = comicsQuery.toMap(); 44 | Call> call = api.getComics(queryAsMap); 45 | return execute(call); 46 | } 47 | 48 | public MarvelResponse getComic(String comicId) throws MarvelApiException { 49 | if (comicId == null || comicId.isEmpty()) { 50 | throw new IllegalArgumentException("The ComicId must not be null or empty"); 51 | } 52 | ComicApiRest api = getApi(ComicApiRest.class); 53 | 54 | Call> call = api.getComic(comicId); 55 | MarvelResponse comics = execute(call); 56 | ComicsDto comicsDto = comics.getResponse(); 57 | if (comicsDto != null && comicsDto.getCount() > 0) { 58 | ComicDto comicDto = comicsDto.getComics().get(0); 59 | MarvelResponse comicResponse = new MarvelResponse<>(comics); 60 | comicResponse.setResponse(comicDto); 61 | return comicResponse; 62 | } else { 63 | throw new MarvelApiException("Comic not found", null); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/ComicApiRest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient; 17 | 18 | import com.karumi.marvelapiclient.model.ComicsDto; 19 | import com.karumi.marvelapiclient.model.MarvelResponse; 20 | import java.util.Map; 21 | import retrofit2.Call; 22 | import retrofit2.http.GET; 23 | import retrofit2.http.Path; 24 | import retrofit2.http.QueryMap; 25 | 26 | interface ComicApiRest { 27 | @GET("comics") Call> getComics( 28 | @QueryMap Map comicFilter); 29 | 30 | @GET("comics/{id}") Call> getComic( 31 | @Path("id") String comicId); 32 | } 33 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/MarvelApiClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient; 17 | 18 | import com.google.gson.Gson; 19 | import java.io.IOException; 20 | import retrofit2.Call; 21 | import retrofit2.Response; 22 | 23 | class MarvelApiClient { 24 | private static final int INVALID_AUTH_CODE = 401; 25 | 26 | private final MarvelApiConfig marvelApiConfig; 27 | 28 | public MarvelApiClient(MarvelApiConfig marvelApiConfig) { 29 | this.marvelApiConfig = marvelApiConfig; 30 | } 31 | 32 | T getApi(Class apiRest) { 33 | return marvelApiConfig.getRetrofit().create(apiRest); 34 | } 35 | 36 | public T execute(Call call) throws MarvelApiException { 37 | Response response = null; 38 | try { 39 | response = call.execute(); 40 | } catch (IOException e) { 41 | throw new MarvelApiException("Network error", e); 42 | } 43 | if (response.isSuccessful()) { 44 | return response.body(); 45 | } else { 46 | parseError(response); 47 | return null; 48 | } 49 | } 50 | 51 | private void parseError(Response execute) throws MarvelApiException { 52 | String marvelCode = ""; 53 | String marvelDescription = ""; 54 | if (execute.errorBody() != null) { 55 | Gson gson = new Gson(); 56 | try { 57 | String errorBody = execute.errorBody().string(); 58 | MarvelError marvelError = gson.fromJson(errorBody, MarvelError.class); 59 | marvelCode = marvelError.getCode(); 60 | marvelDescription = marvelError.getMessage(); 61 | if (marvelDescription == null || "".equals(marvelDescription)) { 62 | marvelDescription = marvelError.getStatus(); 63 | } 64 | } catch (IOException e) { 65 | } 66 | } 67 | 68 | if(execute.code() == INVALID_AUTH_CODE) { 69 | throw new MarvelAuthApiException(execute.code(), marvelCode, marvelDescription, null); 70 | } else { 71 | throw new MarvelApiException(execute.code(), marvelCode, marvelDescription, null); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/MarvelApiConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient; 17 | 18 | import okhttp3.OkHttpClient; 19 | import okhttp3.logging.HttpLoggingInterceptor; 20 | import retrofit2.Retrofit; 21 | import retrofit2.converter.gson.GsonConverterFactory; 22 | 23 | /** 24 | * Api client for access to Marvel Api. 25 | */ 26 | public class MarvelApiConfig { 27 | 28 | private static MarvelApiConfig singleton; 29 | private final String publicKey; 30 | private final String privateKey; 31 | private final boolean debug; 32 | private final Retrofit retrofit; 33 | 34 | MarvelApiConfig(String publicKey, String privateKey, Retrofit retrofit, boolean debug) { 35 | this.publicKey = publicKey; 36 | this.privateKey = privateKey; 37 | this.retrofit = retrofit; 38 | this.debug = debug; 39 | } 40 | 41 | public static MarvelApiConfig with(String publicKey, String privateKey) { 42 | if (singleton == null) { 43 | singleton = new Builder(publicKey, privateKey).build(); 44 | } 45 | return singleton; 46 | } 47 | 48 | public Retrofit getRetrofit() { 49 | return retrofit; 50 | } 51 | 52 | /** 53 | * Fluent API for creating {@link MarvelApiConfig} instances. 54 | */ 55 | @SuppressWarnings("UnusedDeclaration") public static class Builder { 56 | 57 | private static final String MARVEL_API_BASE_URL = "https://gateway.marvel.com/v1/public/"; 58 | private final String privateKey; 59 | private final String publicKey; 60 | private boolean debug; 61 | private Retrofit retrofit; 62 | private String baseUrl = MARVEL_API_BASE_URL; 63 | private TimeProvider timeProvider = new TimeProvider(); 64 | 65 | public Builder(String publicKey, String privateKey) { 66 | if (publicKey == null) { 67 | throw new IllegalArgumentException("publicKey must not be null."); 68 | } 69 | 70 | if (privateKey == null) { 71 | throw new IllegalArgumentException("privateKey must not be null."); 72 | } 73 | 74 | this.publicKey = publicKey; 75 | this.privateKey = privateKey; 76 | } 77 | 78 | public Builder debug() { 79 | this.debug = true; 80 | return this; 81 | } 82 | 83 | public Builder baseUrl(String url) { 84 | this.baseUrl = url; 85 | return this; 86 | } 87 | 88 | public Builder retrofit(Retrofit retrofit) { 89 | if (retrofit == null) { 90 | throw new IllegalArgumentException("retrofit must not be null."); 91 | } 92 | this.retrofit = retrofit; 93 | return this; 94 | } 95 | 96 | public MarvelApiConfig build() { 97 | if (retrofit == null) { 98 | retrofit = buildRetrofit(); 99 | } 100 | 101 | return new MarvelApiConfig(publicKey, privateKey, retrofit, debug); 102 | } 103 | 104 | private Retrofit buildRetrofit() { 105 | OkHttpClient.Builder builder = new OkHttpClient.Builder() 106 | .addInterceptor(new AuthInterceptor(publicKey, privateKey, timeProvider)); 107 | if (debug) { 108 | HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); 109 | interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); 110 | builder.addInterceptor(interceptor); 111 | } 112 | 113 | OkHttpClient client = builder.build(); 114 | 115 | return new Retrofit.Builder().baseUrl(baseUrl) 116 | .client(client) 117 | .addConverterFactory(GsonConverterFactory.create()) 118 | .build(); 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/MarvelApiException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient; 17 | 18 | public class MarvelApiException extends Exception { 19 | private final int httpCode; 20 | private final String marvelCode; 21 | 22 | public MarvelApiException(int httpCode, String marvelCode, String description, Throwable cause) { 23 | super(description, cause); 24 | this.httpCode = httpCode; 25 | this.marvelCode = marvelCode; 26 | } 27 | 28 | public MarvelApiException(String message, Throwable cause) { 29 | this(-1, "", message, cause); 30 | } 31 | 32 | public int getHttpCode() { 33 | return httpCode; 34 | } 35 | 36 | public String getMarvelCode() { 37 | return marvelCode; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/MarvelAuthApiException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient; 17 | 18 | public class MarvelAuthApiException extends MarvelApiException { 19 | public MarvelAuthApiException(int httpCode, String marvelCode, String description, 20 | Throwable cause) { 21 | super(httpCode, marvelCode, description, cause); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/MarvelError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient; 17 | 18 | import com.google.gson.annotations.SerializedName; 19 | 20 | class MarvelError { 21 | @SerializedName("code") private String code; 22 | @SerializedName("message") private String message; 23 | @SerializedName("status") private String status = ""; 24 | 25 | String getCode() { 26 | return code; 27 | } 28 | 29 | String getMessage() { 30 | return message; 31 | } 32 | 33 | String getStatus() { 34 | return status; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/SeriesApiClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient; 17 | 18 | import com.karumi.marvelapiclient.model.ComicsDto; 19 | import com.karumi.marvelapiclient.model.ComicsQuery; 20 | import com.karumi.marvelapiclient.model.MarvelResponse; 21 | import com.karumi.marvelapiclient.model.SeriesCollectionDto; 22 | import com.karumi.marvelapiclient.model.SeriesDto; 23 | import com.karumi.marvelapiclient.model.SeriesQuery; 24 | import java.util.Map; 25 | import retrofit2.Call; 26 | 27 | /** 28 | * Retrieves Series information given a {@link SeriesQuery} or some simple params like the 29 | * serie id. A valid {@link MarvelApiConfig} is needed. 30 | */ 31 | public final class SeriesApiClient extends MarvelApiClient { 32 | 33 | public SeriesApiClient(MarvelApiConfig marvelApiConfig) { 34 | super(marvelApiConfig); 35 | } 36 | 37 | public MarvelResponse getAll(int offset, int limit) 38 | throws MarvelApiException { 39 | SeriesQuery query = SeriesQuery.Builder.create().withOffset(offset).withLimit(limit).build(); 40 | return getAll(query); 41 | } 42 | 43 | public MarvelResponse getAll(SeriesQuery seriesQuery) 44 | throws MarvelApiException { 45 | SeriesApiRest api = getApi(SeriesApiRest.class); 46 | 47 | Map queryAsMap = seriesQuery.toMap(); 48 | Call> call = api.getSeries(queryAsMap); 49 | return execute(call); 50 | } 51 | 52 | public MarvelResponse getSeriesById(String seriesId) throws MarvelApiException { 53 | if (seriesId == null || seriesId.isEmpty()) { 54 | throw new IllegalArgumentException("The seriesId must not be null or empty"); 55 | } 56 | SeriesApiRest api = getApi(SeriesApiRest.class); 57 | 58 | Call> call = api.getSerie(seriesId); 59 | MarvelResponse series = execute(call); 60 | SeriesCollectionDto seriesCollectionDto = series.getResponse(); 61 | if (seriesCollectionDto != null && seriesCollectionDto.getCount() > 0) { 62 | SeriesDto seriesDto = seriesCollectionDto.getSeries().get(0); 63 | MarvelResponse serieResponse = new MarvelResponse<>(series); 64 | serieResponse.setResponse(seriesDto); 65 | return serieResponse; 66 | } else { 67 | throw new MarvelApiException("Series not found", null); 68 | } 69 | } 70 | 71 | public MarvelResponse getComicsBySeries(String seriesId, int offset, int limit) 72 | throws MarvelApiException { 73 | ComicsQuery query = ComicsQuery.Builder.create().withOffset(offset).withLimit(limit).build(); 74 | return getComicsBySeries(seriesId, query); 75 | } 76 | 77 | public MarvelResponse getComicsBySeries(String seriesId, ComicsQuery comicsQuery) 78 | throws MarvelApiException { 79 | if (seriesId == null || seriesId.isEmpty()) { 80 | throw new IllegalArgumentException("The seriesId must not be null or empty"); 81 | } 82 | SeriesApiRest api = getApi(SeriesApiRest.class); 83 | 84 | Map queryMap = comicsQuery.toMap(); 85 | Call> call = api.getComicsBySerie(seriesId, queryMap); 86 | 87 | return execute(call); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/SeriesApiRest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient; 17 | 18 | import com.karumi.marvelapiclient.model.ComicsDto; 19 | import com.karumi.marvelapiclient.model.MarvelResponse; 20 | import com.karumi.marvelapiclient.model.SeriesCollectionDto; 21 | import java.util.Map; 22 | import retrofit2.Call; 23 | import retrofit2.http.GET; 24 | import retrofit2.http.Path; 25 | import retrofit2.http.QueryMap; 26 | 27 | interface SeriesApiRest { 28 | @GET("series") Call> getSeries( 29 | @QueryMap Map seriesFilter); 30 | 31 | @GET("series/{id}") Call> getSerie( 32 | @Path("id") String serieId); 33 | 34 | @GET("series/{id}/comics") Call> getComicsBySerie( 35 | @Path("id") String serieId, @QueryMap Map comicFilter); 36 | } 37 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/TimeProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient; 17 | 18 | class TimeProvider { 19 | long currentTimeMillis() { 20 | return System.currentTimeMillis(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/CharacterDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | import com.google.gson.annotations.SerializedName; 19 | import java.util.List; 20 | 21 | public class CharacterDto { 22 | 23 | @SerializedName("id") private String id; 24 | @SerializedName("name") private String name; 25 | @SerializedName("description") private String description; 26 | @SerializedName("modified") private String modified; 27 | @SerializedName("resourceURI") private String resourceUri; 28 | @SerializedName("urls") private List urls; 29 | @SerializedName("thumbnail") private MarvelImage thumbnail; 30 | @SerializedName("comics") private MarvelResources comics; 31 | @SerializedName("stories") private MarvelResources stories; 32 | @SerializedName("events") private MarvelResources events; 33 | @SerializedName("series") private MarvelResources series; 34 | 35 | public String getId() { 36 | return id; 37 | } 38 | 39 | public String getName() { 40 | return name; 41 | } 42 | 43 | public String getDescription() { 44 | return description; 45 | } 46 | 47 | public String getModified() { 48 | return modified; 49 | } 50 | 51 | public String getResourceUri() { 52 | return resourceUri; 53 | } 54 | 55 | public List getUrls() { 56 | return urls; 57 | } 58 | 59 | public MarvelImage getThumbnail() { 60 | return thumbnail; 61 | } 62 | 63 | public MarvelResources getComics() { 64 | return comics; 65 | } 66 | 67 | public MarvelResources getStories() { 68 | return stories; 69 | } 70 | 71 | public MarvelResources getEvents() { 72 | return events; 73 | } 74 | 75 | public MarvelResources getSeries() { 76 | return series; 77 | } 78 | 79 | @Override public String toString() { 80 | return "CharacterDto{" 81 | + "id='" 82 | + id 83 | + '\'' 84 | + ", name='" 85 | + name 86 | + '\'' 87 | + ", description='" 88 | + description 89 | + '\'' 90 | + ", modified='" 91 | + modified 92 | + '\'' 93 | + ", resourceUri='" 94 | + resourceUri 95 | + '\'' 96 | + ", urls=" 97 | + urls 98 | + ", thumbnail=" 99 | + thumbnail 100 | + ", comics=" 101 | + comics 102 | + ", stories=" 103 | + stories 104 | + ", events=" 105 | + events 106 | + ", series=" 107 | + series 108 | + 109 | '}'; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/CharacterResourceDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | public class CharacterResourceDto extends MarvelResourceDto { 19 | } 20 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/CharactersDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | import com.google.gson.annotations.SerializedName; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | public class CharactersDto extends MarvelCollection { 23 | 24 | public List getCharacters() { 25 | return getResults(); 26 | } 27 | 28 | @Override public String toString() { 29 | return "CharactersDto{" 30 | + "offset=" 31 | + getOffset() 32 | + ", limit=" 33 | + getLimit() 34 | + ", total=" 35 | + getTotal() 36 | + ", count=" 37 | + getCount() 38 | + ", characters=" 39 | + getCharacters().toString() 40 | + '}'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/CharactersQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | import com.karumi.marvelapiclient.utils.DateUtil; 19 | import java.util.ArrayList; 20 | import java.util.Date; 21 | import java.util.HashMap; 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | public class CharactersQuery { 26 | 27 | private static final String QUERY_NAME = "name"; 28 | private static final String QUERY_NAME_START_WITH = "nameStartsWith"; 29 | private static final String QUERY_MODIFIED_SINCE = "modifiedSince"; 30 | private static final String QUERY_COMICS = "comics"; 31 | private static final String QUERY_SERIES = "series"; 32 | private static final String QUERY_EVENTS = "events"; 33 | private static final String QUERY_STORIES = "stories"; 34 | private static final String QUERY_ORDER_BY = "orderBy"; 35 | private static final String QUERY_LIMIT = "limit"; 36 | private static final String QUERY_OFFSET = "offset"; 37 | 38 | private String name; 39 | private String nameStartWith; 40 | private String modifiedSince; 41 | private String comics; 42 | private String series; 43 | private String events; 44 | private String stories; 45 | private String orderBy; 46 | private int limit; 47 | private int offset; 48 | 49 | private CharactersQuery(String name, String nameStartWith, String modifiedSince, String comics, 50 | String series, String events, String stories, String orderBy, int limit, int offset) { 51 | this.name = name; 52 | this.nameStartWith = nameStartWith; 53 | this.modifiedSince = modifiedSince; 54 | this.comics = comics; 55 | this.series = series; 56 | this.events = events; 57 | this.stories = stories; 58 | this.orderBy = orderBy; 59 | this.limit = limit; 60 | this.offset = offset; 61 | } 62 | 63 | public Map toMap() { 64 | Map returnValues = new HashMap<>(); 65 | 66 | if (name != null) { 67 | returnValues.put(CharactersQuery.QUERY_NAME, name); 68 | } 69 | 70 | if (nameStartWith != null) { 71 | returnValues.put(CharactersQuery.QUERY_NAME_START_WITH, nameStartWith); 72 | } 73 | 74 | if (modifiedSince != null) { 75 | returnValues.put(CharactersQuery.QUERY_MODIFIED_SINCE, modifiedSince); 76 | } 77 | 78 | if (comics != null) { 79 | returnValues.put(CharactersQuery.QUERY_COMICS, comics); 80 | } 81 | 82 | if (series != null) { 83 | returnValues.put(CharactersQuery.QUERY_SERIES, series); 84 | } 85 | 86 | if (events != null) { 87 | returnValues.put(CharactersQuery.QUERY_EVENTS, events); 88 | } 89 | 90 | if (stories != null) { 91 | returnValues.put(CharactersQuery.QUERY_STORIES, stories); 92 | } 93 | 94 | if (orderBy != null) { 95 | returnValues.put(CharactersQuery.QUERY_ORDER_BY, orderBy); 96 | } 97 | 98 | if (limit > 0) { 99 | returnValues.put(CharactersQuery.QUERY_LIMIT, limit); 100 | } 101 | 102 | if (offset > 0) { 103 | returnValues.put(CharactersQuery.QUERY_OFFSET, offset); 104 | } 105 | 106 | return returnValues; 107 | } 108 | 109 | 110 | public static class Builder { 111 | public final static int MAX_SIZE = 100; 112 | 113 | public static final String LIST_SEPARATOR = ","; 114 | private String name; 115 | private String nameStartWith; 116 | private Date modifiedSince; 117 | private List comics = new ArrayList<>(); 118 | private List series = new ArrayList<>(); 119 | private List events = new ArrayList<>(); 120 | private List stories = new ArrayList<>(); 121 | private OrderBy orderBy; 122 | private boolean orderByAscendant; 123 | private int limit; 124 | private int offset; 125 | 126 | private Builder() { 127 | } 128 | 129 | public static Builder create() { 130 | return new Builder(); 131 | } 132 | 133 | public Builder withName(String name) { 134 | this.name = name; 135 | return this; 136 | } 137 | 138 | public Builder withNameStartWith(String nameStartWith) { 139 | this.nameStartWith = nameStartWith; 140 | return this; 141 | } 142 | 143 | public Builder withModifiedSince(Date modifiedSince) { 144 | this.modifiedSince = modifiedSince; 145 | return this; 146 | } 147 | 148 | public Builder addComic(int comic) { 149 | comics.add(comic); 150 | return this; 151 | } 152 | 153 | public Builder addComics(List comics) { 154 | checkNull(comics); 155 | this.comics.addAll(comics); 156 | return this; 157 | } 158 | 159 | public Builder addSerie(int serie) { 160 | series.add(serie); 161 | return this; 162 | } 163 | 164 | public Builder addSeries(List series) { 165 | checkNull(series); 166 | this.series.addAll(series); 167 | return this; 168 | } 169 | 170 | public Builder addEvent(int event) { 171 | events.add(event); 172 | return this; 173 | } 174 | 175 | public Builder addEvents(List events) { 176 | checkNull(events); 177 | this.events.addAll(events); 178 | return this; 179 | } 180 | 181 | public Builder addStory(int story) { 182 | stories.add(story); 183 | return this; 184 | } 185 | 186 | public Builder addStory(List stories) { 187 | checkNull(stories); 188 | this.stories.addAll(stories); 189 | return this; 190 | } 191 | 192 | public Builder withOrderBy(OrderBy orderBy, boolean ascendant) { 193 | this.orderBy = orderBy; 194 | this.orderByAscendant = ascendant; 195 | return this; 196 | } 197 | 198 | public Builder withOrderBy(OrderBy orderBy) { 199 | this.orderBy = orderBy; 200 | this.orderByAscendant = true; 201 | return this; 202 | } 203 | 204 | public Builder withLimit(int limit) { 205 | checkLimit(limit); 206 | this.limit = limit; 207 | return this; 208 | } 209 | 210 | public Builder withOffset(int offset) { 211 | if (offset < 0) { 212 | throw new IllegalArgumentException("offset must be bigger or equals than zero"); 213 | } 214 | 215 | this.offset = offset; 216 | return this; 217 | } 218 | 219 | public CharactersQuery build() { 220 | String plainModifedSince = convertDate(modifiedSince); 221 | String plainComics = convertToList(comics); 222 | String plainEvents = convertToList(events); 223 | String plainSeries = convertToList(series); 224 | String plainStories = convertToList(stories); 225 | String plainOrderBy = convertOrderBy(orderBy, orderByAscendant); 226 | 227 | return new CharactersQuery(name, nameStartWith, plainModifedSince, plainComics, plainSeries, 228 | plainEvents, plainStories, plainOrderBy, limit, offset); 229 | } 230 | 231 | private void checkLimit(int limit) { 232 | if (limit <= 0) { 233 | throw new IllegalArgumentException("limit must be bigger than zero"); 234 | } 235 | 236 | if (limit > MAX_SIZE) { 237 | throw new IllegalArgumentException("limit must be smaller than 100"); 238 | } 239 | } 240 | 241 | private void checkNull(List list) { 242 | if (list == null) { 243 | throw new IllegalArgumentException("the collection can not be null"); 244 | } 245 | } 246 | 247 | private String convertDate(Date date) { 248 | if (date == null) { 249 | return null; 250 | } 251 | return DateUtil.parseDate(date); 252 | } 253 | 254 | private String convertOrderBy(OrderBy orderBy, boolean ascendant) { 255 | if (orderBy == null) { 256 | return null; 257 | } 258 | 259 | String plainOrderBy = orderBy.toString(); 260 | return (ascendant) ? plainOrderBy : "-" + plainOrderBy; 261 | } 262 | 263 | private String convertToList(List list) { 264 | String plainList = ""; 265 | for (int i = 0; i < list.size(); i++) { 266 | plainList += Integer.toString(list.get(i)); 267 | if (i < list.size() - 1) { 268 | plainList += LIST_SEPARATOR; 269 | } 270 | } 271 | return (plainList.isEmpty()) ? null : plainList; 272 | } 273 | } 274 | } 275 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/ComicDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | import com.google.gson.annotations.SerializedName; 18 | import java.util.List; 19 | 20 | public class ComicDto { 21 | @SerializedName("id") private String id; 22 | @SerializedName("digitalId") private int digitalId; 23 | @SerializedName("title") private String title; 24 | @SerializedName("issueNumber") private double issueNumber; 25 | @SerializedName("variantDescription") private String variantDescription; 26 | @SerializedName("description") private String description; 27 | @SerializedName("modified") private String modified; 28 | @SerializedName("isbn") private String isbn; 29 | @SerializedName("upc") private String upc; 30 | @SerializedName("diamondCode") private String diamondCode; 31 | @SerializedName("ean") private String ean; 32 | @SerializedName("issn") private String issn; 33 | @SerializedName("format") private String format; 34 | @SerializedName("pageCount") private int pageCount; 35 | @SerializedName("textObjects") private List textObjects; 36 | @SerializedName("resourceURI") private String resourceURI; 37 | @SerializedName("urls") private List urls; 38 | @SerializedName("series") private ComicResourceDto series; 39 | @SerializedName("variants") private List variants; 40 | @SerializedName("collections") private List collections; 41 | @SerializedName("collectedIssues") private List collectedIssues; 42 | @SerializedName("dates") private List dates; 43 | @SerializedName("prices") private List prices; 44 | @SerializedName("thumbnail") private MarvelImage thumbnail; 45 | @SerializedName("images") private List images; 46 | @SerializedName("creators") private MarvelResources creators; 47 | @SerializedName("characters") private MarvelResources characters; 48 | @SerializedName("stories") private MarvelResources stories; 49 | @SerializedName("events") private MarvelResources events; 50 | 51 | public String getId() { 52 | return id; 53 | } 54 | 55 | public int getDigitalId() { 56 | return digitalId; 57 | } 58 | 59 | public String getTitle() { 60 | return title; 61 | } 62 | 63 | public double getIssueNumber() { 64 | return issueNumber; 65 | } 66 | 67 | public String getVariantDescription() { 68 | return variantDescription; 69 | } 70 | 71 | public String getDescription() { 72 | return description; 73 | } 74 | 75 | public String getModified() { 76 | return modified; 77 | } 78 | 79 | public String getIsbn() { 80 | return isbn; 81 | } 82 | 83 | public String getUpc() { 84 | return upc; 85 | } 86 | 87 | public String getDiamondCode() { 88 | return diamondCode; 89 | } 90 | 91 | public String getEan() { 92 | return ean; 93 | } 94 | 95 | public String getIssn() { 96 | return issn; 97 | } 98 | 99 | public String getFormat() { 100 | return format; 101 | } 102 | 103 | public int getPageCount() { 104 | return pageCount; 105 | } 106 | 107 | public List getTextObjects() { 108 | return textObjects; 109 | } 110 | 111 | public String getResourceURI() { 112 | return resourceURI; 113 | } 114 | 115 | public List getUrls() { 116 | return urls; 117 | } 118 | 119 | public ComicResourceDto getSeries() { 120 | return series; 121 | } 122 | 123 | public List getVariants() { 124 | return variants; 125 | } 126 | 127 | public List getCollections() { 128 | return collections; 129 | } 130 | 131 | public List getCollectedIssues() { 132 | return collectedIssues; 133 | } 134 | 135 | public List getDates() { 136 | return dates; 137 | } 138 | 139 | public List getPrices() { 140 | return prices; 141 | } 142 | 143 | public MarvelImage getThumbnail() { 144 | return thumbnail; 145 | } 146 | 147 | public List getImages() { 148 | return images; 149 | } 150 | 151 | public MarvelResources getCreators() { 152 | return creators; 153 | } 154 | 155 | public MarvelResources getCharacters() { 156 | return characters; 157 | } 158 | 159 | public MarvelResources getStories() { 160 | return stories; 161 | } 162 | 163 | public MarvelResources getEvents() { 164 | return events; 165 | } 166 | 167 | @Override public String toString() { 168 | return "ComicDto{" + 169 | "id='" + id + '\'' + 170 | ", digitalId=" + digitalId + 171 | ", title='" + title + '\'' + 172 | ", issueNumber=" + issueNumber + 173 | ", variantDescription='" + variantDescription + '\'' + 174 | ", description='" + description + '\'' + 175 | ", modified='" + modified + '\'' + 176 | ", isbn='" + isbn + '\'' + 177 | ", upc='" + upc + '\'' + 178 | ", diamondCode='" + diamondCode + '\'' + 179 | ", ean='" + ean + '\'' + 180 | ", issn='" + issn + '\'' + 181 | ", format='" + format + '\'' + 182 | ", pageCount=" + pageCount + 183 | ", textObjects=" + textObjects + 184 | ", resourceURI='" + resourceURI + '\'' + 185 | ", urls=" + urls + 186 | ", series=" + series + 187 | ", variants=" + variants + 188 | ", collections=" + collections + 189 | ", collectedIssues=" + collectedIssues + 190 | ", dates=" + dates + 191 | ", prices=" + prices + 192 | ", thumbnail=" + thumbnail + 193 | ", images=" + images + 194 | ", creators=" + creators + 195 | ", characters=" + characters + 196 | ", stories=" + stories + 197 | ", events=" + events + 198 | '}'; 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/ComicResourceDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | public class ComicResourceDto extends MarvelResourceDto { 19 | } 20 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/ComicsDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | import java.util.List; 19 | 20 | public class ComicsDto extends MarvelCollection { 21 | 22 | public List getComics() { 23 | return getResults(); 24 | } 25 | 26 | @Override public String toString() { 27 | return "CharactersDto{" 28 | + "offset=" 29 | + getOffset() 30 | + ", limit=" 31 | + getLimit() 32 | + ", total=" 33 | + getTotal() 34 | + ", count=" 35 | + getCount() 36 | + ", characters=" 37 | + getComics().toString() 38 | + '}'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/CreatorResourceDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | import com.google.gson.annotations.SerializedName; 19 | 20 | public class CreatorResourceDto extends MarvelResourceDto { 21 | @SerializedName("role") private String role; 22 | 23 | public String getRole() { 24 | return role; 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/EventResourceDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | public class EventResourceDto extends MarvelResourceDto { 19 | } 20 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/Format.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | public enum Format { 19 | COMIC("comic"), 20 | MAGAZINE("magazine"), 21 | TRADE_PAPERBACK("trade paperback"), 22 | HARDCOVER("hardcover"), 23 | DIGEST("digest"), 24 | GRAPHIC_NOVEL("graphic novel"), 25 | DIGITAL_COMIC("digital comic"), 26 | INFINITE_COMIC("infinite comic"); 27 | 28 | private final String format; 29 | 30 | private Format(final String format) { 31 | this.format = format; 32 | } 33 | 34 | @Override public String toString() { 35 | return format; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/MarvelCollection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | import com.google.gson.annotations.SerializedName; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | public class MarvelCollection { 23 | @SerializedName("offset") private int offset; 24 | @SerializedName("limit") private int limit; 25 | @SerializedName("total") private int total; 26 | @SerializedName("count") private int count; 27 | @SerializedName("results") private List results = new ArrayList<>(); 28 | 29 | public int getOffset() { 30 | return offset; 31 | } 32 | 33 | public int getLimit() { 34 | return limit; 35 | } 36 | 37 | public int getTotal() { 38 | return total; 39 | } 40 | 41 | public int getCount() { 42 | return count; 43 | } 44 | 45 | protected List getResults() { 46 | return results; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/MarvelDate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | import com.google.gson.annotations.SerializedName; 19 | 20 | public class MarvelDate { 21 | @SerializedName("type") private String type; 22 | @SerializedName("date") private String date; 23 | 24 | public String getType() { 25 | return type; 26 | } 27 | 28 | public String getDate() { 29 | return date; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/MarvelImage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | import com.google.gson.annotations.SerializedName; 19 | 20 | public class MarvelImage { 21 | private static final String SEPARATOR = "/"; 22 | private static final String DOT = "."; 23 | @SerializedName("path") private String path; 24 | @SerializedName("extension") private String extension; 25 | 26 | public String getPath() { 27 | return path; 28 | } 29 | 30 | public String getExtension() { 31 | return extension; 32 | } 33 | 34 | public String getImageUrl(Size size) { 35 | if (size == Size.FULLSIZE) { 36 | return path + DOT + extension; 37 | } else { 38 | return path + SEPARATOR + size.toString() + DOT + extension; 39 | } 40 | } 41 | 42 | @Override public String toString() { 43 | return "MarvelImage{" + "path='" + path + '\'' + ", extension='" + extension + '\'' + '}'; 44 | } 45 | 46 | public enum Size { 47 | /** 50x75px */ 48 | PORTRAIT_SMALL("portrait_small"), 49 | /** 100x150px */ 50 | PORTRAIT_MEDIUM("portrait_medium"), 51 | /** 150x225px */ 52 | PORTRAIT_XLARGE("portrait_xlarge"), 53 | /** 168x252px */ 54 | PORTRAIT_FANTASTIC("portrait_fantastic"), 55 | /** 300x450px */ 56 | PORTRAIT_UNCANNY("portrait_uncanny"), 57 | /** 216x324px */ 58 | PORTRAIT_INCREDIBLE("portrait_incredible"), 59 | /** 65x45px */ 60 | STANDARD_SMALL("standard_small"), 61 | /** 100x100px */ 62 | STANDARD_MEDIUM("standard_medium"), 63 | /** 140x140px */ 64 | STANDARD_LARGE("standard_large"), 65 | /** 200x200px */ 66 | STANDARD_XLARGE("standard_xlarge"), 67 | /** 250x250px */ 68 | STANDARD_FANTASTIC("standard_fantastic"), 69 | /** 180x180px */ 70 | STANDARD_AMAZING("standard_amazing"), 71 | /** 120x90px */ 72 | LANDSCAPE_SMALL("landscape_small"), 73 | /** 175x130px */ 74 | LANDSCAPE_MEDIUM("landscape_medium"), 75 | /** 190x140px */ 76 | LANDSCAPE_LARGE("landscape_large"), 77 | /** 270x200px */ 78 | LANDSCAPE_XLARGE("landscape_xlarge"), 79 | /** 250x156px */ 80 | LANDSCAPE_AMAZING("landscape_amazing"), 81 | /** 464x261px */ 82 | LANDSCAPE_INCREDIBLE("landscape_incredible"), 83 | DETAIL("detail"), 84 | FULLSIZE("fullsize"); 85 | 86 | private final String size; 87 | 88 | private Size(final String size) { 89 | this.size = size; 90 | } 91 | 92 | @Override public String toString() { 93 | return size; 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/MarvelPrice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | import com.google.gson.annotations.SerializedName; 19 | 20 | public class MarvelPrice { 21 | @SerializedName("type") private String type; 22 | @SerializedName("price") private float price; 23 | 24 | public String getType() { 25 | return type; 26 | } 27 | 28 | public float getPrice() { 29 | return price; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/MarvelResourceDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | import com.google.gson.annotations.SerializedName; 19 | 20 | public class MarvelResourceDto { 21 | @SerializedName("resourceURI") private String resourceUri; 22 | @SerializedName("name") private String name; 23 | 24 | public String getResourceUri() { 25 | return resourceUri; 26 | } 27 | 28 | public String getName() { 29 | return name; 30 | } 31 | 32 | @Override public String toString() { 33 | return "MarvelResourceDto{" 34 | + "resourceUri='" 35 | + resourceUri 36 | + '\'' 37 | + ", name='" 38 | + name 39 | + '\'' 40 | + '}'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/MarvelResources.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | import com.google.gson.annotations.SerializedName; 19 | import java.util.List; 20 | 21 | public class MarvelResources { 22 | @SerializedName("available") private int available; 23 | @SerializedName("returned") private int returned; 24 | @SerializedName("collectionURI") private String collectionUri; 25 | @SerializedName("items") private List items; 26 | 27 | public int getAvailable() { 28 | return available; 29 | } 30 | 31 | public int getReturned() { 32 | return returned; 33 | } 34 | 35 | public String getCollectionUri() { 36 | return collectionUri; 37 | } 38 | 39 | public List getItems() { 40 | return items; 41 | } 42 | 43 | @Override public String toString() { 44 | return "MarvelResources{" 45 | + "available=" 46 | + available 47 | + ", returned=" 48 | + returned 49 | + ", collectionUri='" 50 | + collectionUri 51 | + '\'' 52 | + ", items=" 53 | + items 54 | + 55 | '}'; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/MarvelResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | import com.google.gson.annotations.SerializedName; 19 | 20 | public class MarvelResponse { 21 | @SerializedName("code") private int code; 22 | @SerializedName("status") private String status; 23 | @SerializedName("copyright") private String copyright; 24 | @SerializedName("attributionText") private String attributionText; 25 | @SerializedName("attributionHTML") private String getAttributionHtml; 26 | @SerializedName("etag") private String etag; 27 | 28 | @SerializedName("data") private T response; 29 | 30 | public MarvelResponse() { 31 | } 32 | 33 | public MarvelResponse(MarvelResponse marvelResponse) { 34 | code = marvelResponse.getCode(); 35 | status = marvelResponse.getStatus(); 36 | copyright = marvelResponse.getCopyright(); 37 | attributionText = marvelResponse.getAttributionText(); 38 | getAttributionHtml = marvelResponse.getGetAttributionHtml(); 39 | etag = marvelResponse.getEtag(); 40 | } 41 | 42 | public int getCode() { 43 | return code; 44 | } 45 | 46 | public String getStatus() { 47 | return status; 48 | } 49 | 50 | public String getCopyright() { 51 | return copyright; 52 | } 53 | 54 | public String getAttributionText() { 55 | return attributionText; 56 | } 57 | 58 | public String getGetAttributionHtml() { 59 | return getAttributionHtml; 60 | } 61 | 62 | public T getResponse() { 63 | return response; 64 | } 65 | 66 | public String getEtag() { 67 | return etag; 68 | } 69 | 70 | @Override public String toString() { 71 | return "MarvelResponse{" 72 | + "code=" 73 | + code 74 | + ", status='" 75 | + status 76 | + '\'' 77 | + ", copyright='" 78 | + copyright 79 | + '\'' 80 | + ", attributionText='" 81 | + attributionText 82 | + '\'' 83 | + ", getAttributionHtml='" 84 | + getAttributionHtml 85 | + '\'' 86 | + ", etag='" 87 | + etag 88 | + '\'' 89 | + ", response=" 90 | + response 91 | + '}'; 92 | } 93 | 94 | public void setResponse(T response) { 95 | this.response = response; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/MarvelUrl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | import com.google.gson.annotations.SerializedName; 19 | 20 | public class MarvelUrl { 21 | @SerializedName("type") private String type; 22 | @SerializedName("url") private String url; 23 | 24 | public String getType() { 25 | return type; 26 | } 27 | 28 | public String getUrl() { 29 | return url; 30 | } 31 | 32 | @Override public String toString() { 33 | return "MarvelUrl{" + "type='" + type + '\'' + ", url='" + url + '\'' + '}'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/OrderBy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | public enum OrderBy { 19 | NAME("name"), 20 | MODIFIED("modified"); 21 | 22 | private final String orderBy; 23 | 24 | private OrderBy(final String orderBy) { 25 | this.orderBy = orderBy; 26 | } 27 | 28 | @Override public String toString() { 29 | return orderBy; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/SerieResourceDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | public class SerieResourceDto extends MarvelResourceDto { 19 | } 20 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/SeriesCollectionDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | import java.util.List; 19 | 20 | public class SeriesCollectionDto extends MarvelCollection { 21 | 22 | public List getSeries() { 23 | return getResults(); 24 | } 25 | 26 | @Override public String toString() { 27 | return "CharactersDto{" 28 | + "offset=" 29 | + getOffset() 30 | + ", limit=" 31 | + getLimit() 32 | + ", total=" 33 | + getTotal() 34 | + ", count=" 35 | + getCount() 36 | + ", characters=" 37 | + getSeries().toString() 38 | + '}'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/SeriesDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | import com.google.gson.annotations.SerializedName; 19 | import java.util.List; 20 | 21 | public class SeriesDto { 22 | @SerializedName("id") private String id; 23 | @SerializedName("title") private String title; 24 | @SerializedName("description") private String description; 25 | @SerializedName("resourceURI") private String resourceURI; 26 | @SerializedName("urls") private List urls; 27 | @SerializedName("startYear") private int startYear; 28 | @SerializedName("endYear") private int endYear; 29 | @SerializedName("rating") private String rating; 30 | @SerializedName("modified") private String modified; 31 | @SerializedName("thumbnail") private MarvelImage thumbnail; 32 | @SerializedName("comics") private MarvelResources comics; 33 | @SerializedName("stories") private MarvelResources stories; 34 | @SerializedName("events") private MarvelResources events; 35 | @SerializedName("characters") private MarvelResources characters; 36 | @SerializedName("creators") private MarvelResources creators; 37 | @SerializedName("next") private MarvelResourceDto next; 38 | @SerializedName("previous") private MarvelResourceDto previous; 39 | 40 | public String getId() { 41 | return id; 42 | } 43 | 44 | public String getTitle() { 45 | return title; 46 | } 47 | 48 | public String getDescription() { 49 | return description; 50 | } 51 | 52 | public String getResourceURI() { 53 | return resourceURI; 54 | } 55 | 56 | public List getUrls() { 57 | return urls; 58 | } 59 | 60 | public int getStartYear() { 61 | return startYear; 62 | } 63 | 64 | public int getEndYear() { 65 | return endYear; 66 | } 67 | 68 | public String getRating() { 69 | return rating; 70 | } 71 | 72 | public String getModified() { 73 | return modified; 74 | } 75 | 76 | public MarvelImage getThumbnail() { 77 | return thumbnail; 78 | } 79 | 80 | public MarvelResources getComics() { 81 | return comics; 82 | } 83 | 84 | public MarvelResources getStories() { 85 | return stories; 86 | } 87 | 88 | public MarvelResources getEvents() { 89 | return events; 90 | } 91 | 92 | public MarvelResources getCharacters() { 93 | return characters; 94 | } 95 | 96 | public MarvelResources getCreators() { 97 | return creators; 98 | } 99 | 100 | public MarvelResourceDto getNext() { 101 | return next; 102 | } 103 | 104 | public MarvelResourceDto getPrevious() { 105 | return previous; 106 | } 107 | 108 | @Override public String toString() { 109 | return "SeriesDto{" + 110 | "id='" + id + '\'' + 111 | ", title='" + title + '\'' + 112 | ", description='" + description + '\'' + 113 | ", resourceURI='" + resourceURI + '\'' + 114 | ", urls=" + urls + 115 | ", startYear=" + startYear + 116 | ", endYear=" + endYear + 117 | ", rating='" + rating + '\'' + 118 | ", modified='" + modified + '\'' + 119 | ", thumbnail=" + thumbnail + 120 | ", comics=" + comics + 121 | ", stories=" + stories + 122 | ", events=" + events + 123 | ", characters=" + characters + 124 | ", creators=" + creators + 125 | ", next=" + next + 126 | ", previous=" + previous + 127 | '}'; 128 | } 129 | } -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/SeriesQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | import com.karumi.marvelapiclient.utils.DateUtil; 19 | import java.util.ArrayList; 20 | import java.util.Date; 21 | import java.util.HashMap; 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | public class SeriesQuery { 26 | private static final String QUERY_TITLE = "title"; 27 | private static final String QUERY_TITLE_STARTS_WITH = "titleStartsWith"; 28 | private static final String QUERY_START_YEAR = "startYear"; 29 | private static final String QUERY_MODIFIED_SINCE = "modifiedSince"; 30 | private static final String QUERY_CREATORS = "creators"; 31 | private static final String QUERY_CHARACTERS = "characters"; 32 | private static final String QUERY_COMICS = "comics"; 33 | private static final String QUERY_EVENTS = "events"; 34 | private static final String QUERY_STORIES = "stories"; 35 | private static final String QUERY_ORDER_BY = "orderBy"; 36 | private static final String QUERY_LIMIT = "limit"; 37 | private static final String QUERY_OFFSET = "offset"; 38 | private static final String QUERY_SERIES_TYPE = "seriesType"; 39 | private static final String QUERY_CONTAINS = "contains"; 40 | 41 | private String title; 42 | private String titleStartsWith; 43 | private int startYear; 44 | private String modifiedSince; 45 | private String comics; 46 | private String stories; 47 | private String events; 48 | private String creators; 49 | private String characters; 50 | private String orderBy; 51 | private String seriesType; 52 | private String contains; 53 | private int limit; 54 | private int offset; 55 | 56 | public SeriesQuery(String title, String titleStartsWith, int startYear, String modifiedSince, 57 | String comics, String stories, String events, String creators, String characters, 58 | String orderBy, String seriesType, String contains, int limit, int offset) { 59 | this.title = title; 60 | this.titleStartsWith = titleStartsWith; 61 | this.startYear = startYear; 62 | this.modifiedSince = modifiedSince; 63 | this.comics = comics; 64 | this.stories = stories; 65 | this.events = events; 66 | this.creators = creators; 67 | this.characters = characters; 68 | this.orderBy = orderBy; 69 | this.seriesType = seriesType; 70 | this.contains = contains; 71 | this.limit = limit; 72 | this.offset = offset; 73 | } 74 | 75 | public Map toMap() { 76 | Map returnValues = new HashMap<>(); 77 | 78 | if (title != null) { 79 | returnValues.put(QUERY_TITLE, title); 80 | } 81 | if (titleStartsWith != null) { 82 | returnValues.put(QUERY_TITLE_STARTS_WITH, titleStartsWith); 83 | } 84 | 85 | if (startYear > 0) { 86 | returnValues.put(QUERY_START_YEAR, startYear); 87 | } 88 | 89 | if (modifiedSince != null) { 90 | returnValues.put(QUERY_MODIFIED_SINCE, modifiedSince); 91 | } 92 | 93 | if (creators != null) { 94 | returnValues.put(QUERY_CREATORS, creators); 95 | } 96 | 97 | if (characters != null) { 98 | returnValues.put(QUERY_CHARACTERS, characters); 99 | } 100 | 101 | if (comics != null) { 102 | returnValues.put(QUERY_COMICS, comics); 103 | } 104 | 105 | if (events != null) { 106 | returnValues.put(QUERY_EVENTS, events); 107 | } 108 | 109 | if (stories != null) { 110 | returnValues.put(QUERY_STORIES, stories); 111 | } 112 | 113 | if (seriesType != null) { 114 | returnValues.put(QUERY_SERIES_TYPE, seriesType); 115 | } 116 | 117 | if (contains != null) { 118 | returnValues.put(QUERY_CONTAINS, contains); 119 | } 120 | 121 | if (orderBy != null) { 122 | returnValues.put(QUERY_ORDER_BY, orderBy); 123 | } 124 | 125 | if (limit > 0) { 126 | returnValues.put(QUERY_LIMIT, limit); 127 | } 128 | 129 | if (offset > 0) { 130 | returnValues.put(QUERY_OFFSET, offset); 131 | } 132 | 133 | return returnValues; 134 | } 135 | 136 | public enum SeriesType { 137 | COLLECTION("collection"), 138 | ONE_SHOT("oneShot"), 139 | LIMITED("limited"), 140 | ONGOING("ongoing"); 141 | 142 | private final String seriesType; 143 | 144 | private SeriesType(final String seriesType) { 145 | this.seriesType = seriesType; 146 | } 147 | 148 | @Override public String toString() { 149 | return seriesType; 150 | } 151 | } 152 | 153 | public static class Builder { 154 | private static final String LIST_SEPARATOR = ","; 155 | public final static int MAX_SIZE = 100; 156 | 157 | private String title; 158 | private String titleStartsWith; 159 | private int startYear; 160 | private Date modifiedSince; 161 | private List creators = new ArrayList<>(); 162 | private List characters = new ArrayList<>(); 163 | private List comics = new ArrayList<>(); 164 | private List events = new ArrayList<>(); 165 | private List stories = new ArrayList<>(); 166 | private Format contains; 167 | private SeriesType seriesType; 168 | private OrderBy orderBy; 169 | private int limit; 170 | private int offset; 171 | private boolean orderByAscendant; 172 | 173 | private Builder() { 174 | } 175 | 176 | public static Builder create() { 177 | return new Builder(); 178 | } 179 | 180 | public Builder withTitle(String title) { 181 | this.title = title; 182 | return this; 183 | } 184 | 185 | public Builder withTitleStartsWith(String titleStartsWith) { 186 | this.titleStartsWith = titleStartsWith; 187 | return this; 188 | } 189 | 190 | public Builder withStartYear(int year) { 191 | this.startYear = year; 192 | return this; 193 | } 194 | 195 | public Builder withModifiedSince(Date modifiedSince) { 196 | this.modifiedSince = modifiedSince; 197 | return this; 198 | } 199 | 200 | public Builder addCreator(int creatorId) { 201 | creators.add(creatorId); 202 | return this; 203 | } 204 | 205 | public Builder addCreator(List creatorIds) { 206 | checkNotNull(creatorIds); 207 | creators.addAll(creatorIds); 208 | return this; 209 | } 210 | 211 | public Builder addCharacter(int characterId) { 212 | characters.add(characterId); 213 | return this; 214 | } 215 | 216 | public Builder addCharacter(List characterIds) { 217 | checkNotNull(characterIds); 218 | characters.addAll(characterIds); 219 | return this; 220 | } 221 | 222 | public Builder addComic(int comicId) { 223 | comics.add(comicId); 224 | return this; 225 | } 226 | 227 | public Builder addComic(List comicIds) { 228 | checkNotNull(comicIds); 229 | comics.addAll(comicIds); 230 | return this; 231 | } 232 | 233 | public Builder addEvent(int eventId) { 234 | events.add(eventId); 235 | return this; 236 | } 237 | 238 | public Builder addEvent(List eventIds) { 239 | checkNotNull(eventIds); 240 | events.addAll(eventIds); 241 | return this; 242 | } 243 | 244 | public Builder addStory(int storyId) { 245 | stories.add(storyId); 246 | return this; 247 | } 248 | 249 | public Builder addStory(List storyIds) { 250 | checkNotNull(storyIds); 251 | stories.addAll(storyIds); 252 | return this; 253 | } 254 | 255 | public Builder withOrderBy(OrderBy orderBy, boolean ascendant) { 256 | this.orderBy = orderBy; 257 | this.orderByAscendant = ascendant; 258 | return this; 259 | } 260 | 261 | public Builder withSeriesType(SeriesType seriesType) { 262 | this.seriesType = seriesType; 263 | return this; 264 | } 265 | 266 | public Builder withContains(Format format) { 267 | this.contains = format; 268 | return this; 269 | } 270 | 271 | public Builder withOrderBy(OrderBy orderBy) { 272 | return withOrderBy(orderBy, true); 273 | } 274 | 275 | public Builder withLimit(int limit) { 276 | checkLimit(limit); 277 | this.limit = limit; 278 | return this; 279 | } 280 | 281 | public Builder withOffset(int offset) { 282 | this.offset = offset; 283 | return this; 284 | } 285 | 286 | public SeriesQuery build() { 287 | String modifiedSinceAsString = convertDate(modifiedSince); 288 | String creatorsAsString = convertToList(creators); 289 | String charactersAsString = convertToList(characters); 290 | String comicsAsString = convertToList(comics); 291 | String eventsAsString = convertToList(events); 292 | String storiesAsString = convertToList(stories); 293 | String orderByAsString = convertOrderBy(orderBy, orderByAscendant); 294 | String containsAsString = (contains != null) ? contains.toString() : null; 295 | String seriesTypeAsString = (seriesType != null) ? seriesType.toString() : null; 296 | 297 | return new SeriesQuery(title, titleStartsWith, startYear, modifiedSinceAsString, 298 | comicsAsString, storiesAsString, eventsAsString, creatorsAsString, charactersAsString, 299 | orderByAsString, seriesTypeAsString, containsAsString, limit, offset); 300 | } 301 | 302 | private void checkLimit(int limit) { 303 | if (limit <= 0) { 304 | throw new IllegalArgumentException("limit must be bigger than zero"); 305 | } 306 | 307 | if (limit > MAX_SIZE) { 308 | throw new IllegalArgumentException("limit must be smaller than 100"); 309 | } 310 | } 311 | 312 | private void checkNotNull(Object object) { 313 | if (object == null) { 314 | throw new IllegalArgumentException("the argument can not be null"); 315 | } 316 | } 317 | 318 | private String convertDate(Date date) { 319 | if (date == null) { 320 | return null; 321 | } 322 | return DateUtil.parseDate(date); 323 | } 324 | 325 | private String convertOrderBy(OrderBy orderBy, boolean ascendant) { 326 | if (orderBy == null) { 327 | return null; 328 | } 329 | 330 | String plainOrderBy = orderBy.toString(); 331 | return (ascendant) ? plainOrderBy : "-" + plainOrderBy; 332 | } 333 | 334 | private String convertToList(List list) { 335 | String plainList = ""; 336 | for (int i = 0; i < list.size(); i++) { 337 | plainList += Integer.toString(list.get(i)); 338 | if (i < list.size() - 1) { 339 | plainList += LIST_SEPARATOR; 340 | } 341 | } 342 | return (plainList.isEmpty()) ? null : plainList; 343 | } 344 | } 345 | } 346 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/StoryResourceDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | import com.google.gson.annotations.SerializedName; 19 | 20 | public class StoryResourceDto extends MarvelResourceDto { 21 | @SerializedName("type") private String type; 22 | 23 | public String getType() { 24 | return type; 25 | } 26 | 27 | @Override public String toString() { 28 | return "StoryResourceDto{" 29 | + "name=" 30 | + super.getName() 31 | + "resourceUri=" 32 | + super.getResourceUri() 33 | + "type='" 34 | + type 35 | + '\'' 36 | + 37 | '}'; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/model/TextObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | import com.google.gson.annotations.SerializedName; 19 | 20 | public class TextObject { 21 | @SerializedName("type") private String type; 22 | @SerializedName("language") private String language; 23 | @SerializedName("text") private String text; 24 | 25 | public String getType() { 26 | return type; 27 | } 28 | 29 | public String getLanguage() { 30 | return language; 31 | } 32 | 33 | public String getText() { 34 | return text; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /MarvelApiClient/src/main/java/com/karumi/marvelapiclient/utils/DateUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.utils; 17 | 18 | import java.text.SimpleDateFormat; 19 | import java.util.Date; 20 | 21 | public class DateUtil { 22 | 23 | private static final String DATE_PATTERN = "yyyy-MM-dd'T'HH:mm:ssZ"; 24 | 25 | public static String parseDate(Date date) { 26 | SimpleDateFormat format = new SimpleDateFormat(DATE_PATTERN); 27 | return format.format(date); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /MarvelApiClient/src/test/java/com/karumi/marvelapiclient/ApiClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient; 17 | 18 | import com.karumi.marvelapiclient.extensions.FileExtensions; 19 | import com.karumi.marvelapiclient.model.MarvelResponse; 20 | import com.squareup.okhttp.mockwebserver.MockResponse; 21 | import com.squareup.okhttp.mockwebserver.MockWebServer; 22 | import com.squareup.okhttp.mockwebserver.RecordedRequest; 23 | import java.io.IOException; 24 | import org.hamcrest.core.StringContains; 25 | import org.junit.After; 26 | import org.junit.Assert; 27 | import org.junit.Before; 28 | import org.mockito.MockitoAnnotations; 29 | 30 | import static org.junit.Assert.assertEquals; 31 | 32 | public class ApiClientTest { 33 | protected static final String ANY_TIME_ZONE = "PST"; 34 | private static final int OK_CODE = 200; 35 | 36 | private MockWebServer server; 37 | 38 | @Before public void setUp() throws Exception { 39 | System.setProperty("user.timezone", ANY_TIME_ZONE); 40 | MockitoAnnotations.initMocks(this); 41 | this.server = new MockWebServer(); 42 | this.server.start(); 43 | } 44 | 45 | @After public void tearDown() throws Exception { 46 | server.shutdown(); 47 | } 48 | 49 | protected void enqueueMockResponse() throws IOException { 50 | enqueueMockResponse(OK_CODE); 51 | } 52 | 53 | protected void enqueueMockResponse(int code) throws IOException { 54 | enqueueMockResponse(code, "{}"); 55 | } 56 | 57 | protected void enqueueMockResponse(int code, String response) throws IOException { 58 | MockResponse mockResponse = new MockResponse(); 59 | mockResponse.setResponseCode(code); 60 | mockResponse.setBody(response); 61 | server.enqueue(mockResponse); 62 | } 63 | 64 | protected void enqueueMockResponse(String fileName) throws IOException { 65 | String body = FileExtensions.getStringFromFile(getClass(), fileName); 66 | MockResponse response = new MockResponse(); 67 | response.setResponseCode(OK_CODE); 68 | response.setBody(body); 69 | server.enqueue(response); 70 | } 71 | 72 | protected void assertRequestSentTo(String url) throws InterruptedException { 73 | RecordedRequest request = server.takeRequest(); 74 | assertEquals(url, request.getPath()); 75 | } 76 | 77 | protected void assertRequestSentToContains(String... paths) throws InterruptedException { 78 | RecordedRequest request = server.takeRequest(); 79 | 80 | for (String path : paths) { 81 | Assert.assertThat(request.getPath(), StringContains.containsString(path)); 82 | } 83 | } 84 | 85 | protected void assertBasicMarvelResponse(MarvelResponse marvelResponse) { 86 | assertEquals(200, marvelResponse.getCode()); 87 | assertEquals("Ok", marvelResponse.getStatus()); 88 | assertEquals("© 2015 MARVEL", marvelResponse.getCopyright()); 89 | assertEquals("Data provided by Marvel. © 2015 MARVEL", marvelResponse.getAttributionText()); 90 | assertEquals("Data provided by Marvel. © 2015 MARVEL", 91 | marvelResponse.getGetAttributionHtml()); 92 | assertEquals("55122b303dfbc9fdfd12c080eded740b83354269", marvelResponse.getEtag()); 93 | } 94 | 95 | protected String getBaseEndpoint() { 96 | return server.getUrl("/").toString(); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /MarvelApiClient/src/test/java/com/karumi/marvelapiclient/AuthHashGeneratorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient; 17 | 18 | import org.junit.Test; 19 | 20 | import static org.junit.Assert.assertEquals; 21 | 22 | public class AuthHashGeneratorTest { 23 | 24 | public static final String ANY_TIMESTAMP = "1"; 25 | public static final String ANY_PUBLIC_KEY = "1234"; 26 | public static final String ANY_PRIVATE_KEY = "abcd"; 27 | public static final String VALID_MD5 = "ffd275c5130566a2916217b101f26150"; 28 | 29 | @Test public void shouldProvideAValidMd5WhenGiveValidValues() throws Exception { 30 | AuthHashGenerator authHashGenerator = new AuthHashGenerator(); 31 | 32 | String md5 = authHashGenerator.generateHash(ANY_TIMESTAMP, ANY_PUBLIC_KEY, ANY_PRIVATE_KEY); 33 | 34 | assertEquals(VALID_MD5, md5); 35 | } 36 | } -------------------------------------------------------------------------------- /MarvelApiClient/src/test/java/com/karumi/marvelapiclient/CharacterApiClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient; 17 | 18 | import com.karumi.marvelapiclient.model.CharacterDto; 19 | import com.karumi.marvelapiclient.model.CharactersDto; 20 | import com.karumi.marvelapiclient.model.CharactersQuery; 21 | import com.karumi.marvelapiclient.model.ComicResourceDto; 22 | import com.karumi.marvelapiclient.model.MarvelImage; 23 | import com.karumi.marvelapiclient.model.MarvelResources; 24 | import com.karumi.marvelapiclient.model.MarvelResponse; 25 | import com.karumi.marvelapiclient.model.MarvelUrl; 26 | import com.karumi.marvelapiclient.model.OrderBy; 27 | import com.karumi.marvelapiclient.model.StoryResourceDto; 28 | import java.util.ArrayList; 29 | import java.util.Calendar; 30 | import java.util.Date; 31 | import java.util.List; 32 | import java.util.TimeZone; 33 | import org.junit.Test; 34 | import retrofit2.Retrofit; 35 | import retrofit2.converter.gson.GsonConverterFactory; 36 | 37 | import static org.junit.Assert.assertEquals; 38 | 39 | public class CharacterApiClientTest extends ApiClientTest { 40 | 41 | private static final String ANY_PUBLIC_KEY = "1234"; 42 | private static final String ANY_PRIVATE_KEY = "abcd"; 43 | private static final String ANY_URL = "http://fake.marvel.com/"; 44 | private static final int ANY_OFFSET = 1; 45 | private static final int ANY_LIMIT = 10; 46 | private static final int INVALID_LIMIT = 0; 47 | private static final String ANY_NAME = "Spider-man"; 48 | private static final String ANY_START_NAME = "Spider"; 49 | private static final int ANY_COMIC_1 = 1; 50 | private static final int ANY_COMIC_2 = 2; 51 | private static final int ANY_SERIE = 1; 52 | private static final int ANY_STORY = 1; 53 | private static final int ANY_EVENT_1 = 1; 54 | private static final int ANY_EVENT_2 = 2; 55 | private static final String ANY_MODIFIED_SINCE = "2015-01-09T22:10:45-0800"; 56 | private static final String ORDER_NAME_DESCEDANT_VALUE = "-name"; 57 | private static final String INVALID_CHARACTER_ID = ""; 58 | private static final String ANY_NOT_FOUND_ID = "1234"; 59 | private static final String THREED_MAN_CHARACTER_ID = "123456"; 60 | public static final String COMICS_REQUEST = "1,2"; 61 | public static final String EVENTS_REQUEST = "1,2"; 62 | 63 | @Test public void shouldRequestCharactersByOffsetAndLimitWithAsParams() throws Exception { 64 | CharacterApiClient characterApiClient = givenCharacterApiClient(); 65 | enqueueMockResponse(); 66 | 67 | characterApiClient.getAll(ANY_OFFSET, ANY_LIMIT); 68 | 69 | assertRequestSentToContains("offset=" + ANY_OFFSET, "limit=" + ANY_LIMIT); 70 | } 71 | 72 | @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionWhenLimitIsZero() 73 | throws Exception { 74 | CharacterApiClient characterApiClient = givenCharacterApiClient(); 75 | enqueueMockResponse(); 76 | 77 | characterApiClient.getAll(ANY_OFFSET, INVALID_LIMIT); 78 | } 79 | 80 | @Test public void shouldRequestCharactersUsingAllTheRequestParams() throws Exception { 81 | CharacterApiClient characterApiClient = givenCharacterApiClient(); 82 | enqueueMockResponse(); 83 | 84 | CharactersQuery query = CharactersQuery.Builder.create() 85 | .withName(ANY_NAME) 86 | .withNameStartWith(ANY_START_NAME) 87 | .withLimit(ANY_LIMIT) 88 | .withOffset(ANY_OFFSET) 89 | .withModifiedSince(getAnyDate()) 90 | .withOrderBy(OrderBy.NAME, false) 91 | .addComic(ANY_COMIC_1) 92 | .addComic(ANY_COMIC_2) 93 | .addEvents(getAnyEvents()) 94 | .addSerie(ANY_SERIE) 95 | .addStory(ANY_STORY) 96 | .build(); 97 | characterApiClient.getAll(query); 98 | 99 | assertRequestSentToContains("offset=" + ANY_OFFSET, "limit=" + ANY_LIMIT, "name=" + ANY_NAME, 100 | "nameStartsWith=" + ANY_START_NAME, "modifiedSince=" + ANY_MODIFIED_SINCE, 101 | "orderBy=" + ORDER_NAME_DESCEDANT_VALUE, "comics=" + COMICS_REQUEST, 102 | "events=" + EVENTS_REQUEST, "series=" + ANY_SERIE, "stories=" + ANY_STORY); 103 | } 104 | 105 | @Test(expected = MarvelAuthApiException.class) 106 | public void shouldThrowMarvelApiExceptionOnAuthHttpError() throws Exception { 107 | CharacterApiClient characterApiClient = givenCharacterApiClient(); 108 | enqueueMockResponse(401, 109 | "{\"code\":\"InvalidCredentials\",\"message\":\"That hash, timestamp and key " 110 | + "combination is invalid.\"}"); 111 | 112 | try { 113 | characterApiClient.getAll(ANY_OFFSET, ANY_LIMIT); 114 | } catch (MarvelApiException e) { 115 | assertEquals("InvalidCredentials", e.getMarvelCode()); 116 | assertEquals("That hash, timestamp and key combination is invalid.", e.getMessage()); 117 | throw e; 118 | } 119 | } 120 | 121 | @Test public void shouldParseGetAllCharactersResponse() throws Exception { 122 | CharacterApiClient characterApiClient = givenCharacterApiClient(); 123 | enqueueMockResponse("getCharacters.json"); 124 | 125 | MarvelResponse characters = characterApiClient.getAll(0, ANY_LIMIT); 126 | 127 | assertBasicMarvelResponse(characters); 128 | assertGetAllCharactersResponseIsProperlyParsed(characters); 129 | } 130 | 131 | @Test(expected = IllegalArgumentException.class) public void shouldNotAcceptEmptyCharacterIds() 132 | throws Exception { 133 | CharacterApiClient characterApiClient = givenCharacterApiClient(); 134 | 135 | characterApiClient.getCharacter(INVALID_CHARACTER_ID); 136 | } 137 | 138 | @Test public void shouldSendGetCharacterRequestToTheCorrectEndpoint() throws Exception { 139 | CharacterApiClient characterApiClient = givenCharacterApiClient(); 140 | enqueueMockResponse("getCharacter.json"); 141 | 142 | characterApiClient.getCharacter(THREED_MAN_CHARACTER_ID); 143 | 144 | assertRequestSentToContains("characters/" + THREED_MAN_CHARACTER_ID); 145 | } 146 | 147 | @Test(expected = MarvelApiException.class) 148 | public void shouldReturnMarvelExceptionWhenTheIdDoesNotExist() throws Exception { 149 | CharacterApiClient characterApiClient = givenCharacterApiClient(); 150 | enqueueMockResponse(404, "{\"code\":404,\"status\":\"We couldn't find that character\"}"); 151 | 152 | try { 153 | characterApiClient.getCharacter(ANY_NOT_FOUND_ID); 154 | } catch (MarvelApiException e) { 155 | assertEquals("404", e.getMarvelCode()); 156 | assertEquals("We couldn't find that character", e.getMessage()); 157 | throw e; 158 | } 159 | } 160 | 161 | @Test public void shouldParseGetCharacterResponse() throws Exception { 162 | CharacterApiClient characterApiClient = givenCharacterApiClient(); 163 | enqueueMockResponse("getCharacter.json"); 164 | 165 | MarvelResponse character = 166 | characterApiClient.getCharacter(THREED_MAN_CHARACTER_ID); 167 | 168 | assertBasicMarvelResponse(character); 169 | 170 | CharacterDto response = character.getResponse(); 171 | assertIs3dManCharacter(response); 172 | } 173 | 174 | private List getAnyEvents() { 175 | List events = new ArrayList<>(); 176 | events.add(ANY_EVENT_1); 177 | events.add(ANY_EVENT_2); 178 | return events; 179 | } 180 | 181 | private CharacterApiClient givenCharacterApiClient() { 182 | Retrofit retrofit = new Retrofit.Builder().baseUrl(getBaseEndpoint()) 183 | .addConverterFactory(GsonConverterFactory.create()) 184 | .build(); 185 | 186 | MarvelApiConfig marvelApiConfig = 187 | new MarvelApiConfig.Builder(ANY_PUBLIC_KEY, ANY_PRIVATE_KEY).baseUrl(ANY_URL) 188 | .retrofit(retrofit) 189 | .build(); 190 | return new CharacterApiClient(marvelApiConfig); 191 | } 192 | 193 | private void assertGetAllCharactersResponseIsProperlyParsed( 194 | MarvelResponse characters) { 195 | CharactersDto charactersDto = characters.getResponse(); 196 | assertEquals(10, charactersDto.getCount()); 197 | assertEquals(10, charactersDto.getLimit()); 198 | assertEquals(0, charactersDto.getOffset()); 199 | assertEquals(1485, charactersDto.getTotal()); 200 | 201 | CharacterDto firstCharacter = charactersDto.getCharacters().get(0); 202 | assertIs3dManCharacter(firstCharacter); 203 | } 204 | 205 | private void assertIs3dManCharacter(CharacterDto character) { 206 | assertEquals("1011334", character.getId()); 207 | assertEquals("3-D Man", character.getName()); 208 | assertEquals("3-D man is a 3d superhero", character.getDescription()); 209 | assertEquals("2014-04-29T14:18:17-0400", character.getModified()); 210 | assertEquals("http://gateway.marvel.com/v1/public/characters/1011334", 211 | character.getResourceUri()); 212 | 213 | MarvelImage thumbnail = character.getThumbnail(); 214 | assertEquals("http://i.annihil.us/u/prod/marvel/i/mg/c/e0/535fecbbb9784", thumbnail.getPath()); 215 | assertEquals("jpg", thumbnail.getExtension()); 216 | 217 | List urls = character.getUrls(); 218 | assertEquals(3, urls.size()); 219 | MarvelUrl marvelUrl = urls.get(0); 220 | assertEquals("detail", marvelUrl.getType()); 221 | assertEquals("http://marvel.com/characters/74/3-d_man?utm_campaign=apiRef&utm_source=" 222 | + "838a08a2f4c39fa3fd218b1b2d43f19a", marvelUrl.getUrl()); 223 | 224 | MarvelResources comics = character.getComics(); 225 | assertEquals(11, comics.getAvailable()); 226 | assertEquals(11, comics.getReturned()); 227 | assertEquals("http://gateway.marvel.com/v1/public/characters/1011334/comics", 228 | comics.getCollectionUri()); 229 | assertEquals(11, comics.getItems().size()); 230 | ComicResourceDto firstComic = comics.getItems().get(0); 231 | assertEquals("Avengers: The Initiative (2007) #14", firstComic.getName()); 232 | assertEquals("http://gateway.marvel.com/v1/public/comics/21366", firstComic.getResourceUri()); 233 | 234 | MarvelResources stories = character.getStories(); 235 | assertEquals(17, stories.getAvailable()); 236 | assertEquals(17, stories.getReturned()); 237 | assertEquals("http://gateway.marvel.com/v1/public/characters/1011334/stories", 238 | stories.getCollectionUri()); 239 | assertEquals(17, stories.getItems().size()); 240 | StoryResourceDto firstStory = stories.getItems().get(0); 241 | assertEquals("Cover #19947", firstStory.getName()); 242 | assertEquals("http://gateway.marvel.com/v1/public/stories/19947", firstStory.getResourceUri()); 243 | assertEquals("cover", firstStory.getType()); 244 | } 245 | 246 | public Date getAnyDate() { 247 | Calendar instance = Calendar.getInstance(); 248 | instance.setTimeZone(TimeZone.getTimeZone(ANY_TIME_ZONE)); 249 | instance.set(Calendar.YEAR, 2015); 250 | instance.set(Calendar.MONTH, Calendar.JANUARY); 251 | instance.set(Calendar.DAY_OF_MONTH, 9); 252 | instance.set(Calendar.HOUR_OF_DAY, 22); 253 | instance.set(Calendar.MINUTE, 10); 254 | instance.set(Calendar.SECOND, 45); 255 | return instance.getTime(); 256 | } 257 | } 258 | -------------------------------------------------------------------------------- /MarvelApiClient/src/test/java/com/karumi/marvelapiclient/ComicApiClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient; 17 | 18 | import com.karumi.marvelapiclient.model.CharacterResourceDto; 19 | import com.karumi.marvelapiclient.model.ComicDto; 20 | import com.karumi.marvelapiclient.model.ComicResourceDto; 21 | import com.karumi.marvelapiclient.model.ComicsDto; 22 | import com.karumi.marvelapiclient.model.ComicsQuery; 23 | import com.karumi.marvelapiclient.model.CreatorResourceDto; 24 | import com.karumi.marvelapiclient.model.EventResourceDto; 25 | import com.karumi.marvelapiclient.model.Format; 26 | import com.karumi.marvelapiclient.model.MarvelDate; 27 | import com.karumi.marvelapiclient.model.MarvelImage; 28 | import com.karumi.marvelapiclient.model.MarvelPrice; 29 | import com.karumi.marvelapiclient.model.MarvelResources; 30 | import com.karumi.marvelapiclient.model.MarvelResponse; 31 | import com.karumi.marvelapiclient.model.MarvelUrl; 32 | import com.karumi.marvelapiclient.model.OrderBy; 33 | import com.karumi.marvelapiclient.model.StoryResourceDto; 34 | import com.karumi.marvelapiclient.model.TextObject; 35 | import java.util.ArrayList; 36 | import java.util.Calendar; 37 | import java.util.Date; 38 | import java.util.List; 39 | import java.util.TimeZone; 40 | import org.junit.Test; 41 | import retrofit2.Retrofit; 42 | import retrofit2.converter.gson.GsonConverterFactory; 43 | 44 | import static org.junit.Assert.assertEquals; 45 | import static org.junit.Assert.assertTrue; 46 | 47 | public class ComicApiClientTest extends ApiClientTest { 48 | 49 | private static final String ANY_PUBLIC_KEY = "1234"; 50 | private static final String ANY_PRIVATE_KEY = "abcd"; 51 | private static final String ANY_URL = "http://fake.marvel.com/"; 52 | private static final int ANY_OFFSET = 1; 53 | private static final int ANY_LIMIT = 10; 54 | private static final int INVALID_LIMIT = 0; 55 | private static final String ANY_TITLE = "name"; 56 | private static final String ANY_START_TITLE = "name"; 57 | private static final int ANY_START_YEAR = 2002; 58 | private static final int ANY_ISSUE_NUMBER = 1; 59 | private static final String ANY_DIAMOND_CODE = "any"; 60 | private static final String ANY_UPC = "1"; 61 | private static final String ANY_ISBN = "1"; 62 | private static final String ANY_EAN = "1"; 63 | private static final String ANY_ISSN = "1"; 64 | private static final int ANY_SERIE = 1; 65 | private static final int ANY_STORY = 1; 66 | private static final int ANY_CREATOR = 1; 67 | private static final int ANY_CHARACTER = 3; 68 | private static final int ANY_SHARED_APPEARANCES = 4; 69 | private static final int ANY_EVENT_1 = 1; 70 | private static final int ANY_EVENT_2 = 2; 71 | private static final int ANY_COLLABORATOR_1 = 1; 72 | private static final int ANY_COLLABORATOR_2 = 2; 73 | private static final String ANY_DATE_RANGE = "2015-01-09T22:10:45-0800"; 74 | private static final String ANY_MODIFIED_SINCE = "2015-01-09T22:10:45-0800"; 75 | private static final String ORDER_NAME_DESCEDANT_VALUE = "-name"; 76 | private static final String INVALID_COMIC_ID = ""; 77 | private static final String ANY_NOT_FOUND_ID = "1234"; 78 | private static final String ANY_COMIC_ID = "123456"; 79 | private static final String EVENTS_REQUEST = "1,2"; 80 | private static final String COLLABORATORS_REQUEST = "1,2"; 81 | private static final String LAST_WEEK_REQUEST = "last%20week"; 82 | 83 | @Test public void shouldRequestComicsByOffsetAndLimitWithAsParams() throws Exception { 84 | ComicApiClient comicApiClient = givenComicApiClient(); 85 | enqueueMockResponse(); 86 | 87 | comicApiClient.getAll(ANY_OFFSET, ANY_LIMIT); 88 | 89 | assertRequestSentToContains("offset=" + ANY_OFFSET, "limit=" + ANY_LIMIT); 90 | } 91 | 92 | @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionWhenLimitIsZero() 93 | throws Exception { 94 | ComicApiClient comicApiClient = givenComicApiClient(); 95 | enqueueMockResponse(); 96 | 97 | comicApiClient.getAll(ANY_OFFSET, INVALID_LIMIT); 98 | } 99 | 100 | @Test public void shouldUseAllTheRequestParamsAddedFromQueryWhenSendIt() throws Exception { 101 | ComicApiClient comicApiClient = givenComicApiClient(); 102 | enqueueMockResponse(); 103 | 104 | ComicsQuery query = ComicsQuery.Builder.create() 105 | .withFormat(Format.COMIC) 106 | .withFormatType(ComicsQuery.FormatType.COLLECTION) 107 | .withNoVariants() 108 | .withDateDescriptor(ComicsQuery.DateDescriptor.LAST_WEEK) 109 | .withDateRange(getAnyDate()) 110 | .withTitle(ANY_TITLE) 111 | .withTitleStartsWith(ANY_START_TITLE) 112 | .withStartYear(ANY_START_YEAR) 113 | .withIssueNumber(ANY_ISSUE_NUMBER) 114 | .withDiamondCode(ANY_DIAMOND_CODE) 115 | .withUpc(ANY_UPC) 116 | .withIsbn(ANY_ISBN) 117 | .withEan(ANY_EAN) 118 | .withIssn(ANY_ISSN) 119 | .withHasDigitalIssue() 120 | .withLimit(ANY_LIMIT) 121 | .withOffset(ANY_OFFSET) 122 | .addCreator(ANY_CREATOR) 123 | .addCharacter(ANY_CHARACTER) 124 | .withModifiedSince(getAnyDate()) 125 | .withOrderBy(OrderBy.NAME, false) 126 | .addEvent(getAnyEvents()) 127 | .addSerie(ANY_SERIE) 128 | .addStory(ANY_STORY) 129 | .addSharedAppearance(ANY_SHARED_APPEARANCES) 130 | .addCollaborator(getAnyCollaborators()) 131 | .build(); 132 | 133 | comicApiClient.getAll(query); 134 | 135 | assertRequestSentToContains("format=" + Format.COMIC.toString(), 136 | "formatType=" + ComicsQuery.FormatType.COLLECTION, "noVariants=true", 137 | "dateDescriptor=" + LAST_WEEK_REQUEST, "dateRange=" + ANY_DATE_RANGE, 138 | "startYear=" + ANY_START_YEAR, "issueNumber=" + ANY_ISSUE_NUMBER, 139 | "diamondCode=" + ANY_DIAMOND_CODE, "upc=" + ANY_UPC, "isbn=" + ANY_ISBN, "ean=" + ANY_EAN, 140 | "issn=" + ANY_ISSN, "hasDigitalIssue=true", "creators=" + ANY_CREATOR, 141 | "characters=" + ANY_CHARACTER, "offset=" + ANY_OFFSET, 142 | "appearances=" + ANY_SHARED_APPEARANCES, "collaborators=" + COLLABORATORS_REQUEST, 143 | "limit=" + ANY_LIMIT, "title=" + ANY_TITLE, "titleStartsWith=" + ANY_START_TITLE, 144 | "modifiedSince=" + ANY_MODIFIED_SINCE, "orderBy=" + ORDER_NAME_DESCEDANT_VALUE, 145 | "events=" + EVENTS_REQUEST, "series=" + ANY_SERIE, "stories=" + ANY_STORY); 146 | } 147 | 148 | @Test(expected = MarvelAuthApiException.class) 149 | public void shouldThrowMarvelApiExceptionOnAuthHttpError() throws Exception { 150 | ComicApiClient comicApiClient = givenComicApiClient(); 151 | enqueueMockResponse(401, 152 | "{\"code\":\"InvalidCredentials\",\"message\":\"That hash, timestamp and key " 153 | + "combination is invalid.\"}"); 154 | 155 | try { 156 | comicApiClient.getAll(ANY_OFFSET, ANY_LIMIT); 157 | } catch (MarvelApiException e) { 158 | assertEquals("InvalidCredentials", e.getMarvelCode()); 159 | assertEquals("That hash, timestamp and key combination is invalid.", e.getMessage()); 160 | throw e; 161 | } 162 | } 163 | 164 | @Test public void shouldParseGetAllComicsResponse() throws Exception { 165 | ComicApiClient comicApiClient = givenComicApiClient(); 166 | enqueueMockResponse("getComics.json"); 167 | 168 | MarvelResponse comics = comicApiClient.getAll(0, ANY_LIMIT); 169 | 170 | assertBasicMarvelResponse(comics); 171 | assertGetAllComicsResponseIsProperlyParsed(comics); 172 | } 173 | 174 | @Test(expected = IllegalArgumentException.class) public void shouldNotAcceptEmptyComicIds() 175 | throws Exception { 176 | ComicApiClient comicApiClient = givenComicApiClient(); 177 | 178 | comicApiClient.getComic(INVALID_COMIC_ID); 179 | } 180 | 181 | @Test public void shouldSendGetComicRequestToTheCorrectEndpoint() throws Exception { 182 | ComicApiClient comicApiClient = givenComicApiClient(); 183 | enqueueMockResponse("getComic.json"); 184 | 185 | comicApiClient.getComic(ANY_COMIC_ID); 186 | 187 | assertRequestSentToContains("comics/" + ANY_COMIC_ID); 188 | } 189 | 190 | @Test(expected = MarvelApiException.class) 191 | public void shouldReturnMarvelExceptionWhenTheIdDoesNotExist() throws Exception { 192 | ComicApiClient comicApiClient = givenComicApiClient(); 193 | enqueueMockResponse(404, "{\"code\":404,\"status\":\"We couldn't find that comic\"}"); 194 | 195 | try { 196 | comicApiClient.getComic(ANY_NOT_FOUND_ID); 197 | } catch (MarvelApiException e) { 198 | assertEquals("404", e.getMarvelCode()); 199 | assertEquals("We couldn't find that comic", e.getMessage()); 200 | throw e; 201 | } 202 | } 203 | 204 | @Test public void shouldParseGetComicResponse() throws Exception { 205 | ComicApiClient comicApiClient = givenComicApiClient(); 206 | enqueueMockResponse("getComic.json"); 207 | 208 | MarvelResponse comic = comicApiClient.getComic(ANY_COMIC_ID); 209 | 210 | assertBasicMarvelResponse(comic); 211 | 212 | ComicDto response = comic.getResponse(); 213 | assertIsLornaTheJungleGirl6(response); 214 | } 215 | 216 | private List getAnyEvents() { 217 | List events = new ArrayList<>(); 218 | events.add(ANY_EVENT_1); 219 | events.add(ANY_EVENT_2); 220 | return events; 221 | } 222 | 223 | private List getAnyCollaborators() { 224 | List collaborators = new ArrayList<>(); 225 | collaborators.add(ANY_COLLABORATOR_1); 226 | collaborators.add(ANY_COLLABORATOR_2); 227 | return collaborators; 228 | } 229 | 230 | private ComicApiClient givenComicApiClient() { 231 | Retrofit retrofit = new Retrofit.Builder().baseUrl(getBaseEndpoint()) 232 | .addConverterFactory(GsonConverterFactory.create()) 233 | .build(); 234 | 235 | MarvelApiConfig marvelApiConfig = 236 | new MarvelApiConfig.Builder(ANY_PUBLIC_KEY, ANY_PRIVATE_KEY).baseUrl(ANY_URL) 237 | .retrofit(retrofit) 238 | .build(); 239 | return new ComicApiClient(marvelApiConfig); 240 | } 241 | 242 | private void assertGetAllComicsResponseIsProperlyParsed(MarvelResponse comics) { 243 | ComicsDto comicsDto = comics.getResponse(); 244 | assertEquals(10, comicsDto.getCount()); 245 | assertEquals(10, comicsDto.getLimit()); 246 | assertEquals(0, comicsDto.getOffset()); 247 | assertEquals(35767, comicsDto.getTotal()); 248 | 249 | ComicDto comicDto = comicsDto.getComics().get(0); 250 | assertIsLornaTheJungleGirl6(comicDto); 251 | } 252 | 253 | private void assertIsLornaTheJungleGirl6(ComicDto comicDto) { 254 | assertEquals("42882", comicDto.getId()); 255 | assertEquals(26110, comicDto.getDigitalId()); 256 | assertEquals("Lorna the Jungle Girl (1954) #6", comicDto.getTitle()); 257 | assertEquals(6, comicDto.getIssueNumber(), 0); 258 | assertEquals("variant", comicDto.getVariantDescription()); 259 | assertEquals("description", comicDto.getDescription()); 260 | assertEquals("2015-10-15T11:13:52-0400", comicDto.getModified()); 261 | assertEquals("1", comicDto.getIsbn()); 262 | assertEquals("2", comicDto.getUpc()); 263 | assertEquals("3", comicDto.getEan()); 264 | assertEquals("4", comicDto.getIssn()); 265 | assertEquals("5", comicDto.getDiamondCode()); 266 | assertEquals("Comic", comicDto.getFormat()); 267 | assertEquals(32, comicDto.getPageCount()); 268 | TextObject textObject = comicDto.getTextObjects().get(0); 269 | assertEquals("issue_solicit_text", textObject.getType()); 270 | assertEquals("en-us", textObject.getLanguage()); 271 | assertEquals("From the award-winning team that brought you Daredevil and Spider-Woman " 272 | + "comes another explosive chapter of one of the most controversial " 273 | + "creator-owned comics being published today. Scarlet has declared " 274 | + "war on a city that refuses to stop the corruption that is strangling " 275 | + "it from within, and now she'll be forced to make her most dangerous " 276 | + "move yet: letting them capture her.", textObject.getText()); 277 | 278 | assertEquals("http://gateway.marvel.com/v1/public/comics/42882", comicDto.getResourceURI()); 279 | MarvelUrl marvelUrl = comicDto.getUrls().get(0); 280 | assertEquals("detail", marvelUrl.getType()); 281 | assertEquals( 282 | "http://marvel.com/comics/issue/42882/lorna_the_jungle_girl_1954_6?utm_campaign=apiRef" 283 | + "&utm_source=838a08a2f4c39fa3fd218b1b2d43f19a", marvelUrl.getUrl()); 284 | 285 | ComicResourceDto series = comicDto.getSeries(); 286 | assertEquals("http://gateway.marvel.com/v1/public/series/16355", series.getResourceUri()); 287 | assertEquals("Lorna the Jungle Girl (1954 - 1957)", series.getName()); 288 | 289 | MarvelDate marvelDate = comicDto.getDates().get(0); 290 | assertEquals("onsaleDate", marvelDate.getType()); 291 | assertEquals("2054-03-01T00:00:00-0500", marvelDate.getDate()); 292 | 293 | MarvelPrice marvelPrice = comicDto.getPrices().get(0); 294 | assertEquals("printPrice", marvelPrice.getType()); 295 | assertEquals(0, marvelPrice.getPrice(), 0); 296 | 297 | MarvelImage thumbnail = comicDto.getThumbnail(); 298 | assertEquals("http://i.annihil.us/u/prod/marvel/i/mg/9/40/50b4fc783d30f", thumbnail.getPath()); 299 | assertEquals("jpg", thumbnail.getExtension()); 300 | 301 | MarvelImage marvelImage = comicDto.getImages().get(0); 302 | assertEquals("http://i.annihil.us/u/prod/marvel/i/mg/9/40/50b4fc783d30f", 303 | marvelImage.getPath()); 304 | assertEquals("jpg", marvelImage.getExtension()); 305 | 306 | MarvelResources creators = comicDto.getCreators(); 307 | assertEquals(1, creators.getAvailable()); 308 | assertEquals("http://gateway.marvel.com/v1/public/comics/41530/creators", 309 | creators.getCollectionUri()); 310 | assertEquals(1, creators.getReturned()); 311 | CreatorResourceDto creatorResourceDto = creators.getItems().get(0); 312 | assertEquals("http://gateway.marvel.com/v1/public/creators/4430", 313 | creatorResourceDto.getResourceUri()); 314 | assertEquals("Jeff Youngquist", creatorResourceDto.getName()); 315 | assertEquals("editor", creatorResourceDto.getRole()); 316 | 317 | MarvelResources characters = comicDto.getCharacters(); 318 | assertEquals(0, characters.getAvailable()); 319 | assertEquals(0, characters.getReturned()); 320 | assertTrue(characters.getItems().isEmpty()); 321 | 322 | MarvelResources stories = comicDto.getStories(); 323 | assertEquals(1, stories.getAvailable()); 324 | assertEquals("http://gateway.marvel.com/v1/public/comics/42882/stories", 325 | stories.getCollectionUri()); 326 | assertEquals(1, stories.getReturned()); 327 | StoryResourceDto storyResourceDto = stories.getItems().get(0); 328 | assertEquals("cover from Lorna the Jungle Girl #6", storyResourceDto.getName()); 329 | assertEquals("cover", storyResourceDto.getType()); 330 | 331 | MarvelResources events = comicDto.getEvents(); 332 | assertEquals(0, events.getAvailable()); 333 | assertEquals(0, events.getReturned()); 334 | assertEquals("http://gateway.marvel.com/v1/public/comics/42882/events", 335 | events.getCollectionUri()); 336 | assertTrue(events.getItems().isEmpty()); 337 | } 338 | 339 | public Date getAnyDate() { 340 | Calendar instance = Calendar.getInstance(); 341 | instance.setTimeZone(TimeZone.getTimeZone(ANY_TIME_ZONE)); 342 | instance.set(Calendar.YEAR, 2015); 343 | instance.set(Calendar.MONTH, Calendar.JANUARY); 344 | instance.set(Calendar.DAY_OF_MONTH, 9); 345 | instance.set(Calendar.HOUR_OF_DAY, 22); 346 | instance.set(Calendar.MINUTE, 10); 347 | instance.set(Calendar.SECOND, 45); 348 | return instance.getTime(); 349 | } 350 | } 351 | -------------------------------------------------------------------------------- /MarvelApiClient/src/test/java/com/karumi/marvelapiclient/MarvelApiConfigTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient; 17 | 18 | import org.junit.Test; 19 | 20 | public class MarvelApiConfigTest { 21 | 22 | private static final String ANY_PRIVATE_KEY = "PRIVATEKEY"; 23 | private static final String ANY_PUBLIC_KEY = "PUBLICKEY"; 24 | 25 | @Test(expected = IllegalArgumentException.class) 26 | public void shouldThrowInvalidArgumentExceptionWhenCreateWithoutPublicKey() { 27 | MarvelApiConfig.with(null, ANY_PRIVATE_KEY); 28 | } 29 | 30 | @Test(expected = IllegalArgumentException.class) 31 | public void shouldThrowInvalidArgumentExceptionWhenCreateWithoutPrivateKey() { 32 | MarvelApiConfig.with(ANY_PUBLIC_KEY, null); 33 | } 34 | 35 | @Test(expected = IllegalArgumentException.class) 36 | public void shouldThrowInvalidArgumentExceptionWhenCreateWithInvalidRetrofit() { 37 | new MarvelApiConfig.Builder(ANY_PUBLIC_KEY, ANY_PRIVATE_KEY).retrofit(null); 38 | } 39 | } -------------------------------------------------------------------------------- /MarvelApiClient/src/test/java/com/karumi/marvelapiclient/SeriesApiClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient; 17 | 18 | import com.karumi.marvelapiclient.model.CharacterResourceDto; 19 | import com.karumi.marvelapiclient.model.ComicResourceDto; 20 | import com.karumi.marvelapiclient.model.ComicsQuery; 21 | import com.karumi.marvelapiclient.model.CreatorResourceDto; 22 | import com.karumi.marvelapiclient.model.EventResourceDto; 23 | import com.karumi.marvelapiclient.model.Format; 24 | import com.karumi.marvelapiclient.model.MarvelImage; 25 | import com.karumi.marvelapiclient.model.MarvelResources; 26 | import com.karumi.marvelapiclient.model.MarvelResponse; 27 | import com.karumi.marvelapiclient.model.MarvelUrl; 28 | import com.karumi.marvelapiclient.model.OrderBy; 29 | import com.karumi.marvelapiclient.model.SeriesCollectionDto; 30 | import com.karumi.marvelapiclient.model.SeriesDto; 31 | import com.karumi.marvelapiclient.model.SeriesQuery; 32 | import com.karumi.marvelapiclient.model.StoryResourceDto; 33 | import java.util.ArrayList; 34 | import java.util.Calendar; 35 | import java.util.Date; 36 | import java.util.List; 37 | import java.util.TimeZone; 38 | import org.junit.Test; 39 | import retrofit2.Retrofit; 40 | import retrofit2.converter.gson.GsonConverterFactory; 41 | 42 | import static org.junit.Assert.assertEquals; 43 | import static org.junit.Assert.assertTrue; 44 | 45 | public class SeriesApiClientTest extends ApiClientTest { 46 | 47 | private static final String ANY_PUBLIC_KEY = "1234"; 48 | private static final String ANY_PRIVATE_KEY = "abcd"; 49 | private static final String ANY_URL = "http://fake.marvel.com/"; 50 | private static final int ANY_OFFSET = 1; 51 | private static final int ANY_LIMIT = 10; 52 | private static final int INVALID_LIMIT = 0; 53 | private static final String ANY_TITLE = "name"; 54 | private static final String ANY_START_TITLE = "name"; 55 | private static final int ANY_START_YEAR = 2002; 56 | private static final int ANY_COMIC = 1; 57 | private static final int ANY_STORY = 1; 58 | private static final int ANY_CREATOR = 1; 59 | private static final int ANY_CHARACTER = 3; 60 | private static final int ANY_EVENT_1 = 1; 61 | private static final int ANY_EVENT_2 = 2; 62 | private static final int ANY_COLLABORATOR_1 = 1; 63 | private static final int ANY_COLLABORATOR_2 = 2; 64 | private static final String ANY_MODIFIED_SINCE = "2015-01-09T22:10:45-0800"; 65 | private static final String ORDER_NAME_DESCEDANT_VALUE = "-name"; 66 | private static final String INVALID_SERIES_ID = ""; 67 | private static final String ANY_NOT_FOUND_ID = "1234"; 68 | private static final String ANY_SERIE_ID = "123456"; 69 | private static final String EVENTS_REQUEST = "1,2"; 70 | private static final int ANY_SERIE = 1; 71 | private static final int ANY_SHARED_APPEARANCES = 4; 72 | private static final String COLLABORATORS_REQUEST = "1,2"; 73 | private static final String LAST_WEEK_REQUEST = "last%20week"; 74 | private static final String ANY_DATE_RANGE = "2015-01-09T22:10:45-0800"; 75 | 76 | private static final int ANY_ISSUE_NUMBER = 1; 77 | private static final String ANY_DIAMOND_CODE = "any"; 78 | private static final String ANY_UPC = "1"; 79 | private static final String ANY_ISBN = "1"; 80 | private static final String ANY_EAN = "1"; 81 | private static final String ANY_ISSN = "1"; 82 | 83 | @Test public void shouldSendOffsetAsLimitAsParamsWhenGetAll() throws Exception { 84 | SeriesApiClient seriesApiClient = givenSeriesApiClient(); 85 | enqueueMockResponse(); 86 | 87 | seriesApiClient.getAll(ANY_OFFSET, ANY_LIMIT); 88 | 89 | assertRequestSentToContains("offset=" + ANY_OFFSET, "limit=" + ANY_LIMIT); 90 | } 91 | 92 | @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionWhenLimitIsZero() 93 | throws Exception { 94 | SeriesApiClient seriesApiClient = givenSeriesApiClient(); 95 | enqueueMockResponse(); 96 | 97 | seriesApiClient.getAll(ANY_OFFSET, INVALID_LIMIT); 98 | } 99 | 100 | @Test public void shouldUseAllTheRequestParamsAddedFromQueryWhenSendIt() throws Exception { 101 | SeriesApiClient seriesApiClient = givenSeriesApiClient(); 102 | enqueueMockResponse(); 103 | 104 | SeriesQuery query = SeriesQuery.Builder.create() 105 | .withTitle(ANY_TITLE) 106 | .withTitleStartsWith(ANY_START_TITLE) 107 | .withStartYear(ANY_START_YEAR) 108 | .withLimit(ANY_LIMIT) 109 | .withOffset(ANY_OFFSET) 110 | .addCreator(ANY_CREATOR) 111 | .addCharacter(ANY_CHARACTER) 112 | .withModifiedSince(getAnyDate()) 113 | .withOrderBy(OrderBy.NAME, false) 114 | .addEvent(getAnyEvents()) 115 | .addComic(ANY_COMIC) 116 | .addStory(ANY_STORY) 117 | .withContains(Format.COMIC) 118 | .withSeriesType(SeriesQuery.SeriesType.COLLECTION) 119 | .build(); 120 | 121 | seriesApiClient.getAll(query); 122 | 123 | assertRequestSentToContains("startYear=" + ANY_START_YEAR, "creators=" + ANY_CREATOR, 124 | "characters=" + ANY_CHARACTER, "offset=" + ANY_OFFSET, "limit=" + ANY_LIMIT, 125 | "title=" + ANY_TITLE, "titleStartsWith=" + ANY_START_TITLE, 126 | "modifiedSince=" + ANY_MODIFIED_SINCE, "orderBy=" + ORDER_NAME_DESCEDANT_VALUE, 127 | "events=" + EVENTS_REQUEST, "comics=" + ANY_COMIC, "stories=" + ANY_STORY, 128 | "contains=" + Format.COMIC.toString(), 129 | "seriesType=" + SeriesQuery.SeriesType.COLLECTION.toString()); 130 | } 131 | 132 | @Test(expected = MarvelAuthApiException.class) 133 | public void shouldThrowMarvelApiExceptionOnAuthHttpError() throws Exception { 134 | SeriesApiClient seriesApiClient = givenSeriesApiClient(); 135 | enqueueMockResponse(401, 136 | "{\"code\":\"InvalidCredentials\",\"message\":\"That hash, timestamp and key " 137 | + "combination is invalid.\"}"); 138 | 139 | try { 140 | seriesApiClient.getAll(ANY_OFFSET, ANY_LIMIT); 141 | } catch (MarvelApiException e) { 142 | assertEquals("InvalidCredentials", e.getMarvelCode()); 143 | assertEquals("That hash, timestamp and key combination is invalid.", e.getMessage()); 144 | throw e; 145 | } 146 | } 147 | 148 | @Test public void shouldParseGetAllSeriesResponse() throws Exception { 149 | SeriesApiClient seriesApiClient = givenSeriesApiClient(); 150 | enqueueMockResponse("getSeriesCollection.json"); 151 | 152 | MarvelResponse series = seriesApiClient.getAll(0, ANY_LIMIT); 153 | 154 | assertBasicMarvelResponse(series); 155 | assertGetAllSeriesResponseIsProperlyParsed(series); 156 | } 157 | 158 | @Test(expected = IllegalArgumentException.class) public void shouldNotAcceptEmptySeriesId() 159 | throws Exception { 160 | SeriesApiClient seriesApiClient = givenSeriesApiClient(); 161 | 162 | seriesApiClient.getSeriesById(INVALID_SERIES_ID); 163 | } 164 | 165 | @Test public void shouldSendGetSeriesRequestToTheCorrectEndpoint() throws Exception { 166 | SeriesApiClient seriesApiClient = givenSeriesApiClient(); 167 | enqueueMockResponse("getSeriesCollection.json"); 168 | 169 | seriesApiClient.getSeriesById(ANY_SERIE_ID); 170 | 171 | assertRequestSentToContains("series/" + ANY_SERIE_ID); 172 | } 173 | 174 | @Test(expected = MarvelApiException.class) 175 | public void shouldReturnMarvelExceptionWhenTheIdDoesNotExist() throws Exception { 176 | SeriesApiClient seriesApiClient = givenSeriesApiClient(); 177 | enqueueMockResponse(404, "{\"code\":404,\"status\":\"We couldn't find that series\"}"); 178 | 179 | try { 180 | seriesApiClient.getSeriesById(ANY_NOT_FOUND_ID); 181 | } catch (MarvelApiException e) { 182 | assertEquals("404", e.getMarvelCode()); 183 | assertEquals("We couldn't find that series", e.getMessage()); 184 | throw e; 185 | } 186 | } 187 | 188 | @Test public void shouldParseGetSeriesResponse() throws Exception { 189 | SeriesApiClient seriesApiClient = givenSeriesApiClient(); 190 | enqueueMockResponse("getSeries.json"); 191 | 192 | MarvelResponse series = seriesApiClient.getSeriesById(ANY_SERIE_ID); 193 | 194 | assertBasicMarvelResponse(series); 195 | 196 | SeriesDto response = series.getResponse(); 197 | assertIs5Ronnin(response); 198 | } 199 | 200 | @Test public void shouldSendGetComicBySeriesRequestToTheCorrectEndpoint() throws Exception { 201 | SeriesApiClient seriesApiClient = givenSeriesApiClient(); 202 | enqueueMockResponse("getComics.json"); 203 | 204 | ComicsQuery query = ComicsQuery.Builder.create() 205 | .withFormat(Format.COMIC) 206 | .withFormatType(ComicsQuery.FormatType.COLLECTION) 207 | .withNoVariants() 208 | .withDateDescriptor(ComicsQuery.DateDescriptor.LAST_WEEK) 209 | .withDateRange(getAnyDate()) 210 | .withTitle(ANY_TITLE) 211 | .withTitleStartsWith(ANY_START_TITLE) 212 | .withStartYear(ANY_START_YEAR) 213 | .withIssueNumber(ANY_ISSUE_NUMBER) 214 | .withDiamondCode(ANY_DIAMOND_CODE) 215 | .withUpc(ANY_UPC) 216 | .withIsbn(ANY_ISBN) 217 | .withEan(ANY_EAN) 218 | .withIssn(ANY_ISSN) 219 | .withHasDigitalIssue() 220 | .withLimit(ANY_LIMIT) 221 | .withOffset(ANY_OFFSET) 222 | .addCreator(ANY_CREATOR) 223 | .addCharacter(ANY_CHARACTER) 224 | .withModifiedSince(getAnyDate()) 225 | .withOrderBy(OrderBy.NAME, false) 226 | .addEvent(getAnyEvents()) 227 | .addSerie(ANY_SERIE) 228 | .addStory(ANY_STORY) 229 | .addSharedAppearance(ANY_SHARED_APPEARANCES) 230 | .addCollaborator(getAnyCollaborators()) 231 | .build(); 232 | 233 | seriesApiClient.getComicsBySeries(ANY_SERIE_ID, query); 234 | 235 | assertRequestSentToContains("series/" + ANY_SERIE_ID, "format=" + Format.COMIC.toString(), 236 | "formatType=" + ComicsQuery.FormatType.COLLECTION, "noVariants=true", 237 | "dateDescriptor=" + LAST_WEEK_REQUEST, "dateRange=" + ANY_DATE_RANGE, 238 | "startYear=" + ANY_START_YEAR, "issueNumber=" + ANY_ISSUE_NUMBER, 239 | "diamondCode=" + ANY_DIAMOND_CODE, "upc=" + ANY_UPC, "isbn=" + ANY_ISBN, "ean=" + ANY_EAN, 240 | "issn=" + ANY_ISSN, "hasDigitalIssue=true", "creators=" + ANY_CREATOR, 241 | "characters=" + ANY_CHARACTER, "offset=" + ANY_OFFSET, 242 | "appearances=" + ANY_SHARED_APPEARANCES, "collaborators=" + COLLABORATORS_REQUEST, 243 | "limit=" + ANY_LIMIT, "title=" + ANY_TITLE, "titleStartsWith=" + ANY_START_TITLE, 244 | "modifiedSince=" + ANY_MODIFIED_SINCE, "orderBy=" + ORDER_NAME_DESCEDANT_VALUE, 245 | "events=" + EVENTS_REQUEST, "series=" + ANY_SERIE, "stories=" + ANY_STORY); 246 | } 247 | 248 | @Test(expected = IllegalArgumentException.class) 249 | public void shouldThrowExceptionWhenCallGetComicBySerieAndLimitIsZero() throws Exception { 250 | SeriesApiClient seriesApiClient = givenSeriesApiClient(); 251 | enqueueMockResponse(); 252 | 253 | seriesApiClient.getComicsBySeries(ANY_SERIE_ID, ANY_OFFSET, INVALID_LIMIT); 254 | } 255 | 256 | @Test(expected = IllegalArgumentException.class) 257 | public void shouldThrowExceptionWhenCallGetComicBySerieAndSerieIdIsEmpty() throws Exception { 258 | SeriesApiClient seriesApiClient = givenSeriesApiClient(); 259 | enqueueMockResponse(); 260 | 261 | seriesApiClient.getComicsBySeries("", ANY_OFFSET, INVALID_LIMIT); 262 | } 263 | 264 | private List getAnyCollaborators() { 265 | List collaborators = new ArrayList<>(); 266 | collaborators.add(ANY_COLLABORATOR_1); 267 | collaborators.add(ANY_COLLABORATOR_2); 268 | return collaborators; 269 | } 270 | 271 | private List getAnyEvents() { 272 | List events = new ArrayList<>(); 273 | events.add(ANY_EVENT_1); 274 | events.add(ANY_EVENT_2); 275 | return events; 276 | } 277 | 278 | private SeriesApiClient givenSeriesApiClient() { 279 | Retrofit retrofit = new Retrofit.Builder().baseUrl(getBaseEndpoint()) 280 | .addConverterFactory(GsonConverterFactory.create()) 281 | .build(); 282 | 283 | MarvelApiConfig marvelApiConfig = 284 | new MarvelApiConfig.Builder(ANY_PUBLIC_KEY, ANY_PRIVATE_KEY).baseUrl(ANY_URL) 285 | .retrofit(retrofit) 286 | .build(); 287 | return new SeriesApiClient(marvelApiConfig); 288 | } 289 | 290 | private void assertGetAllSeriesResponseIsProperlyParsed( 291 | MarvelResponse series) { 292 | SeriesCollectionDto seriesCollectionDto = series.getResponse(); 293 | assertEquals(10, seriesCollectionDto.getCount()); 294 | assertEquals(10, seriesCollectionDto.getLimit()); 295 | assertEquals(0, seriesCollectionDto.getOffset()); 296 | assertEquals(1823, seriesCollectionDto.getTotal()); 297 | 298 | SeriesDto seriesDto = seriesCollectionDto.getSeries().get(0); 299 | assertIs5Ronnin(seriesDto); 300 | } 301 | 302 | private void assertIs5Ronnin(SeriesDto seriesDto) { 303 | assertEquals("15276", seriesDto.getId()); 304 | assertEquals("5 Ronin (2011)", seriesDto.getTitle()); 305 | assertEquals("description", seriesDto.getDescription()); 306 | assertEquals("2011-05-20T16:25:29-0400", seriesDto.getModified()); 307 | assertEquals(2011, seriesDto.getStartYear()); 308 | assertEquals(2011, seriesDto.getEndYear()); 309 | assertEquals("+18", seriesDto.getRating()); 310 | 311 | assertEquals("http://gateway.marvel.com/v1/public/series/15276", seriesDto.getResourceURI()); 312 | 313 | MarvelUrl marvelUrl = seriesDto.getUrls().get(0); 314 | assertEquals("detail", marvelUrl.getType()); 315 | assertEquals("http://marvel.com/comics/series/15276/5_ronin_2011?utm_campaign=apiRef&utm_source" 316 | + "=838a08a2f4c39fa3fd218b1b2d43f19a", marvelUrl.getUrl()); 317 | 318 | MarvelImage thumbnail = seriesDto.getThumbnail(); 319 | assertEquals("http://i.annihil.us/u/prod/marvel/i/mg/b/40/image_not_available", 320 | thumbnail.getPath()); 321 | assertEquals("jpg", thumbnail.getExtension()); 322 | 323 | MarvelResources creators = seriesDto.getCreators(); 324 | assertEquals(8, creators.getAvailable()); 325 | assertEquals("http://gateway.marvel.com/v1/public/series/15276/creators", 326 | creators.getCollectionUri()); 327 | assertEquals(8, creators.getReturned()); 328 | CreatorResourceDto creatorResourceDto = creators.getItems().get(0); 329 | assertEquals("http://gateway.marvel.com/v1/public/creators/750", 330 | creatorResourceDto.getResourceUri()); 331 | assertEquals("David Aja", creatorResourceDto.getName()); 332 | assertEquals("penciller (cover)", creatorResourceDto.getRole()); 333 | 334 | MarvelResources characters = seriesDto.getCharacters(); 335 | assertEquals(4, characters.getAvailable()); 336 | assertEquals(4, characters.getReturned()); 337 | CharacterResourceDto characterResourceDto = characters.getItems().get(0); 338 | assertEquals("http://gateway.marvel.com/v1/public/characters/1009268", 339 | characterResourceDto.getResourceUri()); 340 | assertEquals("Deadpool", characterResourceDto.getName()); 341 | 342 | MarvelResources stories = seriesDto.getStories(); 343 | assertEquals(12, stories.getAvailable()); 344 | assertEquals("http://gateway.marvel.com/v1/public/series/15276/stories", 345 | stories.getCollectionUri()); 346 | assertEquals(12, stories.getReturned()); 347 | StoryResourceDto storyResourceDto = stories.getItems().get(0); 348 | assertEquals("http://gateway.marvel.com/v1/public/stories/80038", 349 | storyResourceDto.getResourceUri()); 350 | assertEquals("Interior #80038", storyResourceDto.getName()); 351 | assertEquals("interiorStory", storyResourceDto.getType()); 352 | 353 | MarvelResources comics = seriesDto.getComics(); 354 | assertEquals(2, comics.getAvailable()); 355 | assertEquals("http://gateway.marvel.com/v1/public/series/15276/comics", 356 | comics.getCollectionUri()); 357 | assertEquals(2, comics.getReturned()); 358 | ComicResourceDto comicResourceDto = comics.getItems().get(0); 359 | assertEquals("http://gateway.marvel.com/v1/public/comics/41112", 360 | comicResourceDto.getResourceUri()); 361 | assertEquals("5 Ronin (Hardcover)", comicResourceDto.getName()); 362 | 363 | MarvelResources events = seriesDto.getEvents(); 364 | assertEquals(0, events.getAvailable()); 365 | assertEquals(0, events.getReturned()); 366 | assertEquals("http://gateway.marvel.com/v1/public/series/15276/events", 367 | events.getCollectionUri()); 368 | assertTrue(events.getItems().isEmpty()); 369 | } 370 | 371 | public Date getAnyDate() { 372 | Calendar instance = Calendar.getInstance(); 373 | instance.setTimeZone(TimeZone.getTimeZone(ANY_TIME_ZONE)); 374 | instance.set(Calendar.YEAR, 2015); 375 | instance.set(Calendar.MONTH, Calendar.JANUARY); 376 | instance.set(Calendar.DAY_OF_MONTH, 9); 377 | instance.set(Calendar.HOUR_OF_DAY, 22); 378 | instance.set(Calendar.MINUTE, 10); 379 | instance.set(Calendar.SECOND, 45); 380 | return instance.getTime(); 381 | } 382 | } 383 | -------------------------------------------------------------------------------- /MarvelApiClient/src/test/java/com/karumi/marvelapiclient/extensions/FileExtensions.java: -------------------------------------------------------------------------------- 1 | package com.karumi.marvelapiclient.extensions; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import org.apache.commons.io.FileUtils; 6 | 7 | /** 8 | * Used to extend file functionality with new methods like the one to read from a file and parse 9 | * it to a string. 10 | */ 11 | public final class FileExtensions { 12 | 13 | private static final String UTF_8 = "UTF-8"; 14 | 15 | private FileExtensions() { 16 | } 17 | 18 | public static String getStringFromFile(Class clazz, String filePath) throws IOException { 19 | ClassLoader classLoader = clazz.getClassLoader(); 20 | File file = new File(classLoader.getResource("resources/" + filePath).getFile()); 21 | return FileUtils.readFileToString(file, UTF_8); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /MarvelApiClient/src/test/java/com/karumi/marvelapiclient/model/CharactersQueryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.model; 17 | 18 | import org.junit.Test; 19 | 20 | public class CharactersQueryTest { 21 | private static final int INVALID_LIMIT = 0; 22 | private static final int INVALID_OFFSET = -1; 23 | private static final int LIMIT_BIGGET_THAN_MAX = 101; 24 | 25 | @Test(expected = IllegalArgumentException.class) 26 | public void shouldThrowExceptionWhenSetInvalidOffset() throws Exception { 27 | CharactersQuery.Builder.create().withOffset(INVALID_OFFSET).build(); 28 | } 29 | 30 | @Test(expected = IllegalArgumentException.class) 31 | public void shouldThrowExceptionWhenSetLimitEqualZero() throws Exception { 32 | CharactersQuery.Builder.create().withLimit(INVALID_LIMIT).build(); 33 | } 34 | 35 | @Test(expected = IllegalArgumentException.class) 36 | public void shouldThrowExceptionWhenSetLimitMoreThanMaxLimit() throws Exception { 37 | CharactersQuery.Builder.create().withLimit(LIMIT_BIGGET_THAN_MAX).build(); 38 | } 39 | 40 | @Test(expected = IllegalArgumentException.class) 41 | public void shouldThrowExceptionWhenAddNullComics() throws Exception { 42 | CharactersQuery.Builder.create().addComics(null).build(); 43 | } 44 | 45 | @Test(expected = IllegalArgumentException.class) 46 | public void shouldThrowExceptionWhenAddNullEvents() throws Exception { 47 | CharactersQuery.Builder.create().addEvents(null).build(); 48 | } 49 | 50 | @Test(expected = IllegalArgumentException.class) 51 | public void shouldThrowExceptionWhenAddNullSeries() throws Exception { 52 | CharactersQuery.Builder.create().addSeries(null).build(); 53 | } 54 | 55 | @Test(expected = IllegalArgumentException.class) 56 | public void shouldThrowExceptionWhenAddNullStories() throws Exception { 57 | CharactersQuery.Builder.create().addStory(null).build(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /MarvelApiClient/src/test/resources/getCharacter.json: -------------------------------------------------------------------------------- 1 | { 2 | "code": 200, 3 | "status": "Ok", 4 | "copyright": "© 2015 MARVEL", 5 | "attributionText": "Data provided by Marvel. © 2015 MARVEL", 6 | "attributionHTML": "Data provided by Marvel. © 2015 MARVEL", 7 | "etag": "55122b303dfbc9fdfd12c080eded740b83354269", 8 | "data": { 9 | "offset": 0, 10 | "limit": 20, 11 | "total": 1, 12 | "count": 1, 13 | "results": [ 14 | { 15 | "id": 1011334, 16 | "name": "3-D Man", 17 | "description": "3-D man is a 3d superhero", 18 | "modified": "2014-04-29T14:18:17-0400", 19 | "thumbnail": { 20 | "path": "http://i.annihil.us/u/prod/marvel/i/mg/c/e0/535fecbbb9784", 21 | "extension": "jpg" 22 | }, 23 | "resourceURI": "http://gateway.marvel.com/v1/public/characters/1011334", 24 | "comics": { 25 | "available": 11, 26 | "collectionURI": "http://gateway.marvel.com/v1/public/characters/1011334/comics", 27 | "items": [ 28 | { 29 | "resourceURI": "http://gateway.marvel.com/v1/public/comics/21366", 30 | "name": "Avengers: The Initiative (2007) #14" 31 | }, 32 | { 33 | "resourceURI": "http://gateway.marvel.com/v1/public/comics/24571", 34 | "name": "Avengers: The Initiative (2007) #14 (SPOTLIGHT VARIANT)" 35 | }, 36 | { 37 | "resourceURI": "http://gateway.marvel.com/v1/public/comics/21546", 38 | "name": "Avengers: The Initiative (2007) #15" 39 | }, 40 | { 41 | "resourceURI": "http://gateway.marvel.com/v1/public/comics/21741", 42 | "name": "Avengers: The Initiative (2007) #16" 43 | }, 44 | { 45 | "resourceURI": "http://gateway.marvel.com/v1/public/comics/21975", 46 | "name": "Avengers: The Initiative (2007) #17" 47 | }, 48 | { 49 | "resourceURI": "http://gateway.marvel.com/v1/public/comics/22299", 50 | "name": "Avengers: The Initiative (2007) #18" 51 | }, 52 | { 53 | "resourceURI": "http://gateway.marvel.com/v1/public/comics/22300", 54 | "name": "Avengers: The Initiative (2007) #18 (ZOMBIE VARIANT)" 55 | }, 56 | { 57 | "resourceURI": "http://gateway.marvel.com/v1/public/comics/22506", 58 | "name": "Avengers: The Initiative (2007) #19" 59 | }, 60 | { 61 | "resourceURI": "http://gateway.marvel.com/v1/public/comics/10223", 62 | "name": "Marvel Premiere (1972) #35" 63 | }, 64 | { 65 | "resourceURI": "http://gateway.marvel.com/v1/public/comics/10224", 66 | "name": "Marvel Premiere (1972) #36" 67 | }, 68 | { 69 | "resourceURI": "http://gateway.marvel.com/v1/public/comics/10225", 70 | "name": "Marvel Premiere (1972) #37" 71 | } 72 | ], 73 | "returned": 11 74 | }, 75 | "series": { 76 | "available": 2, 77 | "collectionURI": "http://gateway.marvel.com/v1/public/characters/1011334/series", 78 | "items": [ 79 | { 80 | "resourceURI": "http://gateway.marvel.com/v1/public/series/1945", 81 | "name": "Avengers: The Initiative (2007 - 2010)" 82 | }, 83 | { 84 | "resourceURI": "http://gateway.marvel.com/v1/public/series/2045", 85 | "name": "Marvel Premiere (1972 - 1981)" 86 | } 87 | ], 88 | "returned": 2 89 | }, 90 | "stories": { 91 | "available": 17, 92 | "collectionURI": "http://gateway.marvel.com/v1/public/characters/1011334/stories", 93 | "items": [ 94 | { 95 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/19947", 96 | "name": "Cover #19947", 97 | "type": "cover" 98 | }, 99 | { 100 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/19948", 101 | "name": "The 3-D Man!", 102 | "type": "interiorStory" 103 | }, 104 | { 105 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/19949", 106 | "name": "Cover #19949", 107 | "type": "cover" 108 | }, 109 | { 110 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/19950", 111 | "name": "The Devil's Music!", 112 | "type": "interiorStory" 113 | }, 114 | { 115 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/19951", 116 | "name": "Cover #19951", 117 | "type": "cover" 118 | }, 119 | { 120 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/19952", 121 | "name": "Code-Name: The Cold Warrior!", 122 | "type": "interiorStory" 123 | }, 124 | { 125 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/47185", 126 | "name": "Avengers: The Initiative (2007) #14 - Int", 127 | "type": "interiorStory" 128 | }, 129 | { 130 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/47499", 131 | "name": "Avengers: The Initiative (2007) #15 - Int", 132 | "type": "interiorStory" 133 | }, 134 | { 135 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/47792", 136 | "name": "Avengers: The Initiative (2007) #16", 137 | "type": "cover" 138 | }, 139 | { 140 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/47793", 141 | "name": "Avengers: The Initiative (2007) #16 - Int", 142 | "type": "interiorStory" 143 | }, 144 | { 145 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/48362", 146 | "name": "Avengers: The Initiative (2007) #17 - Int", 147 | "type": "interiorStory" 148 | }, 149 | { 150 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/49104", 151 | "name": "Avengers: The Initiative (2007) #18 - Int", 152 | "type": "interiorStory" 153 | }, 154 | { 155 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/49106", 156 | "name": "Avengers: The Initiative (2007) #18, Zombie Variant - Int", 157 | "type": "interiorStory" 158 | }, 159 | { 160 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/49888", 161 | "name": "Avengers: The Initiative (2007) #19", 162 | "type": "cover" 163 | }, 164 | { 165 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/49889", 166 | "name": "Avengers: The Initiative (2007) #19 - Int", 167 | "type": "interiorStory" 168 | }, 169 | { 170 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/54371", 171 | "name": "Avengers: The Initiative (2007) #14, Spotlight Variant - Int", 172 | "type": "interiorStory" 173 | }, 174 | { 175 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/96303", 176 | "name": "Deadpool (1997) #44", 177 | "type": "interiorStory" 178 | } 179 | ], 180 | "returned": 17 181 | }, 182 | "events": { 183 | "available": 1, 184 | "collectionURI": "http://gateway.marvel.com/v1/public/characters/1011334/events", 185 | "items": [ 186 | { 187 | "resourceURI": "http://gateway.marvel.com/v1/public/events/269", 188 | "name": "Secret Invasion" 189 | } 190 | ], 191 | "returned": 1 192 | }, 193 | "urls": [ 194 | { 195 | "type": "detail", 196 | "url": "http://marvel.com/characters/74/3-d_man?utm_campaign=apiRef&utm_source=838a08a2f4c39fa3fd218b1b2d43f19a" 197 | }, 198 | { 199 | "type": "wiki", 200 | "url": "http://marvel.com/universe/3-D_Man_(Chandler)?utm_campaign=apiRef&utm_source=838a08a2f4c39fa3fd218b1b2d43f19a" 201 | }, 202 | { 203 | "type": "comiclink", 204 | "url": "http://marvel.com/comics/characters/1011334/3-d_man?utm_campaign=apiRef&utm_source=838a08a2f4c39fa3fd218b1b2d43f19a" 205 | } 206 | ] 207 | } 208 | ] 209 | } 210 | } -------------------------------------------------------------------------------- /MarvelApiClient/src/test/resources/getComic.json: -------------------------------------------------------------------------------- 1 | { 2 | "code": 200, 3 | "status": "Ok", 4 | "copyright": "© 2015 MARVEL", 5 | "attributionText": "Data provided by Marvel. © 2015 MARVEL", 6 | "attributionHTML": "Data provided by Marvel. © 2015 MARVEL", 7 | "etag": "55122b303dfbc9fdfd12c080eded740b83354269", 8 | "data": { 9 | "offset": 0, 10 | "limit": 20, 11 | "total": 1, 12 | "count": 1, 13 | "results": [ 14 | { 15 | "id": 42882, 16 | "digitalId": 26110, 17 | "title": "Lorna the Jungle Girl (1954) #6", 18 | "issueNumber": 6, 19 | "variantDescription": "variant", 20 | "description": "description", 21 | "modified": "2015-10-15T11:13:52-0400", 22 | "isbn": "1", 23 | "upc": "2", 24 | "diamondCode": "5", 25 | "ean": "3", 26 | "issn": "4", 27 | "format": "Comic", 28 | "pageCount": 32, 29 | "textObjects": [ 30 | { 31 | "type": "issue_solicit_text", 32 | "language": "en-us", 33 | "text": "From the award-winning team that brought you Daredevil and Spider-Woman comes another explosive chapter of one of the most controversial creator-owned comics being published today. Scarlet has declared war on a city that refuses to stop the corruption that is strangling it from within, and now she'll be forced to make her most dangerous move yet: letting them capture her." 34 | } 35 | ], 36 | "resourceURI": "http://gateway.marvel.com/v1/public/comics/42882", 37 | "urls": [ 38 | { 39 | "type": "detail", 40 | "url": "http://marvel.com/comics/issue/42882/lorna_the_jungle_girl_1954_6?utm_campaign=apiRef&utm_source=838a08a2f4c39fa3fd218b1b2d43f19a" 41 | }, 42 | { 43 | "type": "reader", 44 | "url": "http://marvel.com/digitalcomics/view.htm?iid=26110&utm_campaign=apiRef&utm_source=838a08a2f4c39fa3fd218b1b2d43f19a" 45 | } 46 | ], 47 | "series": { 48 | "resourceURI": "http://gateway.marvel.com/v1/public/series/16355", 49 | "name": "Lorna the Jungle Girl (1954 - 1957)" 50 | }, 51 | "variants": [], 52 | "collections": [], 53 | "collectedIssues": [], 54 | "dates": [ 55 | { 56 | "type": "onsaleDate", 57 | "date": "2054-03-01T00:00:00-0500" 58 | }, 59 | { 60 | "type": "focDate", 61 | "date": "-0001-11-30T00:00:00-0500" 62 | }, 63 | { 64 | "type": "unlimitedDate", 65 | "date": "2012-04-13T00:00:00-0400" 66 | } 67 | ], 68 | "prices": [ 69 | { 70 | "type": "printPrice", 71 | "price": 0 72 | } 73 | ], 74 | "thumbnail": { 75 | "path": "http://i.annihil.us/u/prod/marvel/i/mg/9/40/50b4fc783d30f", 76 | "extension": "jpg" 77 | }, 78 | "images": [ 79 | { 80 | "path": "http://i.annihil.us/u/prod/marvel/i/mg/9/40/50b4fc783d30f", 81 | "extension": "jpg" 82 | } 83 | ], 84 | "creators": { 85 | "available": 1, 86 | "collectionURI": "http://gateway.marvel.com/v1/public/comics/41530/creators", 87 | "items": [ 88 | { 89 | "resourceURI": "http://gateway.marvel.com/v1/public/creators/4430", 90 | "name": "Jeff Youngquist", 91 | "role": "editor" 92 | } 93 | ], 94 | "returned": 1 95 | }, 96 | "characters": { 97 | "available": 0, 98 | "collectionURI": "http://gateway.marvel.com/v1/public/comics/42882/characters", 99 | "items": [], 100 | "returned": 0 101 | }, 102 | "stories": { 103 | "available": 1, 104 | "collectionURI": "http://gateway.marvel.com/v1/public/comics/42882/stories", 105 | "items": [ 106 | { 107 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/106292", 108 | "name": "cover from Lorna the Jungle Girl #6", 109 | "type": "cover" 110 | } 111 | ], 112 | "returned": 1 113 | }, 114 | "events": { 115 | "available": 0, 116 | "collectionURI": "http://gateway.marvel.com/v1/public/comics/42882/events", 117 | "items": [], 118 | "returned": 0 119 | } 120 | } 121 | ] 122 | } 123 | } -------------------------------------------------------------------------------- /MarvelApiClient/src/test/resources/getSeries.json: -------------------------------------------------------------------------------- 1 | { 2 | "code": 200, 3 | "status": "Ok", 4 | "copyright": "© 2015 MARVEL", 5 | "attributionText": "Data provided by Marvel. © 2015 MARVEL", 6 | "attributionHTML": "Data provided by Marvel. © 2015 MARVEL", 7 | "etag": "55122b303dfbc9fdfd12c080eded740b83354269", 8 | "data": { 9 | "offset": 0, 10 | "limit": 20, 11 | "total": 1, 12 | "count": 1, 13 | "results": [ 14 | { 15 | "id": 15276, 16 | "title": "5 Ronin (2011)", 17 | "description": "description", 18 | "resourceURI": "http://gateway.marvel.com/v1/public/series/15276", 19 | "urls": [ 20 | { 21 | "type": "detail", 22 | "url": "http://marvel.com/comics/series/15276/5_ronin_2011?utm_campaign=apiRef&utm_source=838a08a2f4c39fa3fd218b1b2d43f19a" 23 | } 24 | ], 25 | "startYear": 2011, 26 | "endYear": 2011, 27 | "rating": "+18", 28 | "type": "", 29 | "modified": "2011-05-20T16:25:29-0400", 30 | "thumbnail": { 31 | "path": "http://i.annihil.us/u/prod/marvel/i/mg/b/40/image_not_available", 32 | "extension": "jpg" 33 | }, 34 | "creators": { 35 | "available": 8, 36 | "collectionURI": "http://gateway.marvel.com/v1/public/series/15276/creators", 37 | "items": [ 38 | { 39 | "resourceURI": "http://gateway.marvel.com/v1/public/creators/750", 40 | "name": "David Aja", 41 | "role": "penciller (cover)" 42 | }, 43 | { 44 | "resourceURI": "http://gateway.marvel.com/v1/public/creators/162", 45 | "name": "John Cassaday", 46 | "role": "penciller (cover)" 47 | }, 48 | { 49 | "resourceURI": "http://gateway.marvel.com/v1/public/creators/645", 50 | "name": "Laurence Campbell", 51 | "role": "penciller" 52 | }, 53 | { 54 | "resourceURI": "http://gateway.marvel.com/v1/public/creators/1421", 55 | "name": "Tomm Coker", 56 | "role": "penciller" 57 | }, 58 | { 59 | "resourceURI": "http://gateway.marvel.com/v1/public/creators/273", 60 | "name": "Leandro Fernandez", 61 | "role": "penciller" 62 | }, 63 | { 64 | "resourceURI": "http://gateway.marvel.com/v1/public/creators/10082", 65 | "name": "Dalibor Talajic", 66 | "role": "penciller" 67 | }, 68 | { 69 | "resourceURI": "http://gateway.marvel.com/v1/public/creators/94", 70 | "name": "Peter Milligan", 71 | "role": "writer" 72 | }, 73 | { 74 | "resourceURI": "http://gateway.marvel.com/v1/public/creators/4430", 75 | "name": "Jeff Youngquist", 76 | "role": "artist" 77 | } 78 | ], 79 | "returned": 8 80 | }, 81 | "characters": { 82 | "available": 4, 83 | "collectionURI": "http://gateway.marvel.com/v1/public/series/15276/characters", 84 | "items": [ 85 | { 86 | "resourceURI": "http://gateway.marvel.com/v1/public/characters/1009268", 87 | "name": "Deadpool" 88 | }, 89 | { 90 | "resourceURI": "http://gateway.marvel.com/v1/public/characters/1009351", 91 | "name": "Hulk" 92 | }, 93 | { 94 | "resourceURI": "http://gateway.marvel.com/v1/public/characters/1009515", 95 | "name": "Punisher" 96 | }, 97 | { 98 | "resourceURI": "http://gateway.marvel.com/v1/public/characters/1009718", 99 | "name": "Wolverine" 100 | } 101 | ], 102 | "returned": 4 103 | }, 104 | "stories": { 105 | "available": 12, 106 | "collectionURI": "http://gateway.marvel.com/v1/public/series/15276/stories", 107 | "items": [ 108 | { 109 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/80038", 110 | "name": "Interior #80038", 111 | "type": "interiorStory" 112 | }, 113 | { 114 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/80039", 115 | "name": "5 Ronin #5", 116 | "type": "cover" 117 | }, 118 | { 119 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/80052", 120 | "name": "5 RONIN 3 AJA COVER ", 121 | "type": "interiorStory" 122 | }, 123 | { 124 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/80748", 125 | "name": "5 Ronin #2", 126 | "type": "cover" 127 | }, 128 | { 129 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/80749", 130 | "name": "5 Ronin #2", 131 | "type": "interiorStory" 132 | }, 133 | { 134 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/89879", 135 | "name": "5 Ronin #1", 136 | "type": "cover" 137 | }, 138 | { 139 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/89880", 140 | "name": "5 Ronin #1 ", 141 | "type": "interiorStory" 142 | }, 143 | { 144 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/90212", 145 | "name": "5 Ronin #3 Aja Cover", 146 | "type": "cover" 147 | }, 148 | { 149 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/90349", 150 | "name": "5 Ronin #4", 151 | "type": "cover" 152 | }, 153 | { 154 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/90404", 155 | "name": "5 Ronin #5", 156 | "type": "interiorStory" 157 | }, 158 | { 159 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/93074", 160 | "name": "5 Ronin HC", 161 | "type": "cover" 162 | }, 163 | { 164 | "resourceURI": "http://gateway.marvel.com/v1/public/stories/93075", 165 | "name": "5 Ronin HC DM Only Variant", 166 | "type": "cover" 167 | } 168 | ], 169 | "returned": 12 170 | }, 171 | "comics": { 172 | "available": 2, 173 | "collectionURI": "http://gateway.marvel.com/v1/public/series/15276/comics", 174 | "items": [ 175 | { 176 | "resourceURI": "http://gateway.marvel.com/v1/public/comics/41112", 177 | "name": "5 Ronin (Hardcover)" 178 | }, 179 | { 180 | "resourceURI": "http://gateway.marvel.com/v1/public/comics/41113", 181 | "name": "5 Ronin (Hardcover)" 182 | } 183 | ], 184 | "returned": 2 185 | }, 186 | "events": { 187 | "available": 0, 188 | "collectionURI": "http://gateway.marvel.com/v1/public/series/15276/events", 189 | "items": [], 190 | "returned": 0 191 | }, 192 | "next": null, 193 | "previous": null 194 | } 195 | ] 196 | } 197 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Karumi logo][karumilogo] Marvel Api Client written in Java [![Build Status](https://travis-ci.org/Karumi/MarvelApiClientAndroid.svg?branch=master)](https://travis-ci.org/Karumi/MarvelApiClientAndroid) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.karumi/marvelapiclient/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.karumi/marvelapiclient) 2 | ========================== 3 | 4 | 5 | This is an implementation written in Java for the [Mavel Api][marvelApi]. This library is implemented using Java 7 and it is fully compatible with Android. 6 | 7 | **IMPORTANT**: This library is under development. 8 | 9 | Usage 10 | ----- 11 | 12 | **Prerequisites**: You need to obtain valid Marvel keys for using this library. You can obtain it from [Marvel] [marvelAuthorization] 13 | 14 | To start using the library you just need to create a valid MarvelApiConfiguration: 15 | 16 | ```java 17 | MarvelApiConfig marvelApiConfig = new MarvelApiConfig.Builder(publicKey, privateKey).debug().build(); 18 | ``` 19 | 20 | Once you have configured your Marvel api, you can use this object to obtain information from the Marvel Api. 21 | 22 | ### Characters Api 23 | 24 | ``CharacterApiClient`` contains all operations used to retrieve characters from the Marvel Api. If you want to perform complex queries you can use ``CharactersQuery`` object. 25 | 26 | ```java 27 | CharacterApiClient characterApiClient = new CharacterApiClient(marvelApiConfig); 28 | CharactersQuery spider = CharactersQuery.Builder.create().withOffset(0).withLimit(10).build(); 29 | MarvelResponse all = characterApiClient.getAll(spider); 30 | ``` 31 | 32 | ### Comics Api 33 | 34 | ``ComicApiClient`` contains all operations used to retrieve comics from the Marvel Api. If you want to perform complex queries you can use ``ComicsQuery`` object. 35 | 36 | ```java 37 | ComicApiClient comicApiClient = new ComicApiClient(marvelApiConfig); 38 | ComicsQuery query = ComicsQuery.Builder.create().withOffset(0).withLimit(10).build(); 39 | MarvelResponse all = comicApiClient.getAll(query); 40 | ``` 41 | 42 | ### Series Api 43 | 44 | ``SeriesApiClient`` contains all operations used to retrieve series from the Marvel Api. If you want to perform complex queries you can use ``SeriesQuery`` object. 45 | 46 | ```java 47 | SeriesApiClient seriesApiClient = new SeriesApiClient(marvelApiConfig); 48 | SeriesQuery query = SeriesQuery.Builder.create().withOffset(0).withLimit(10).build(); 49 | MarvelResponse all = seriesApiClient.getAll(query); 50 | ``` 51 | 52 | Add it to your project 53 | ---------------------- 54 | 55 | Include the library in your ``build.gradle`` 56 | 57 | ```groovy 58 | dependencies{ 59 | compile 'com.karumi:marvelapiclient:1.0.1' 60 | } 61 | ``` 62 | 63 | or to your ``pom.xml`` if you are using Maven 64 | 65 | ```xml 66 | 67 | com.karumi 68 | marvelapiclient 69 | 1.0.1 70 | jar 71 | 72 | 73 | ``` 74 | Do you want to contribute? 75 | -------------------------- 76 | 77 | Feel free to add any useful feature to the library, we will be glad to improve it with your help. 78 | 79 | Keep in mind that your PRs **must** be validated by Travis-CI. Please, run a local build with ``./gradlew checkstyle assemble test`` before submiting your code. 80 | 81 | 82 | Libraries used in this project 83 | ------------------------------ 84 | 85 | * [OkHttp] [okHttp] 86 | * [Retrofit] [retrofit] 87 | * [JUnit] [junit] 88 | * [Mockito] [mockito] 89 | * [mockwebserver] [mockwebserver] 90 | 91 | License 92 | ------- 93 | 94 | Copyright 2015 Karumi 95 | 96 | Licensed under the Apache License, Version 2.0 (the "License"); 97 | you may not use this file except in compliance with the License. 98 | You may obtain a copy of the License at 99 | 100 | http://www.apache.org/licenses/LICENSE-2.0 101 | 102 | Unless required by applicable law or agreed to in writing, software 103 | distributed under the License is distributed on an "AS IS" BASIS, 104 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 105 | See the License for the specific language governing permissions and 106 | limitations under the License. 107 | 108 | 109 | Data provided by Marvel. © 2014 Marvel 110 | 111 | [marvelApi]: http://developer.marvel.com/ 112 | [marvelAuthorization]: http://developer.marvel.com/documentation/authorization 113 | [okHttp]: https://github.com/square/okhttp 114 | [retrofit]: https://github.com/square/retrofit 115 | [junit]: https://github.com/junit-team/junit 116 | [mockito]: https://github.com/mockito/mockito 117 | [mockwebserver]: https://github.com/square/okhttp/tree/master/mockwebserver 118 | [karumilogo]: https://cloud.githubusercontent.com/assets/858090/11626547/e5a1dc66-9ce3-11e5-908d-537e07e82090.png 119 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | title: "MarvelApiClientAndroid" 2 | baseurl: /MarvelApiClientAndroid 3 | remote_theme: Karumi/KarumiJekyllTheme 4 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | apply plugin: 'java' 17 | apply plugin: 'checkstyle' 18 | 19 | repositories { 20 | mavenCentral() 21 | } 22 | 23 | task checkstyle(type: Checkstyle) { 24 | configFile file("${project.rootDir}/config/checkstyle/checkstyle.xml") 25 | source 'src' 26 | include '**/*.java' 27 | exclude '**/gen/**' 28 | 29 | classpath = files() 30 | } 31 | -------------------------------------------------------------------------------- /config/checkstyle/checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 20 | 21 | 22 | 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 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015 Karumi. 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | POM_NAME=marvelapiclient 16 | POM_ARTIFACT_ID=marvelapiclient 17 | POM_PACKAGING=jar 18 | VERSION_NAME=1.0.2-SNAPSHOT 19 | VERSION_CODE=100002 20 | GROUP=com.karumi 21 | POM_DESCRIPTION=Marve API Client written in Java. 22 | POM_URL=https://github.com/Karumi/MarvelApiClientAndroid 23 | POM_SCM_URL=https://github.com/Karumi/MarvelApiClientAndroid 24 | POM_SCM_CONNECTION=scm:git@github.com:karumi/MarvelApiClientAndroid 25 | POM_SCM_DEV_CONNECTION=scm:git@github.com:karumi/MarvelApiClientAndroid 26 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 27 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 28 | POM_LICENCE_DIST=repo 29 | POM_DEVELOPER_ID=karumi 30 | POM_DEVELOPER_NAME=Karumi -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Karumi/MarvelApiClientAndroid/39fef861715b325e2eee00a6845f7e348c1249e2/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Nov 20 11:50:38 CET 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | apply plugin: 'java' 17 | 18 | sourceCompatibility = 1.7 19 | 20 | repositories { 21 | mavenCentral() 22 | } 23 | 24 | dependencies { 25 | testCompile group: 'junit', name: 'junit', version: '4.12' 26 | compile project(':MarvelApiClient') 27 | } 28 | -------------------------------------------------------------------------------- /sample/src/main/java/com/karumi/marvelapiclient/sample/MarveApiClientDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.karumi.marvelapiclient.sample; 17 | 18 | import com.karumi.marvelapiclient.CharacterApiClient; 19 | import com.karumi.marvelapiclient.ComicApiClient; 20 | import com.karumi.marvelapiclient.MarvelApiConfig; 21 | import com.karumi.marvelapiclient.MarvelApiException; 22 | import com.karumi.marvelapiclient.SeriesApiClient; 23 | import com.karumi.marvelapiclient.model.CharacterDto; 24 | import com.karumi.marvelapiclient.model.CharactersDto; 25 | import com.karumi.marvelapiclient.model.CharactersQuery; 26 | import com.karumi.marvelapiclient.model.ComicDto; 27 | import com.karumi.marvelapiclient.model.ComicsDto; 28 | import com.karumi.marvelapiclient.model.MarvelResponse; 29 | import com.karumi.marvelapiclient.model.SeriesDto; 30 | import com.karumi.marvelapiclient.model.SeriesCollectionDto; 31 | 32 | public class MarveApiClientDemo { 33 | public static void main(String[] args) { 34 | if (args.length < 3) { 35 | System.out.println("MarveApiClientDemo [publicKey] [privateKey] [operation]"); 36 | } 37 | String publicKey = args[0]; 38 | String privateKey = args[1]; 39 | String operation = args[2]; 40 | 41 | MarvelApiConfig marvelApiConfig = 42 | new MarvelApiConfig.Builder(publicKey, privateKey).debug().build(); 43 | 44 | try { 45 | if (operation.equals("getCharacters")) { 46 | CharacterApiClient characterApiClient = new CharacterApiClient(marvelApiConfig); 47 | CharactersQuery spider = 48 | CharactersQuery.Builder.create().withOffset(0).withLimit(10).build(); 49 | MarvelResponse all = characterApiClient.getAll(spider); 50 | System.out.println(all.toString()); 51 | } else if (operation.equals("getCharacter")) { 52 | CharacterApiClient characterApiClient = new CharacterApiClient(marvelApiConfig); 53 | MarvelResponse character = characterApiClient.getCharacter("1011334"); 54 | System.out.println(character.toString()); 55 | } else if (operation.equals("getComics")) { 56 | ComicApiClient comicApiClient = new ComicApiClient(marvelApiConfig); 57 | MarvelResponse comics = comicApiClient.getAll(0, 10); 58 | System.out.println(comics.toString()); 59 | } else if (operation.equals("getComic")) { 60 | ComicApiClient comicApiClient = new ComicApiClient(marvelApiConfig); 61 | MarvelResponse comic = comicApiClient.getComic("42882"); 62 | System.out.println(comic.toString()); 63 | } else if (operation.equals("getSeries")) { 64 | SeriesApiClient seriesApiClient = new SeriesApiClient(marvelApiConfig); 65 | MarvelResponse series = seriesApiClient.getAll(0, 10); 66 | System.out.println(series.toString()); 67 | } else if (operation.equals("getSeriesById")) { 68 | SeriesApiClient seriesApiClient = new SeriesApiClient(marvelApiConfig); 69 | MarvelResponse serie = seriesApiClient.getSeriesById("15276"); 70 | System.out.println(serie.toString()); 71 | } 72 | } catch (MarvelApiException e) { 73 | System.out.println("An error calling the Marvel Api " + e); 74 | e.printStackTrace(); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Karumi. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | include 'MarvelApiClient', 'sample' 17 | 18 | --------------------------------------------------------------------------------