Skip to content

Commit

Permalink
Implement storefront request type appuserdetails
Browse files Browse the repository at this point in the history
  • Loading branch information
lpradel committed Oct 25, 2016
1 parent 9fad956 commit 914e759
Show file tree
Hide file tree
Showing 10 changed files with 273 additions and 17 deletions.
10 changes: 10 additions & 0 deletions pom.xml
Expand Up @@ -285,6 +285,16 @@
<sourceDirectory>${basedir}/src/main/resources/com/lukaspradel/steamapi/schema/storefrontapi/appdetails</sourceDirectory>
</configuration>
</execution>
<execution>
<id>generate-storefrontapi-appuserdetails</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<targetPackage>com.lukaspradel.steamapi.data.json.appuserdetails</targetPackage>
<sourceDirectory>${basedir}/src/main/resources/com/lukaspradel/steamapi/schema/storefrontapi/appuserdetails</sourceDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
@@ -1,6 +1,7 @@
package com.lukaspradel.steamapi.storefrontapi.core;

import com.lukaspradel.steamapi.data.json.appdetails.Appdetails;
import com.lukaspradel.steamapi.data.json.appuserdetails.AppUserdetails;
import com.lukaspradel.steamapi.data.json.featured.Featured;
import com.lukaspradel.steamapi.data.json.featuredcategories.FeaturedCategories;

Expand All @@ -9,7 +10,7 @@ public enum SteamStorefrontApiMethod {
FEATURED("featured", Featured.class), FEATURED_CATEGORIES(
"featuredcategories", FeaturedCategories.class), APP_DETAILS(
"appdetails", Appdetails.class), APP_USER_DETAILS("appuserdetails",
Object.class), MESSAGES("messages", Object.class), PACKAGE_DETAILS(
AppUserdetails.class), MESSAGES("messages", Object.class), PACKAGE_DETAILS(
"packagedetails", Object.class), SALE_PAGE("salepage", Object.class);

private final String method;
Expand Down
@@ -0,0 +1,61 @@
package com.lukaspradel.steamapi.storefrontapi.request;

import java.util.List;

import com.lukaspradel.steamapi.storefrontapi.core.SteamStorefrontApiMethod;
import com.lukaspradel.steamapi.storefrontapi.request.builders.AbstractSteamStorefrontApiRequestBuilder;

/**
* Steam Web API Request appuserdetails
*
* @see <a href=
* "https://wiki.teamfortress.com/wiki/User:RJackson/StorefrontAPI#appuserdetails"
* >https://wiki.teamfortress.com/wiki/User:RJackson/StorefrontAPI#appuserdetails</a>
* @author lpradel
*
*/
public class AppUserdetailsRequest extends SteamStorefrontApiRequest {

private AppUserdetailsRequest(SteamStorefrontApiRequestBuilder builder) {
super(builder);
}

/**
* Builder object to create instances of {@link SteamStorefrontApiRequest}
* for request type {@link AppUserdetailsRequest}.
*
* @author lpradel
*
*/
public static class AppUserdetailsRequestBuilder extends
AbstractSteamStorefrontApiRequestBuilder {

private final List<Integer> appIds;

public static final String REQUEST_PARAM_APP_IDS = "appids";

public AppUserdetailsRequestBuilder(List<Integer> appIds) {

if (appIds.isEmpty()) {
throw new IllegalArgumentException(
"You must supply at least 1 App ID!");
}

this.appIds = appIds;
}

@Override
protected SteamStorefrontApiMethod getMethod() {

return SteamStorefrontApiMethod.APP_USER_DETAILS;
};

@Override
public AppUserdetailsRequest buildRequest() {

addListParameter(REQUEST_PARAM_APP_IDS, appIds);

return new AppUserdetailsRequest(this);
}
}
}
Expand Up @@ -38,18 +38,20 @@ protected void addParameter(String name, Integer value) {

/**
* Adds List-parameter as comma-separated strings
*
*
* @param <T>
* Type of the parameters (e.g. String, Integer, ...)
* @param name
* Name of the List-parameter
* @param valueList
* List of the comma-separated strings
*/
protected void addListParameter(String name, List<String> valueList) {
protected <T> void addListParameter(String name, List<T> valueList) {

StringBuilder paramValue = new StringBuilder();

for (String value : valueList) {
paramValue.append(value);
for (T value : valueList) {
paramValue.append(value.toString());
paramValue.append(",");
}
paramValue.setLength(paramValue.length() - 1);
Expand All @@ -61,17 +63,19 @@ protected void addListParameter(String name, List<String> valueList) {
* Adds Array-parameter as comma-separated array-strings. For example, an
* array parameter by the name of "param" with the values "val1, val2" would
* be written as "param[0]=val1,param[1]=val2".
*
*
* @param <T>
* Type of the parameters (e.g. String, Integer, ...)
* @param name
* Name of the Array-parameter
* @param valueList
* List of the comma-separated strings
*/
protected void addArrayParameter(String name, List<String> valueList) {
protected <T> void addArrayParameter(String name, List<T> valueList) {

int i = 0;

for (String value : valueList) {
for (T value : valueList) {

StringBuilder paramName = new StringBuilder();
StringBuilder paramValue = new StringBuilder();
Expand All @@ -81,7 +85,7 @@ protected void addArrayParameter(String name, List<String> valueList) {
paramName.append(i);
paramName.append("]");

paramValue.append(value);
paramValue.append(value.toString());

addParameter(paramName.toString(), paramValue.toString());

Expand Down
@@ -1,5 +1,9 @@
package com.lukaspradel.steamapi.storefrontapi.request.builders;

import java.util.List;

import com.lukaspradel.steamapi.storefrontapi.request.AppUserdetailsRequest;
import com.lukaspradel.steamapi.storefrontapi.request.AppUserdetailsRequest.AppUserdetailsRequestBuilder;
import com.lukaspradel.steamapi.storefrontapi.request.AppdetailsRequest;
import com.lukaspradel.steamapi.storefrontapi.request.AppdetailsRequest.AppdetailsRequestBuilder;
import com.lukaspradel.steamapi.storefrontapi.request.FeaturedCategoriesRequest;
Expand Down Expand Up @@ -31,4 +35,10 @@ public static AppdetailsRequest createAppdetailsRequest(int appIds) {

return new AppdetailsRequestBuilder(appIds).buildRequest();
}

public static AppUserdetailsRequest createAppUserdetailsRequest(
List<Integer> appIds) {

return new AppUserdetailsRequestBuilder(appIds).buildRequest();
}
}
Expand Up @@ -43,18 +43,20 @@ protected void addParameter(String name, Integer value) {

/**
* Adds List-parameter as comma-separated strings
*
*
* @param <T>
* Type of the parameters (e.g. String, Integer, ...)
* @param name
* Name of the List-parameter
* @param valueList
* List of the comma-separated strings
*/
protected void addListParameter(String name, List<String> valueList) {
protected <T> void addListParameter(String name, List<T> valueList) {

StringBuilder paramValue = new StringBuilder();

for (String value : valueList) {
paramValue.append(value);
for (T value : valueList) {
paramValue.append(value.toString());
paramValue.append(",");
}
paramValue.setLength(paramValue.length() - 1);
Expand All @@ -66,17 +68,19 @@ protected void addListParameter(String name, List<String> valueList) {
* Adds Array-parameter as comma-separated array-strings. For example, an
* array parameter by the name of "param" with the values "val1, val2" would
* be written as "param[0]=val1,param[1]=val2".
*
*
* @param <T>
* Type of the parameters (e.g. String, Integer, ...)
* @param name
* Name of the Array-parameter
* @param valueList
* List of the comma-separated strings
*/
protected void addArrayParameter(String name, List<String> valueList) {
protected <T> void addArrayParameter(String name, List<T> valueList) {

int i = 0;

for (String value : valueList) {
for (T value : valueList) {

StringBuilder paramName = new StringBuilder();
StringBuilder paramValue = new StringBuilder();
Expand All @@ -86,7 +90,7 @@ protected void addArrayParameter(String name, List<String> valueList) {
paramName.append(i);
paramName.append("]");

paramValue.append(value);
paramValue.append(value.toString());

addParameter(paramName.toString(), paramValue.toString());

Expand Down
@@ -0,0 +1,110 @@
{
"type":"object",
"required":false,
"javaType":"com.lukaspradel.steamapi.data.json.appuserdetails.AppUserdetails",
"additionalProperties":{
"type":"object",
"required":false,
"javaType":"com.lukaspradel.steamapi.data.json.appuserdetails.AppUserdetail",
"properties":{
"data":{
"type":"object",
"required":false,
"properties":{
"added_to_wishlist":{
"type":"boolean",
"required":false
},
"friendsown":{
"type":"array",
"required":false,
"items":{
"type":"object",
"required":false,
"properties":{
"playtime_total":{
"type":"integer",
"required":false
},
"playtime_twoweeks":{
"type":"integer",
"required":false
},
"steamid":{
"type":"string",
"required":false
}
}
}
},
"friendswant":{
"type":"array",
"required":false,
"items":{
"type":"object",
"required":false,
"properties":{
"playtime_total":{
"type":"integer",
"required":false
},
"playtime_twoweeks":{
"type":"integer",
"required":false
},
"steamid":{
"type":"string",
"required":false
}
}
}
},
"is_owned":{
"type":"boolean",
"required":false
},
"recommendations":{
"type":"object",
"required":false,
"properties":{
"friends":{
"type":"array",
"required":false,
"items":{
"type":"object",
"required":false,
"properties":{
"commentcount":{
"type":"integer",
"required":false
},
"recommendation":{
"type":"string",
"required":false
},
"steamid":{
"type":"string",
"required":false
},
"timestamp":{
"type":"integer",
"required":false
}
}
}
},
"totalfriends":{
"type":"integer",
"required":false
}
}
}
}
},
"success":{
"type":"boolean",
"required":false
}
}
}
}
Expand Up @@ -8,6 +8,8 @@
import static org.testng.Assert.fail;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.mockito.Mock;
import org.powermock.reflect.Whitebox;
Expand All @@ -18,8 +20,11 @@
import com.lukaspradel.steamapi.core.exception.SteamApiException;
import com.lukaspradel.steamapi.data.json.appdetails.App;
import com.lukaspradel.steamapi.data.json.appdetails.Appdetails;
import com.lukaspradel.steamapi.data.json.appuserdetails.AppUserdetail;
import com.lukaspradel.steamapi.data.json.appuserdetails.AppUserdetails;
import com.lukaspradel.steamapi.data.json.featured.Featured;
import com.lukaspradel.steamapi.data.json.featuredcategories.FeaturedCategories;
import com.lukaspradel.steamapi.storefrontapi.request.AppUserdetailsRequest;
import com.lukaspradel.steamapi.storefrontapi.request.AppdetailsRequest;
import com.lukaspradel.steamapi.storefrontapi.request.FeaturedCategoriesRequest;
import com.lukaspradel.steamapi.storefrontapi.request.FeaturedRequest;
Expand Down Expand Up @@ -200,4 +205,32 @@ public void testProcessAppdetailsRequest() throws SteamApiException,
assertNotNull(app.getData());
assertEquals(app.getData().getName(), "Borderlands 2");
}

@Test
public void testProcessAppUserdetailsRequest() throws SteamApiException,
IOException {

List<Integer> appIds = new ArrayList<Integer>();
appIds.add(49520);
appIds.add(570);

AppUserdetailsRequest appUserdetailsRequest = SteamStorefrontApiRequestFactory
.createAppUserdetailsRequest(appIds);

String mockAnswer = readResourceAsString("AppUserdetails.json");

when(requestHandlerMock.getStorefrontApiResponse(appUserdetailsRequest))
.thenReturn(mockAnswer);

AppUserdetails appUserdetails = client
.<AppUserdetails> processRequest(appUserdetailsRequest);

assertNotNull(appUserdetails);
AppUserdetail appUserdetail = appUserdetails.getAdditionalProperties()
.get("292030");
assertNotNull(appUserdetail);
assertTrue(appUserdetail.getSuccess());
assertNotNull(appUserdetail.getData());
assertTrue(appUserdetail.getData().getIsOwned());
}
}

0 comments on commit 914e759

Please sign in to comment.