Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Country functionality to Lookup #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>be.ceau</groupId>
<artifactId>itunes-api</artifactId>
<version>4.1</version>
<version>4.1.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>iTunes API</name>
<description>Java client for the Apple iTunes APIs</description>
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/be/ceau/itunesapi/Lookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Map.Entry;
import java.util.Set;

import be.ceau.itunesapi.request.Country;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -60,6 +61,7 @@ public class Lookup implements Serializable {
private Entity entity;
private int limit;
private Sort sort;
private Country country;

/**
* No-arg constructor.
Expand Down Expand Up @@ -383,6 +385,23 @@ public Lookup setSort(Sort sort) {
return this;
}

/**
* @return {@link Country} instance, or {@code null}
*/
public Country getCountry() {
return country;
}

/**
* @param country
* {@link Country}, can be {@code null}
* @return {@code this} instance for method chaining
*/
public Lookup setCountry(Country country) {
this.country = country;
return this;
}

/**
* Create the request url for this {@link Lookup}
*
Expand Down Expand Up @@ -421,6 +440,12 @@ public String build() {
}
sb.append("sort").append("=").append(sort.toString());
}
if (country != null) {
if (sb.length() > 0) {
sb.append("&");
}
sb.append("country").append("=").append(country.getIso());
}
return API_ENDPOINT + sb.toString();
}

Expand Down
12 changes: 12 additions & 0 deletions src/test/java/be/ceau/itunesapi/LookupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package be.ceau.itunesapi;

import be.ceau.itunesapi.request.Country;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -45,4 +46,15 @@ public void albums() {
Assert.assertEquals(response.getResults().size(), response.getResultCount());
}

@Test
public void albumsFromUSStore() {
Response response = new Lookup()
.addId("178834")
.setEntity(Entity.ALBUM)
.setCountry(Country.UNITED_STATES)
.execute();
Assert.assertTrue(response.getResultCount() > 0);
Assert.assertEquals(response.getResults().size(), response.getResultCount());
}

}