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


Java GetRequest类代码示例

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


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

示例1: testRequestWithoutCustomHeaders

import com.mashape.unirest.request.GetRequest; //导入依赖的package包/类
@Test
public void testRequestWithoutCustomHeaders() {
    // GIVEN a fake url
    String remote = "https://fake.kinto.url";
    // AND a kintoClient
    KintoClient kintoClient = new KintoClient(remote);
    // AND an ENDPOINTS
    ENDPOINTS endpoint = ENDPOINTS.GROUPS;
    // WHEN calling request
    GetRequest request = kintoClient.request(endpoint);
    // THEN the root part is initialized
    assertThat(request.getUrl(), is(remote + "/buckets/{bucket}/groups"));
    // AND the get http method is used
    assertThat(request.getHttpMethod(), is(HttpMethod.GET));
    // AND the default headers are set
    assertThat(request.getHeaders(), is(defaultHeaders));
}
 
开发者ID:intesens,项目名称:kinto-http-java,代码行数:18,代码来源:KintoClientTest.java

示例2: testRequestWithCustomHeaders

import com.mashape.unirest.request.GetRequest; //导入依赖的package包/类
@Test
public void testRequestWithCustomHeaders() {
    // GIVEN a fake url
    String remote = "https://fake.kinto.url";
    // AND custom headers
    Map<String, String> customHeaders = new HashMap<>();
    customHeaders.put("Authorization", "Basic supersecurestuff");
    customHeaders.put("Warning", "Be careful");
    customHeaders.put("Accept", "application/html");
    // AND expected headers
    Map<String, List<String>> expectedHeaders = new HashMap<>(defaultHeaders);
    customHeaders.forEach((k, v) -> expectedHeaders.merge(k, Arrays.asList(v), (a, b) -> a.addAll(b) ? a:a));
    // AND a kintoClient
    KintoClient kintoClient = new KintoClient(remote, customHeaders);
    // AND an ENDPOINTS
    ENDPOINTS endpoint = ENDPOINTS.GROUPS;
    // WHEN calling request
    GetRequest request = kintoClient.request(endpoint);
    // THEN the root part is initialized
    assertThat(request.getUrl(), is(remote + "/buckets/{bucket}/groups"));
    // AND the get http method is used
    assertThat(request.getHttpMethod(), is(HttpMethod.GET));
    // AND the default headers are set
    assertThat(request.getHeaders(), is(expectedHeaders));
}
 
开发者ID:intesens,项目名称:kinto-http-java,代码行数:26,代码来源:KintoClientTest.java

示例3: testExecuteCorrect

import com.mashape.unirest.request.GetRequest; //导入依赖的package包/类
@Test
public void testExecuteCorrect() throws UnirestException, KintoException, ClientException {
    // GIVEN a fake url
    String remote = "https://fake.kinto.url";
    // AND a kintoClient
    KintoClient kintoClient = new KintoClient(remote);
    // AND a simple JsonNode
    JsonNode jsonNode = new JsonNode("{}");
    // AND a httpResponse mock
    HttpResponse<JsonNode> response = mock(HttpResponse.class);
    doReturn(200).when(response).getStatus();
    doReturn(jsonNode).when(response).getBody();
    // AND GetRequest mock
    GetRequest request = mock(GetRequest.class);
    doReturn(response).when(request).asJson();
    // WHEN calling execute
    JSONObject jsonObject = kintoClient.execute(request);
    // THEN the result is correct;
    assertThat(jsonObject.toString(), is("{}"));
}
 
开发者ID:intesens,项目名称:kinto-http-java,代码行数:21,代码来源:KintoClientTest.java

示例4: testExecuteKintoError

import com.mashape.unirest.request.GetRequest; //导入依赖的package包/类
@Test(expected = KintoException.class)
public void testExecuteKintoError() throws UnirestException, KintoException, ClientException {
    // GIVEN a fake url
    String remote = "https://fake.kinto.url";
    // AND a kintoClient
    KintoClient kintoClient = new KintoClient(remote);
    // AND a httpResponse mock
    HttpResponse<JsonNode> response = mock(HttpResponse.class);
    doReturn(400).when(response).getStatus();
    doReturn("an error").when(response).getStatusText();
    // AND GetRequest mock
    GetRequest request = mock(GetRequest.class);
    doReturn(response).when(request).asJson();
    // WHEN calling execute
    kintoClient.execute(request);
    // THEN a KintoException is thrown
}
 
开发者ID:intesens,项目名称:kinto-http-java,代码行数:18,代码来源:KintoClientTest.java

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: 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


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