[SOLVED] CS Java package com.jokecompany;

$25

File Name: CS_Java_package_com.jokecompany;.zip
File Size: 301.44 KB

5/5 - (1 vote)

package com.jokecompany;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class JsonFeed {
static String url = ;

public JsonFeed(String endpoint, int results) {
url = endpoint;
}

public static String[] getRandomJokes(String firstname, String lastname, String category) throws URISyntaxException, IOException, InterruptedException {
HttpClient client = HttpClient.newHttpClient();
url += random/;
if (category != null)
url += category;
URI uri = new URI(url);
HttpRequest request = HttpRequest.newBuilder().uri(uri).build();
String joke = client.send(request, HttpResponse.BodyHandlers.ofString()).body();
if (firstname != null && lastname != null)
{
int index = joke.indexOf(Chuck Norris);
String firstPart = joke.substring(0, index);
String secondPart = joke.substring(index + Chuck Norris.length());
joke = firstPart + + firstname + + lastname + secondPart;
}
Gson jsonobject = new GsonBuilder().disableHtmlEscaping().create();
return new String[] {jsonobject.toJson(joke)};
}

public static Dto getnames() throws URISyntaxException, IOException, InterruptedException {
HttpClient client = HttpClient.newHttpClient();
URI uri = new URI(url);
HttpRequest request = HttpRequest.newBuilder().uri(uri).build();
String names = client.send(request, HttpResponse.BodyHandlers.ofString()).body();
Gson gson = new Gson();
return gson.fromJson(names, Dto.class);
}

public static String[] getCategories() throws IOException, InterruptedException, URISyntaxException {
HttpClient client = HttpClient.newHttpClient();
URI uri = new URI(url);
HttpRequest request = HttpRequest.newBuilder().uri(uri).build();
String responsebody = client.send(request, HttpResponse.BodyHandlers.ofString()).body();
return new String[] {new Gson().toJson(responsebody)};
}
}

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS Java package com.jokecompany;
$25