diff options
author | Mavlushechka <mavlushechka@gmail.com> | 2022-10-04 01:12:37 +0500 |
---|---|---|
committer | Mavlushechka <mavlushechka@gmail.com> | 2022-10-04 01:12:37 +0500 |
commit | 86e297d27fbcb072a569848c22902b683ceca96a (patch) | |
tree | 9abbeac5136a87c55101039dbaaae707109a8dc1 /src/main/java/com/mavlushechka/a1qa/utils/JSONPlaceholderAPIManager.java | |
parent | 242813280cdfa8d2e9cdc930a15d021f17c9ec10 (diff) |
Add getResponseCode methods to JSONPlaceholderAPIManager utility class
Diffstat (limited to 'src/main/java/com/mavlushechka/a1qa/utils/JSONPlaceholderAPIManager.java')
-rw-r--r-- | src/main/java/com/mavlushechka/a1qa/utils/JSONPlaceholderAPIManager.java | 26 |
1 files changed, 13 insertions, 13 deletions
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<Post> 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<User> 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> T getObject(String spec, Class<T> 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 <T> List<T> getObjects(String spec, Class<T> classOfObject) throws IOException { @@ -52,8 +56,4 @@ public class JSONPlaceholderAPIManager { return objectsArrayList.stream().toList(); } - private static <T> T postObject(String spec, T object, Class<T> classOfObject) throws IOException { - return JSONParser.convertToObject(URLConnectionManager.post(spec, JSONParser.convertToJSON(object)), classOfObject); - } - } |