public List<MarketplaceConfiguration> getMarketplaceConfigurations(MnoHttpClient client) throws MnoConfigurationException { String string; try { string = client.get(getInstanceUrl()); } catch (MnoException e) { throw new MnoConfigurationException( "Could not retrieve the list of the marketplace: " + e.getMessage(), e); } Map<String, Object> fromJson; try { fromJson = GSON.fromJson(string, Map.class); } catch (JsonSyntaxException e) { throw new MnoConfigurationException( "Could not retrieve the list of the marketplace. The Json is invalid.", e); } if (fromJson.get("error") != null) { throw new MnoConfigurationException( "An error occurred while retrieving the marketplaces. Body content: " + fromJson.get("error")); } Collection<Object> marketplaces = (Collection<Object>) fromJson.get("marketplaces"); if (marketplaces == null) { throw new MnoConfigurationException( "An error occurred while retrieving the marketplaces. No marketplaces in the json answer"); } List<MarketplaceConfiguration> result = new ArrayList<MarketplaceConfiguration>(); for (Object marketplace : marketplaces) { Map<String, Object> castedMarketplace = (Map<String, Object>) marketplace; String name = (String) castedMarketplace.get("marketplace"); Properties properties = MnoPropertiesHelper.fromJson(marketplace); result.add(new MarketplaceConfiguration(name, properties)); } return result; }
private MnoHttpClient getAuthenticatedClient() { return MnoHttpClient.getAuthenticatedClient( devPlatformService.getApiKey(), devPlatformService.getApiSecret(), "application/vnd.api+json"); }