From eb4815fdfc45e63c767f7bcec712613b8ebbbcd3 Mon Sep 17 00:00:00 2001 From: Mavlushechka Date: Tue, 4 Oct 2022 00:42:16 +0500 Subject: Replace spec parameters by ids of objects --- .../a1qa/utils/JSONPlaceholderAPIManager.java | 28 ++++++++++++---------- 1 file changed, 16 insertions(+), 12 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 2305daf..25b9fe4 100644 --- a/src/main/java/com/mavlushechka/a1qa/utils/JSONPlaceholderAPIManager.java +++ b/src/main/java/com/mavlushechka/a1qa/utils/JSONPlaceholderAPIManager.java @@ -9,28 +9,32 @@ import java.util.List; public class JSONPlaceholderAPIManager { - public static Post getPost(String spec) throws IOException { - return getObject(spec, Post.class); + private final static String postsSpec = "/posts"; + private final static String usersSpec = "/users"; + + + public static Post getPost(int id) throws IOException { + return getObject(postsSpec + "/" + id, Post.class); } - public static List getPosts(String spec) throws IOException { - return getObjects(spec, Post.class); + public static List getPosts() throws IOException { + return getObjects(postsSpec, Post.class); } - public static Post postPost(String spec, Post post) throws IOException { - return postObject(spec, post, Post.class); + public static Post postPost(Post post) throws IOException { + return postObject(postsSpec, post, Post.class); } - public static User getUser(String spec) throws IOException { - return getObject(spec, User.class); + public static User getUser(int id) throws IOException { + return getObject(usersSpec + "/" + id, User.class); } - public static List getUsers(String spec) throws IOException { - return getObjects(spec, User.class); + public static List getUsers() throws IOException { + return getObjects(usersSpec, User.class); } - public static User postUser(String spec, User user) throws IOException { - return postObject(spec, user, 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 { -- cgit v1.2.3