From 86e297d27fbcb072a569848c22902b683ceca96a Mon Sep 17 00:00:00 2001 From: Mavlushechka Date: Tue, 4 Oct 2022 01:12:37 +0500 Subject: Add getResponseCode methods to JSONPlaceholderAPIManager utility class --- .../a1qa/utils/JSONPlaceholderAPIManager.java | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/main/java/com/mavlushechka') diff --git a/src/main/java/com/mavlushechka/a1qa/utils/JSONPlaceholderAPIManager.java b/src/main/java/com/mavlushechka/a1qa/utils/JSONPlaceholderAPIManager.java index 2a66576..aecf885 100644 --- a/src/main/java/com/mavlushechka/a1qa/utils/JSONPlaceholderAPIManager.java +++ b/src/main/java/com/mavlushechka/a1qa/utils/JSONPlaceholderAPIManager.java @@ -15,31 +15,35 @@ public class JSONPlaceholderAPIManager { public static Post getPost(int id) throws IOException { - return getObject(postsSpec + "/" + id, Post.class); + return JSONParser.convertToObject(URLConnectionManager.get(postsSpec + "/" + id), Post.class); + } + + public static int getPostResponseCode(int id, String requestMethod) throws IOException { + return URLConnectionManager.getResponseCode(postsSpec + "/" + id, requestMethod); } public static List getPosts() throws IOException { return getObjects(postsSpec, Post.class); } + public static int getPostsResponseCode(String requestMethod) throws IOException { + return URLConnectionManager.getResponseCode(postsSpec, requestMethod); + } + public static Post postPost(Post post) throws IOException { - return postObject(postsSpec, post, Post.class); + return JSONParser.convertToObject(URLConnectionManager.post(postsSpec, JSONParser.convertToJSON(post)), Post.class); } public static User getUser(int id) throws IOException { - return getObject(usersSpec + "/" + id, User.class); + return JSONParser.convertToObject(URLConnectionManager.get(usersSpec + "/" + id), User.class); } public static List getUsers() throws IOException { return getObjects(usersSpec, User.class); } - public static User postUser(User user) throws IOException { - return postObject(usersSpec, user, User.class); - } - - private static T getObject(String spec, Class classOfObject) throws IOException { - return JSONParser.convertToObject(URLConnectionManager.get(spec), classOfObject); + public static int getUsersResponseCode(String requestMethod) throws IOException { + return URLConnectionManager.getResponseCode(usersSpec, requestMethod); } private static List getObjects(String spec, Class classOfObject) throws IOException { @@ -52,8 +56,4 @@ public class JSONPlaceholderAPIManager { return objectsArrayList.stream().toList(); } - private static T postObject(String spec, T object, Class classOfObject) throws IOException { - return JSONParser.convertToObject(URLConnectionManager.post(spec, JSONParser.convertToJSON(object)), classOfObject); - } - } -- cgit v1.2.3