当前位置: 首页>>代码示例>>Java>>正文


Java GetRequest.asJson方法代码示例

本文整理汇总了Java中com.mashape.unirest.request.GetRequest.asJson方法的典型用法代码示例。如果您正苦于以下问题:Java GetRequest.asJson方法的具体用法?Java GetRequest.asJson怎么用?Java GetRequest.asJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mashape.unirest.request.GetRequest的用法示例。


在下文中一共展示了GetRequest.asJson方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getChannelStats

import com.mashape.unirest.request.GetRequest; //导入方法依赖的package包/类
public ChannelStats getChannelStats(String channel, Date startDate, Date endDate) {
	RequestHandler req = RequestHandler.instance();
	HbGet getM = HbGet.STATS_CHANNEL_ALL;
	try {
		Params p = new Params().p("authToken", req.getToken().getToken());
		GetRequest request = req.get(getM, p, channel, String.valueOf(startDate.getTime()), String.valueOf(endDate.getTime()));
		HttpResponse<JsonNode> httpResponse = request.asJson();
		JSONObject object = httpResponse.getBody().getObject();
		if (object.has("channel")) {
			ObjectMapper objectMapper = new ObjectMapper();
			objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
			ChannelStats stats = objectMapper.readValue(object.toString(), ChannelStats.class);
			return stats;
		}
	}
	catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:GRM-dev,项目名称:HitBoard,代码行数:21,代码来源:Statistics.java

示例2: getViewerStats

import com.mashape.unirest.request.GetRequest; //导入方法依赖的package包/类
public ViewerStats getViewerStats(String channel, Date startDate, Date endDate) {
	RequestHandler req = RequestHandler.instance();
	HbGet getM = HbGet.STATS_VIEWER;
	try {
		Params p = new Params().p("authToken", req.getToken().getToken());
		GetRequest request = req.get(getM, p, channel, String.valueOf(startDate.getTime()), String.valueOf(endDate.getTime()));
		HttpResponse<JsonNode> httpResponse = request.asJson();
		JSONObject object = httpResponse.getBody().getObject();
		if (object.has("channel")) {
			ObjectMapper objectMapper = new ObjectMapper();
			objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
			ViewerStats stats = objectMapper.readValue(object.toString(), ViewerStats.class);
			return stats;
		}
	}
	catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:GRM-dev,项目名称:HitBoard,代码行数:21,代码来源:Statistics.java

示例3: getRevenueStats

import com.mashape.unirest.request.GetRequest; //导入方法依赖的package包/类
public RevenueStats getRevenueStats(String channel, Date startDate, Date endDate) {
	RequestHandler req = RequestHandler.instance();
	HbGet getM = HbGet.STATS_REVENUE;
	try {
		Params p = new Params().p("authToken", req.getToken().getToken()).p("startDate", String.valueOf(startDate.getTime())).p("endDate", String.valueOf(endDate.getTime()));
		GetRequest request = req.get(getM, p, channel);
		HttpResponse<JsonNode> httpResponse = request.asJson();
		JSONObject object = httpResponse.getBody().getObject();
		if (object.has("revenues")) {
			ObjectMapper objectMapper = new ObjectMapper();
			objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
			RevenueStats stats = objectMapper.readValue(object.toString(), RevenueStats.class);
			return stats;
		}
	}
	catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:GRM-dev,项目名称:HitBoard,代码行数:21,代码来源:Statistics.java

示例4: getFollowerStats

import com.mashape.unirest.request.GetRequest; //导入方法依赖的package包/类
public List<FollowerStats> getFollowerStats(String channel) {
	RequestHandler req = RequestHandler.instance();
	HbGet getM = HbGet.STATS_FOLLOWER;
	try {
		Params p = new Params().p("authToken", req.getToken().getToken());
		GetRequest request = req.get(getM, p, channel);
		HttpResponse<JsonNode> httpResponse = request.asJson();
		JSONObject object = httpResponse.getBody().getObject();
		JSONArray jsonArray = object.getJSONArray("followers");
		if (jsonArray == null || jsonArray.length() == 0) { return null; }
		ObjectMapper objectMapper = new ObjectMapper();
		objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
		List<FollowerStats> list = new ArrayList<>();
		for (int i = 0; i < jsonArray.length(); i++) {
			JSONObject jobj = jsonArray.getJSONObject(i);
			list.add(objectMapper.readValue(jobj.toString(), FollowerStats.class));
		}
		return list;
	}
	catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:GRM-dev,项目名称:HitBoard,代码行数:25,代码来源:Statistics.java

示例5: getUser

import com.mashape.unirest.request.GetRequest; //导入方法依赖的package包/类
public static UserData getUser(String username) {
	RequestHandler req = RequestHandler.instance();
	HbGet m = HbGet.USER_OBJECT;
	Params p = new Params().p("authToken", req.getToken().getToken());
	try {
		GetRequest request = req.get(m, p, username);
		HttpResponse<JsonNode> response = request.asJson();
		JSONObject object = response.getBody().getObject();
		ObjectMapper objectMapper = new ObjectMapper();
		objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
		UserData user = objectMapper.readValue(object.toString(), UserData.class);
		return user;
	}
	catch (Exception e) {
		e.printStackTrace();
		return null;
	}
}
 
开发者ID:GRM-dev,项目名称:HitBoard,代码行数:19,代码来源:User.java

示例6: getLiveObjectsList

import com.mashape.unirest.request.GetRequest; //导入方法依赖的package包/类
public static List<MediaObject> getLiveObjectsList(boolean publicOnly,
		boolean showHidden, boolean hiddenOnly, boolean liveOnly) {
	RequestHandler req = RequestHandler.instance();
	HbGet method = HbGet.MEDIA_LIVE_LIST;
	Params params = new Params().p("authToken", req.getToken().getToken())
			.p("publicOnly", publicOnly).p("showHidden", showHidden)
			.p("hiddenOnly", hiddenOnly).p("liveOnly", liveOnly);
	try {
		GetRequest getRequest = req.get(method, params);
		HttpResponse<JsonNode> httpResponse = getRequest.asJson();
		JsonNode jsonNode = httpResponse.getBody();
		JSONObject jsonObject = jsonNode.getObject();
		JSONArray jsonArray = jsonObject.getJSONArray("livestream");
		return getAsMediaLive(jsonArray);
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:GRM-dev,项目名称:HitBoard,代码行数:20,代码来源:Media.java

示例7: getMediaStatus

import com.mashape.unirest.request.GetRequest; //导入方法依赖的package包/类
public static MediaStatus getMediaStatus(String channel) throws Exception {
	RequestHandler req = RequestHandler.instance();
	HbGet getM = HbGet.MEDIA_STATUS;
	GetRequest getRequest = req.get(getM, channel);
	HttpResponse<JsonNode> httpResponse = getRequest.asJson();
	JsonNode jsonNode = httpResponse.getBody();
	JSONObject jsonObject = jsonNode.getObject();
	String isLiveS = null;
	String viewsS = null;
	try {
		isLiveS = jsonObject.getString("media_is_live");
		viewsS = jsonObject.getString("media_views");
	} catch (JSONException e) {
		e.printStackTrace();
	}
	boolean isLive = Boolean.parseBoolean(isLiveS);
	int views = Integer.parseInt(viewsS);
	MediaStatus mediaStatus = new MediaStatus(isLive, views);
	return mediaStatus;
}
 
开发者ID:GRM-dev,项目名称:HitBoard,代码行数:21,代码来源:Media.java

示例8: getMediaVideoObjectList

import com.mashape.unirest.request.GetRequest; //导入方法依赖的package包/类
/**
 * @param showHidden
 * @throws Exception
 */
public static List<MediaObject> getMediaVideoObjectList(boolean publicOnly,
		boolean showHidden, boolean hiddenOnly, boolean liveOnly,
		boolean yt, int limit, String channel) throws Exception {
	RequestHandler req = RequestHandler.instance();
	HbGet method = HbGet.MEDIA_VIDEO_LIST;
	Params params = new Params().p("authToken", req.getToken().getToken())
			.p("publicOnly", publicOnly).p("showHidden", showHidden)
			.p("hiddenOnly", hiddenOnly).p("liveOnly", liveOnly).p("yt", yt)
			.p("limit", limit);
	GetRequest getRequest = req.get(method, params, channel);
	HttpResponse<JsonNode> httpResponse = getRequest.asJson();
	JsonNode jsonNode = httpResponse.getBody();
	JSONObject jsonObject = jsonNode.getObject();
	JSONArray jsonArray = jsonObject.getJSONArray("video");
	return getAsMediaLive(jsonArray);
}
 
开发者ID:GRM-dev,项目名称:HitBoard,代码行数:21,代码来源:Media.java

示例9: getRecordingObjects

import com.mashape.unirest.request.GetRequest; //导入方法依赖的package包/类
/**
 * @param limit
 * @param channel
 * @throws Exception
 */
public static List<Recording> getRecordingObjects(int limit, String channel)
		throws Exception {
	RequestHandler req = RequestHandler.instance();
	HbGet method = HbGet.MEDIA_RECORDING_OBJECT;
	Params params = new Params().p("authToken", req.getToken().getToken())
			.p("limit", limit);
	GetRequest getRequest = req.get(method, params, channel);
	HttpResponse<JsonNode> httpResponse = getRequest.asJson();
	JsonNode jsonNode = httpResponse.getBody();
	JSONArray jsonArray = jsonNode.getArray();
	List<Recording> list = new ArrayList<>();
	ObjectMapper objectMapper = new ObjectMapper();
	objectMapper.configure(
			DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT,
			true);
	for (int i = 0; i < jsonArray.length(); i++) {
		JSONObject recJson = jsonArray.getJSONObject(i);
		Recording recording = objectMapper.readValue(recJson.toString(),
				Recording.class);
		list.add(recording);
	}
	return list;
}
 
开发者ID:GRM-dev,项目名称:HitBoard,代码行数:29,代码来源:Media.java

示例10: validateToken

import com.mashape.unirest.request.GetRequest; //导入方法依赖的package包/类
public boolean validateToken(String token) throws Exception {
	if(token==null){
		if ((token = RequestHandler.instance().getToken().getToken()) == null) { throw new Exception("No token available."); }
	}
	GetRequest request = RequestHandler.instance().get(HbGet.TOKEN_VALID, new Params().p("token", new String(token)));
	HttpResponse<JsonNode> response = request.asJson();
	JSONObject jobj = response.getBody().getObject();
	if (jobj.getBoolean("success")) {
		if (jobj.getString("error_msg").equals("logged_in")) {
			return true;
		}
		else {
			return false;
		}
	}
	if (jobj.getBoolean("error")) {
		throw new Exception(jobj.getString("error_msg"));
	}
	else {
		return false;
	}
}
 
开发者ID:GRM-dev,项目名称:HitBoard,代码行数:23,代码来源:Token.java

示例11: getRequestTest

import com.mashape.unirest.request.GetRequest; //导入方法依赖的package包/类
@Test
public void getRequestTest() {
	try {
		GetRequest getResultRequest = reqH.get(HbGet.CHAT_SERVERS);
		assertThat(getResultRequest).isNotNull();
		HttpResponse<JsonNode> jsonResp = getResultRequest.asJson();
		assertThat(jsonResp).isNotNull();
		JsonNode jsonNode = jsonResp.getBody();
		assertThat(jsonNode).isNotNull();
		JSONArray jsonArray = jsonNode.getArray();
		assertThat(jsonArray).isNotNull();
		assertThat(jsonArray.length()).isNotEqualTo(0);
	} catch (Exception e) {
		fail("There was exception!", e);
	}
}
 
开发者ID:GRM-dev,项目名称:HitBoard,代码行数:17,代码来源:RequestHandlerTest.java

示例12: thingRequest

import com.mashape.unirest.request.GetRequest; //导入方法依赖的package包/类
/**
 * Make requests to the ThingSpeak server and parse the results.
 *
 * @param page The page of results to request.
 */
private void thingRequest(Integer page) {
    try {
        GetRequest request = Unirest.get(url + "/channels/public.json");
        if (tag != null) {
            request.field("tag", tag);
        }
        request.field("page", page);
        HttpResponse<JsonNode> response = request.asJson();
        if (response.getCode() != 200) {
            throw new ThingSpeakException("Request failed with code " + response.getCode());
        }
        results = gson.fromJson(response.getBody().toString(), PublicJSONResult.class);
        iterator = results.iterator();
    } catch (UnirestException | ThingSpeakException ex) {
        Logger.getLogger(PublicIterator.class.getName()).log(Level.SEVERE, null, ex);
        results = null;
    }
}
 
开发者ID:angryelectron,项目名称:thingspeak-java,代码行数:24,代码来源:PublicIterator.java

示例13: getNextIssuesAPI

import com.mashape.unirest.request.GetRequest; //导入方法依赖的package包/类
protected HttpResponse<JsonNode> getNextIssuesAPI(Integer page, Instant since) throws UnirestException {
    GetRequest unirest = Unirest.get(constructUrl(page, since));
    if (!config.getAuthUsername().isEmpty() && !config.getAuthPassword().isEmpty() ){
        unirest = unirest.basicAuth(config.getAuthUsername(), config.getAuthPassword());
    }
    log.debug(String.format("GET %s", unirest.getUrl()));
    return unirest.asJson();
}
 
开发者ID:simplesteph,项目名称:kafka-connect-github-source,代码行数:9,代码来源:GitHubAPIHttpClient.java

示例14: execute

import com.mashape.unirest.request.GetRequest; //导入方法依赖的package包/类
/**
 * Execute the given request
 * @param request the {@link GetRequest} object to execute
 * @return the response body as a JSONObject
 * @throws KintoException if there is a kinto error
 * @throws ClientException if there is a http transport error
 */
JSONObject execute(GetRequest request) throws KintoException, ClientException {
    try {
        // Call the remote with a request
        HttpResponse<JsonNode> response = request.asJson();
        // Handle kinto errors
        if(response.getStatus() != 200) {
            throw new KintoException(response.getStatusText());
        }
        return response.getBody().getObject();
    } catch (UnirestException e) {
        throw new ClientException("Error during \"" + request.getUrl() + "\"", e);
    }
}
 
开发者ID:intesens,项目名称:kinto-http-java,代码行数:21,代码来源:KintoClient.java

示例15: getFollowers

import com.mashape.unirest.request.GetRequest; //导入方法依赖的package包/类
public List<Follower> getFollowers(String channel, int offset, int limit, boolean reverse, SortType sort) throws Exception {
	Params p = new Params().p("offset", offset).p("limit", limit).p("reverse", reverse).p("sort", sort.toString().toLowerCase());
	GetRequest request = RequestHandler.instance().get(HbGet.FOLLOWERS_GET_ALL, p, channel);
	HttpResponse<JsonNode> response = request.asJson();
	JSONObject object = response.getBody().getObject();
	ObjectMapper objectMapper = new ObjectMapper();
	objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
	FollowerObject followerObject = objectMapper.readValue(object.toString(), FollowerObject.class);
	List<Follower> followers = followerObject.getFollowers();
	return followers;
}
 
开发者ID:GRM-dev,项目名称:HitBoard,代码行数:12,代码来源:Followers.java


注:本文中的com.mashape.unirest.request.GetRequest.asJson方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。