本文整理汇总了Java中us.monoid.web.JSONResource类的典型用法代码示例。如果您正苦于以下问题:Java JSONResource类的具体用法?Java JSONResource怎么用?Java JSONResource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JSONResource类属于us.monoid.web包,在下文中一共展示了JSONResource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getJSON
import us.monoid.web.JSONResource; //导入依赖的package包/类
/**
* @param url
* @return Returns the JSON
*/
private String getJSON(String url){
JSONResource res = null;
JSONObject obj = null;
Resty resty = new Resty();
try {
res = resty.json(url);
obj = res.toObject();
} catch (IOException | JSONException e) {
// TODO: not my favorite way but does the trick
// e.printStackTrace();
return getJSON(url);
}
return obj.toString();
}
示例2: nextPage
import us.monoid.web.JSONResource; //导入依赖的package包/类
/**
* Attempt to request the next page using the next link from the current page
* @return a BundleSearchResults representing the next page, or null if there are no other pages
* @throws JSONException if the href for the next link could not be obtained for some reason
* @throws IOException if a network failure occurred while fetching the next page
*/
public BundleSearchResults nextPage() throws JSONException, IOException {
if(!hasNextPage()) {
return null;
}
JSONObject nextLink = nextLink();
if(nextLink != null) {
String href = (String)nextLink.get("href");
JSONResource jsonResource =
client.json(client.buildPathFromHref(href));
ClarifyResponse resp = new ClarifyResponse(jsonResource);
BundleSearchResults results = new BundleSearchResults(client, resp);
return results;
}
return null;
}
示例3: nextPage
import us.monoid.web.JSONResource; //导入依赖的package包/类
/**
* Attempt to request the next page using the next link from the current page
* @return a BundleList representing the next page, or null if there are no other pages
* @throws JSONException if the href for the next link could not be obtained for some reason
* @throws IOException if a network failure occurred while fetching the next page
*/
public BundleList nextPage() throws JSONException, IOException {
if(!hasNextPage()) {
return null;
}
JSONObject nextLink = nextLink();
if(nextLink != null) {
String href = (String)nextLink.get("href");
JSONResource jsonResource =
client.json(client.buildPathFromHref(href));
ClarifyResponse resp = new ClarifyResponse(jsonResource);
BundleList list = new BundleList(client, resp);
return list;
}
return null;
}
示例4: createBundle
import us.monoid.web.JSONResource; //导入依赖的package包/类
/**
* Creates a new Clarify Bundle using the Create Bundle REST API using a name, initial media URL, and any number of
* additional fields (as defined by the Clarify Create Bundle API).
*
* @param name a string containing the name of the API bundle
* @param mediaURI a URI containing a valid URL where the media for this Bundle resides
* @param fields a Map of key-value String pairs with any additional parameter values. This value may be null or empty if no additional
* parameters are desired
* @return the newly created Bundle instance
* @throws IOException on a non-success HTTP response containing the JSON payload with the message and any error details
*/
public Bundle createBundle(String name, URI mediaURI, Map<String,String> fields) throws IOException {
if(name == null) { throw new RuntimeException("name cannot be null"); }
if(fields == null) {
// create a new, empty map
fields = new HashMap<String,String>();
}
// load the name and mediaURI into the map (overwriting these two keys that may already be assigned)
fields.put("name",name);
if(mediaURI != null) { fields.put("media_url", mediaURI.toString()); }
String params = urlEncodeMap(fields);
Content content = new Content("application/x-www-form-urlencoded", params.getBytes());
JSONResource jsonResource =
json(buildPathFromResourcePath("/bundles"), content);
String bundleId;
try {
bundleId = (String)jsonResource.get("id");
return findBundle(bundleId);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例5: searchBundles
import us.monoid.web.JSONResource; //导入依赖的package包/类
/**
* Performs an advanced search for the specific query string provided using the additional search query parameters provided.
* See the Search Bundles API documentation for the various fields, filters, and other parameters available.
*
* The result can be used to examine the matched terms, locations within the media file where the terms reside, and paginate through the
* results.
*
* @param query a raw string (automatically URL encoded) containing the query string to search for within the bundles
* @param params a Map of key-value String pairs to pass to the search API. May be nill or empty if no additional parameters are to be provided
* @return a BundleSearchResults instance for examining the results and paginating through the search results
* @throws IOException on a non-success HTTP response containing the JSON payload with the message and any error details
*/
public BundleSearchResults searchBundles(String query, Map<String,String> params) throws IOException {
if(query == null) { throw new RuntimeException("query cannot be null"); }
if(params == null) {
// create a new, empty map
params = new HashMap<String,String>();
}
// load the name and mediaURI into the map (overwriting these two keys that may already be assigned)
params.put("query",enc(query));
String urlParams = urlEncodeMap(params);
JSONResource jsonResource =
json(buildPathFromResourcePath("/search?"+urlParams));
ClarifyResponse resp = new ClarifyResponse(jsonResource);
BundleSearchResults results = new BundleSearchResults(this, resp);
return results;
}
示例6: updateMetadata
import us.monoid.web.JSONResource; //导入依赖的package包/类
/**
* Updates the user-defined data property of the Bundle's Metadata with the supplied JSON string,
* then return a refreshed copy (resulting in 2 API calls)
* @param bundleId the GUID of the Bundle for updating the Metadata
* @param json a String containing valid JSON, or null. If null is passed, then the data is reset to a JSON equiv of {}
* @return a refreshed Metadata instance for the media bundle
* @throws IOException if a failure occurred during the API,
* typically a 4xx HTTP error code + JSON payload with the error message and details
*/
public BundleMetadata updateMetadata(String bundleId, String json) throws IOException {
if(bundleId == null) {
throw new RuntimeException("bundleId cannot be null");
}
if(json == null) {
json = "{}";
}
// wrap the request in a JSON payload with a data property that contains the user JSON data to update
JSONObject payload = null;
try {
payload = new JSONObject().put("data", json);
} catch (JSONException e) {
throw new RuntimeException(e);
}
JSONResource jsonResource =
json(buildPathFromResourcePath("/bundles/"+bundleId+"/metadata"), put(content(payload)));
// re-retrieve
return findMetadata(bundleId);
}
示例7: isTokenValid
import us.monoid.web.JSONResource; //导入依赖的package包/类
private boolean isTokenValid(String token) {
if (token == null) {
return false;
}
boolean isValid = false;
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put(TOKEN, token);
JSONResource response = resty.json(urlHelper.getTokenAuthenticationUrl(), RestyHelper.content(jsonObject,APPLICATION_JSON));
if (response != null) {
if (HttpStatus.SC_OK == (response.getHTTPStatus())) {
isValid = true;
} else {
LOGGER.info("Inavlid token with failure reason from id server:" + response.get(MESSAGE));
}
}
} catch (Exception e) {
LOGGER.error("Failed to valid token:" + token, e);
}
return isValid;
}
示例8: createPlayer
import us.monoid.web.JSONResource; //导入依赖的package包/类
public static OnlinePlayer createPlayer(boolean playing) throws RageGoServerException{
try{
final JSONResource resource = getInstance().json(getPlayersURL(), form(data("player[playing]", playing ? "1" : "0")));
final OnlinePlayer onlinePlayer = OnlinePlayer.loadFromJSON(resource.object());
players.put(onlinePlayer.getId(), onlinePlayer);
return onlinePlayer;
} catch (Exception e){
throw handleException(e);
}
}
示例9: createGame
import us.monoid.web.JSONResource; //导入依赖的package包/类
public static OnlineGame createGame(OnlinePlayer blacks, OnlinePlayer whites) throws RageGoServerException{
try {
final JSONResource resource = getInstance().json(getGamesURL(),
form(
data("game[whites_id]", String.valueOf(whites.getId())),
data("game[blacks_id]", String.valueOf(blacks.getId()))
));
final OnlineGame onlineGame = new OnlineGame(resource.object().getInt("id"), whites, blacks);
games.put(onlineGame.getId(), onlineGame);
return onlineGame;
} catch (Exception e){
throw handleException(e);
}
}
示例10: cubesAdapterQuery
import us.monoid.web.JSONResource; //导入依赖的package包/类
public List<Measurement> cubesAdapterQuery(String bindedSystem, String cubeName, String queryExpression) throws uQasarException{
URI uri = null;
LinkedList<Measurement> measurements = new LinkedList<>();
try {
uri = new URI(bindedSystem + "/" + queryExpression);
String url = uri.toASCIIString();
JSONResource res = getJSON(url);
us.monoid.json.JSONObject json = res.toObject();
logger.info(json.toString());
JSONArray measurementResultJSONArray = new JSONArray();
JSONObject bp = new JSONObject();
bp.put("self", url);
bp.put("key", cubeName);
bp.put("name", queryExpression);
measurementResultJSONArray.put(bp);
logger.info(measurementResultJSONArray.toString());
measurements.add(new Measurement(uQasarMetric.PROJECTS_PER_SYSTEM_INSTANCE, measurementResultJSONArray.toString()));
} catch (URISyntaxException | org.apache.wicket.ajax.json.JSONException | JSONException | IOException e) {
e.printStackTrace();
}
return measurements;
}
示例11: getJSON
import us.monoid.web.JSONResource; //导入依赖的package包/类
/**
* @param url
* @return Returns the JSON as JSON Resource
*/
private JSONResource getJSON(String url) throws uQasarException{
JSONResource res = null;
Resty resty = new Resty();
// Connection counter +1
counter +=1;
// Replaces spaces in URL with char %20
url = url.replaceAll(" ", "%20");
try {
res = resty.json(url);
} catch (IOException e) {
// Check if the limit of trials has been reached
if(counter<counterLimit){
return getJSON(url);} else
throw new uQasarException("Cubes Server is not availabe at this moument, error to connect with " +url);
}
// Reset the connection counter to 0
counter = 0;
return res;
}
示例12: printEJSON
import us.monoid.web.JSONResource; //导入依赖的package包/类
private void printEJSON(JSONResource jsonResult){
try {
String result = (boolean) jsonResult.get("success") ? "Succeed" : "Failed";
System.out.println("EJSON: " + jsonResult.get("message") + ", " + result);
} catch (Throwable e) {
System.out.println(e.getMessage());
}
}
示例13: findBundleByHref
import us.monoid.web.JSONResource; //导入依赖的package包/类
/**
* Uses the Retrieve Bundle API to return a specific Bundle by the specific relative href path
*
* @param href a String containing the relative href path of the Bundle to attempt to retrieve, as returned by the Clarify API
* @return the Bundle retrieved by bundleId
* @throws IOException if a HTTP 400 error is returned due to a malformed GUID, or if a HTTP 404 not found is returned.
* The response will contain a JSON payload with a message and error details
*/
public Bundle findBundleByHref(String href) throws IOException {
if(href == null) {
throw new RuntimeException("href cannot be null");
}
JSONResource jsonResource =
json(buildPathFromHref(href));
ClarifyResponse resp = new ClarifyResponse(jsonResource);
Bundle bundle = new Bundle(this, resp);
return bundle;
}
示例14: findBundle
import us.monoid.web.JSONResource; //导入依赖的package包/类
/**
* Uses the Retrieve Bundle API to return a specific Bundle by the specific bundleId
*
* @param bundleId a String containing the GUID of the Bundle to attempt to retrieve
* @return the Bundle retrieved by bundleId
* @throws IOException if a HTTP 400 error is returned due to a malformed GUID, or if a HTTP 404 not found is returned.
* The response will contain a JSON payload with a message and error details
*/
public Bundle findBundle(String bundleId) throws IOException {
if(bundleId == null) {
throw new RuntimeException("bundleId cannot be null");
}
JSONResource jsonResource =
json(buildPathFromResourcePath("/bundles/"+bundleId));
ClarifyResponse resp = new ClarifyResponse(jsonResource);
Bundle bundle = new Bundle(this, resp);
return bundle;
}
示例15: listTracksForBundle
import us.monoid.web.JSONResource; //导入依赖的package包/类
/**
* Returns the list of Tracks associated to this media Bundle
* @param bundleId the GUID of the Bundle to retrieve the Tracks for
* @return a BundleTrackList with the list of tracks and related details
* @throws IOException if a failure occurred during the API,
* typically a 4xx HTTP error code + JSON payload with the error message and details
*/
public BundleTrackList listTracksForBundle(String bundleId) throws IOException {
if(bundleId == null) {
throw new RuntimeException("bundleId cannot be null");
}
JSONResource jsonResource =
json(buildPathFromResourcePath("/bundles/"+bundleId+"/tracks"));
ClarifyResponse resp = new ClarifyResponse(jsonResource);
BundleTrackList trackList = new BundleTrackList(this, resp);
return trackList;
}