Search in sources :

Example 1 with GetRequest

use of com.mashape.unirest.request.GetRequest in project blueocean-plugin by jenkinsci.

the class PipelineBaseTest method getJwtToken.

public static String getJwtToken(Jenkins jenkins, String username, String password) throws UnirestException {
    GetRequest request = Unirest.get(jenkins.getRootUrl() + "jwt-auth/token/").header("Accept", "*/*").header("Accept-Encoding", "");
    if (username != null && password != null) {
        request.basicAuth(username, password);
    }
    HttpResponse<String> response = request.asString();
    String token = response.getHeaders().getFirst(X_BLUEOCEAN_JWT);
    Assert.assertNotNull(token);
    // tests that test token generation and validation
    return token;
}
Also used : GetRequest(com.mashape.unirest.request.GetRequest)

Example 2 with GetRequest

use of com.mashape.unirest.request.GetRequest in project blueocean-plugin by jenkinsci.

the class BaseTest method getJwtToken.

public static String getJwtToken(Jenkins jenkins, String username, String password) throws UnirestException {
    GetRequest request = Unirest.get(jenkins.getRootUrl() + "jwt-auth/token/").header("Accept", "*/*").header("Accept-Encoding", "");
    if (username != null && password != null) {
        request.basicAuth(username, password);
    }
    HttpResponse<String> response = request.asString();
    String token = response.getHeaders().getFirst(X_BLUEOCEAN_JWT);
    Assert.assertNotNull(token);
    //we do not validate it for test optimization and for the fact that there are separate
    // tests that test token generation and validation
    int i = token.indexOf('.');
    Assert.assertTrue(i > 0);
    int j = token.lastIndexOf(".");
    Assert.assertTrue(j > 0);
    String claim = new String(org.jose4j.base64url.Base64.decode(token.substring(i + 1, j)));
    Map u = JSONObject.fromObject(claim);
    Assert.assertEquals(username, u.get("sub"));
    return token;
}
Also used : GetRequest(com.mashape.unirest.request.GetRequest) Map(java.util.Map)

Example 3 with GetRequest

use of com.mashape.unirest.request.GetRequest in project Ardent by adamint.

the class UD method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    Shard shard = GuildUtils.getShard(guild);
    if (args.length == 1) {
        sendTranslatedMessage("Search a word's definition from Urban Dictionary. Example: {0}ud test".replace("{0}", GuildUtils.getPrefix(guild)), channel, user);
    } else {
        GetRequest getRequest = Unirest.get("http://api.urbandictionary.com/v0/define?term=" + message.getRawContent().replace(GuildUtils.getPrefix(guild) + args[0] + " ", "").replaceAll(" ", "%20"));
        String json = "";
        try {
            json = getRequest.asJson().getBody().toString();
        } catch (UnirestException e) {
            e.printStackTrace();
        }
        UrbanDictionary definition = shard.gson.fromJson(json, UrbanDictionary.class);
        if (definition.getList().size() == 0) {
            sendTranslatedMessage("There aren't any definitions for this word!", channel, user);
        } else {
            EmbedBuilder builder = MessageUtils.getDefaultEmbed(message.getAuthor());
            UDList list = definition.getList().get(0);
            String def = "Definition";
            String author = "Author";
            String example = "Example";
            String link = "Link";
            String thumbsUp = "Thumbs Up";
            String thumbsDown = "Thumbs Down";
            String urbanDictionary = "Urban Dictionary";
            builder.setAuthor(urbanDictionary, shard.bot.getAvatarUrl(), shard.bot.getAvatarUrl());
            builder.setThumbnail("https://i.gyazo.com/6a40e32928743e68e9006396ee7c2a14.jpg");
            builder.setColor(Color.decode("#00B7BE"));
            String definitionText = list.getDefinition();
            String exampleText = list.getExample();
            if (definitionText.length() > 1024)
                definitionText = definitionText.substring(0, 1023);
            if (exampleText.length() > 1024)
                exampleText = exampleText.substring(0, 1023);
            builder.addField(def, definitionText, true);
            builder.addField(example, exampleText, true);
            builder.addField(thumbsUp, String.valueOf(list.getThumbsUp() + ":thumbsup:"), true);
            builder.addField(thumbsDown, String.valueOf(list.getThumbsDown() + ":thumbsdown:"), true);
            builder.addField(author, list.getAuthor(), true);
            builder.addField(link, list.getPermalink(), true);
            sendEmbed(builder, channel, user);
        }
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) UDList(tk.ardentbot.core.models.UDList) GetRequest(com.mashape.unirest.request.GetRequest) UnirestException(com.mashape.unirest.http.exceptions.UnirestException) UrbanDictionary(tk.ardentbot.core.models.UrbanDictionary) Shard(tk.ardentbot.main.Shard)

Aggregations

GetRequest (com.mashape.unirest.request.GetRequest)3 UnirestException (com.mashape.unirest.http.exceptions.UnirestException)1 Map (java.util.Map)1 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)1 UDList (tk.ardentbot.core.models.UDList)1 UrbanDictionary (tk.ardentbot.core.models.UrbanDictionary)1 Shard (tk.ardentbot.main.Shard)1