The Marketplace API Java client lets you get information about an app through the Addons API.
For a stand-alone demo, see GetAddon.java in the Marketplace API Tutorials repository.
You will need:
marketplace-client-java libraryMarketplaceClient objectThe getByKey method of the Addons API queries the details of an app given its app key. It returns an Option containing an Addon object, or Option.none() if the app key was not found:
1 2Option<Addon> result = client.addons().getByKey("my.excellent.app", AddonQuery.any()); // Option implements Iterable, so we can use "for" to execute this code only if it has a value for (Addon a: result) { System.out.println("I found the app; its name is " + a.getName()); } if (!result.isDefined()) { System.out.println("not found"); }
Remember that we specified the default option (AddonQuery.any()) in the example above. One way to vary the query is to ask for the current app version at the same time:
1 2AddonQuery query = AddonQuery.builder(). withVersion(true). build(); Option<Addon> result = client.addons().getByKey("my.excellent.app", query); for (Addon a: result) { System.out.println("I found the app; its name is " + a.getName()); for (AddonVersion v: a.getVersion()) { System.out.println("And the latest version is " + v.getName()); } }
If you specify any other criteria in the AddonQuery, you will get the latest app version that matches those criteria. If there is no such version, the query will return nothing (not even the app). In this example, we are asking for the latest version that is compatible with Cloud:
1 2AddonQuery query = AddonQuery.builder(). hosting(Option.some(HostingType.CLOUD)). withVersion(true). build(); Option<Addon> result = client.addons().getByKey("my.excellent.app", query); for (Addon a: result) { System.out.println("I found the app; its name is " + a.getName()); for (AddonVersion v: a.getVersion()) { System.out.println("And the latest Cloud version is " + v.getName()); } }
Rate this page: