summaryrefslogtreecommitdiff
path: root/src/main/java/com/mavlushechka
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/mavlushechka')
-rw-r--r--src/main/java/com/mavlushechka/a1qa/utils/JSONPlaceholderAPIManager.java26
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);
- }
-
}