當前位置: 首頁>>代碼示例>>Java>>正文


Java Unirest類代碼示例

本文整理匯總了Java中com.mashape.unirest.http.Unirest的典型用法代碼示例。如果您正苦於以下問題:Java Unirest類的具體用法?Java Unirest怎麽用?Java Unirest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Unirest類屬於com.mashape.unirest.http包,在下文中一共展示了Unirest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: requestHttp

import com.mashape.unirest.http.Unirest; //導入依賴的package包/類
/**
 * Using the HttpMethod to return a http request.
 * @param params Parameters to be replaced.
 * @return The http request
 */
private HttpRequest requestHttp(Object... params) {
    String processedPath = processPath(params);

    HttpRequest request = null;
    switch (path.getMethod()) {
        case GET:
            request = Unirest.get(processedPath); break;
        case HEAD:
            request = Unirest.head(processedPath); break;
        case POST:
            request = Unirest.post(processedPath); break;
        case PUT:
            request = Unirest.put(processedPath); break;
        case PATCH:
            request = Unirest.patch(processedPath); break;
        case DELETE:
            request = Unirest.delete(processedPath); break;
        case OPTIONS:
            request = Unirest.options(processedPath); break;
    }
    processRequest(request);
    this.request = request;
    return request;
}
 
開發者ID:AlienIdeology,項目名稱:J-Cord,代碼行數:30,代碼來源:Requester.java

示例2: test_formParams_work

import com.mashape.unirest.http.Unirest; //導入依賴的package包/類
@Test
public void test_formParams_work() throws Exception {
    Javalin app = Javalin.create().port(0).start();
    app.before("/body-reader", ctx -> ctx.header("X-BEFORE", ctx.formParam("username")));
    app.post("/body-reader", ctx -> ctx.result(ctx.formParam("password")));
    app.after("/body-reader", ctx -> ctx.header("X-AFTER", ctx.formParam("repeat-password")));

    HttpResponse<String> response = Unirest
        .post("http://localhost:" + app.port() + "/body-reader")
        .body("username=some-user-name&password=password&repeat-password=password")
        .asString();

    assertThat(response.getHeaders().getFirst("X-BEFORE"), is("some-user-name"));
    assertThat(response.getBody(), is("password"));
    assertThat(response.getHeaders().getFirst("X-AFTER"), is("password"));
    app.stop();
}
 
開發者ID:tipsy,項目名稱:javalin,代碼行數:18,代碼來源:TestBodyReading.java

示例3: execute

import com.mashape.unirest.http.Unirest; //導入依賴的package包/類
public void execute(JobExecutionContext context) throws JobExecutionException {

        // Extract data from job
        Map<String, String> properties = (Map<String, String>) context.getMergedJobDataMap().get(Map.class.getCanonicalName());
        Set<String> taskIds = (Set<String>) context.getMergedJobDataMap().get(Task.class.getCanonicalName());

        taskIds.forEach(taskId -> {
            final String url = urlConverter(
                    DEFAULT_PROTOCOL,
                    properties.get(SERVER_IP),
                    properties.get(SERVER_PORT),
                    properties.get(SERVER_CONTEXT_PATH) + RETRY_PATH + "/" + taskId
            );

            try {
                final HttpResponse<String> httpResponse =
                        Unirest.get(url).asString();
            } catch (UnirestException e) {
                LOGGER.error("UnirestException", e);
            }
        });

    }
 
開發者ID:ftsakiris,項目名稱:async-engine,代碼行數:24,代碼來源:QuartzJob.java

示例4: retrieveAllFiles

import com.mashape.unirest.http.Unirest; //導入依賴的package包/類
public static List<String> retrieveAllFiles(String auth, String folder) throws IOException, UnirestException {
    List<String> lis= new LinkedList<String>();
    HttpResponse<JsonNode> jsonResponse = Unirest.get("https://www.googleapis.com/drive/v2/files/root/children?q=title='"+folder+"'").header("Authorization","Bearer "+auth).asJson();
    JSONObject jsonObject= new JSONObject(jsonResponse.getBody());
    JSONArray array = jsonObject.getJSONArray("array");
    for(int i=0;i<array.length();i++){
        JSONArray jarray=array.getJSONObject(i).getJSONArray("items");
        int j=jarray.length();
        while(j>0){
            String id=jarray.getJSONObject(0).getString("id");
            auxRetrieveAllFiles(lis,auth,"https://www.googleapis.com/drive/v2/files?includeTeamDriveItems=false&pageSize=500&q='"+id+"'%20in%20parents"+"&key="+ MISConfig.getGoogle_api(),id);
            j--;
        }

    }
    return lis;
}
 
開發者ID:LithiumSR,項目名稱:media_information_service,代碼行數:18,代碼來源:GDrvAPIOp.java

示例5: paste

import com.mashape.unirest.http.Unirest; //導入依賴的package包/類
public static String paste(String toSend) {
	try {
		String pasteToken = Unirest.post("https://hastebin.com/documents")
			.header("User-Agent", "Mantaro")
			.header("Content-Type", "text/plain")
			.body(toSend)
			.asJson()
			.getBody()
			.getObject()
			.getString("key");
		return "https://hastebin.com/" + pasteToken;
	} catch (UnirestException e) {
		log.warn("Hastebin is being funny, huh? Cannot send or retrieve paste.", e);
		return "Bot threw ``" + e.getClass().getSimpleName() + "``" + " while trying to upload paste, check logs";
	}
}
 
開發者ID:Mantaro,項目名稱:MantaroRPG,代碼行數:17,代碼來源:Utils.java

示例6: triggerJob

import com.mashape.unirest.http.Unirest; //導入依賴的package包/類
private synchronized void triggerJob() {
    try {
        logger.log(Level.INFO,"Starting Jenkins job: " + JOB_NAME);
        String result = null;
        switch(getJobType()) {
            case Parametrized:
                result = Unirest.post(JENKINS_URL + "/job/" + JOB_NAME + "/build").basicAuth(USER, API_TOKEN)
                        .field("json", getJSON())
                        .asBinary().getStatusText();
                break;
            case Normal:
                result = Unirest.post(JENKINS_URL + "/job/" + JOB_NAME + "/build").basicAuth(USER, API_TOKEN)
                        .asBinary().getStatusText();
                break;
        }
        logger.log(Level.INFO,"Done. Job '" + JOB_NAME + "' status: " + result);
    } catch (UnirestException e) {
        e.printStackTrace();
    }
}
 
開發者ID:iKozzz,項目名稱:service-jenkins,代碼行數:21,代碼來源:JenkinsServiceApp.java

示例7: logout

import com.mashape.unirest.http.Unirest; //導入依賴的package包/類
/**
 * Logs out with the session identifier.
 *
 *  @param url REST API Url.
 *  @param sessionId Session identifier.
 */
public static void logout(String url, String sessionId) {
    try {
        Map<String, String> session = new LinkedHashMap<String, String>();
        session.put("user_name", sessionId);

        ObjectMapper mapper = new ObjectMapper();
        String jsonSessionData = mapper.writeValueAsString(session);

        Map<String, Object> request = new LinkedHashMap<String, Object>();
        request.put("method", "logout");
        request.put("input_type", "json");
        request.put("response_type", "json");
        request.put("rest_data", jsonSessionData);

        Unirest.post(url)
                .fields(request)
                .asString();
    }
    catch (Exception exception) {
    }
}
 
開發者ID:mattkol,項目名稱:SugarOnRest,代碼行數:28,代碼來源:Authentication.java

示例8: getToken

import com.mashape.unirest.http.Unirest; //導入依賴的package包/類
@Override
public String getToken(String code) throws UnirestException {
    HttpResponse<JsonNode> response = Unirest.post("https://www.googleapis.com/oauth2/v4/token")
            .header("User-Agent", "pxls.space")
            .field("grant_type", "authorization_code")
            .field("code", code)
            .field("redirect_uri", getCallbackUrl())
            .field("client_id", App.getConfig().getString("oauth.google.key"))
            .field("client_secret", App.getConfig().getString("oauth.google.secret"))
            .asJson();

    JSONObject json = response.getBody().getObject();

    if (json.has("error")) {
        return null;
    } else {
        return json.getString("access_token");
    }
}
 
開發者ID:xSke,項目名稱:Pxls,代碼行數:20,代碼來源:GoogleAuthService.java

示例9: getToken

import com.mashape.unirest.http.Unirest; //導入依賴的package包/類
public String getToken(String code) throws UnirestException {
    HttpResponse<JsonNode> response = Unirest.post("https://oauth.vk.com/access_token")
            .header("User-Agent", "pxls.space")
            .field("grant_type", "authorization_code")
            .field("code", code)
            .field("redirect_uri", getCallbackUrl())
            .field("client_id", App.getConfig().getString("oauth.vk.key"))
            .field("client_secret", App.getConfig().getString("oauth.vk.secret"))
            .asJson();

    JSONObject json = response.getBody().getObject();

    if (json.has("error")) {
        return null;
    } else {
        return json.getString("access_token");
    }
}
 
開發者ID:xSke,項目名稱:Pxls,代碼行數:19,代碼來源:VKAuthService.java

示例10: getIdentifier

import com.mashape.unirest.http.Unirest; //導入依賴的package包/類
public String getIdentifier(String token) throws UnirestException, InvalidAccountException {
    String[] codes = token.split("\\|");
    HttpResponse<JsonNode> me = Unirest.get("https://api.tumblr.com/v2/user/info?" + getOauthRequest("https://api.tumblr.com/v2/user/info", "oauth_token="+codes[0], "oob", "GET", codes[1]))
            .header("User-Agent", "pxls.space")
            .asJson();
    JSONObject json = me.getBody().getObject();
    if (json.has("error")) {
        return null;
    } else {
        try {
            return json.getJSONObject("response").getJSONObject("user").getString("name");
        } catch (JSONException e) {
            return null;
        }
    }
}
 
開發者ID:xSke,項目名稱:Pxls,代碼行數:17,代碼來源:TumblrAuthService.java

示例11: getToken

import com.mashape.unirest.http.Unirest; //導入依賴的package包/類
public String getToken(String code) throws UnirestException {
    HttpResponse<JsonNode> response = Unirest.post("https://discordapp.com/api/oauth2/token")
            .header("User-Agent", "pxls.space")
            .field("grant_type", "authorization_code")
            .field("code", code)
            .field("redirect_uri", getCallbackUrl())
            .basicAuth(App.getConfig().getString("oauth.discord.key"), App.getConfig().getString("oauth.discord.secret"))
            .asJson();

    JSONObject json = response.getBody().getObject();

    if (json.has("error")) {
        return null;
    } else {
        return json.getString("access_token");
    }
}
 
開發者ID:xSke,項目名稱:Pxls,代碼行數:18,代碼來源:DiscordAuthService.java

示例12: getIdentifier

import com.mashape.unirest.http.Unirest; //導入依賴的package包/類
public String getIdentifier(String token) throws UnirestException, InvalidAccountException {
    HttpResponse<JsonNode> me = Unirest.get("https://discordapp.com/api/users/@me")
            .header("Authorization", "Bearer " + token)
            .header("User-Agent", "pxls.space")
            .asJson();
    JSONObject json = me.getBody().getObject();
    if (json.has("error")) {
        return null;
    } else {
        long id = json.getLong("id");
        long signupTimeMillis = (id >> 22) + 1420070400000L;
        long ageMillis = System.currentTimeMillis() - signupTimeMillis;

        long minAgeMillis = App.getConfig().getDuration("oauth.discord.minAge", TimeUnit.MILLISECONDS);
        if (ageMillis < minAgeMillis){
            long days = minAgeMillis / 86400 / 1000;
            throw new InvalidAccountException("Account too young");
        }
        return json.getString("id");
    }
}
 
開發者ID:xSke,項目名稱:Pxls,代碼行數:22,代碼來源:DiscordAuthService.java

示例13: getToken

import com.mashape.unirest.http.Unirest; //導入依賴的package包/類
public String getToken(String code) throws UnirestException {
    HttpResponse<JsonNode> response = Unirest.post("https://www.reddit.com/api/v1/access_token")
            .header("User-Agent", "pxls.space")
            .field("grant_type", "authorization_code")
            .field("code", code)
            .field("redirect_uri", getCallbackUrl())
            .basicAuth(App.getConfig().getString("oauth.reddit.key"), App.getConfig().getString("oauth.reddit.secret"))
            .asJson();

    JSONObject json = response.getBody().getObject();

    if (json.has("error")) {
        return null;
    } else {
        return json.getString("access_token");
    }
}
 
開發者ID:xSke,項目名稱:Pxls,代碼行數:18,代碼來源:RedditAuthService.java

示例14: getIdentifier

import com.mashape.unirest.http.Unirest; //導入依賴的package包/類
public String getIdentifier(String token) throws UnirestException, InvalidAccountException {
    HttpResponse<JsonNode> me = Unirest.get("https://oauth.reddit.com/api/v1/me")
            .header("Authorization", "bearer " + token)
            .header("User-Agent", "pxls.space")
            .asJson();
    JSONObject json = me.getBody().getObject();
    if (json.has("error")) {
        return null;
    } else {
        long accountAgeSeconds = (System.currentTimeMillis() / 1000 - json.getLong("created"));
        long minAgeSeconds = App.getConfig().getDuration("oauth.reddit.minAge", TimeUnit.SECONDS);
        if (accountAgeSeconds < minAgeSeconds){
            long days = minAgeSeconds / 86400;
            throw new InvalidAccountException("Account too young");
        } else if (!json.getBoolean("has_verified_email")) {
            throw new InvalidAccountException("Account must have a verified e-mail");
        }
        return json.getString("name");
    }
}
 
開發者ID:xSke,項目名稱:Pxls,代碼行數:21,代碼來源:RedditAuthService.java

示例15: getAllDeployments

import com.mashape.unirest.http.Unirest; //導入依賴的package包/類
public JSONArray getAllDeployments() {
    JSONArray deployments = new JSONArray();

    try {
        deployments =
                Unirest.get(MessageFormat.format("http://{0}:{1}/deployments", host, port))
                        .header("accept", "application/json")
                        .header("Content-Type", "application/json")
                        .asJson()
                        .getBody().getArray();
    } catch (UnirestException e) {
        e.printStackTrace();
    }

    return deployments;
}
 
開發者ID:SkymindIO,項目名稱:SKIL_Examples,代碼行數:17,代碼來源:Deployment.java


注:本文中的com.mashape.unirest.http.Unirest類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。