tw.yukina.notion.sdk.Test Maven / Gradle / Ivy
package tw.yukina.notion.sdk;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.FixedValue;
import net.sf.cglib.proxy.MethodInterceptor;
import okhttp3.*;
import tw.yukina.notion.sdk.model.block.Block;
import tw.yukina.notion.sdk.model.block.ParagraphBlock;
import tw.yukina.notion.sdk.model.database.Database;
import tw.yukina.notion.sdk.model.deserializer.ZonedDateTimeDeserializer;
import java.io.IOException;
import java.time.ZonedDateTime;
import java.util.Objects;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class Test {
public static void main(String[] args_){
}
public static void testDatabase(){
OkHttpClient client = new OkHttpClient();
okhttp3.Request request = new Request.Builder()
.addHeader("Authorization", "Bearer secret_56Ev2TSAfi62MVHi0W5IZ5gYlKEiAtU0FS46jg22Jzh")
.addHeader("Notion-Version", "2021-05-13")
.url("https://api.notion.com/v1/databases/60380024691046e7a2b426dd15f2a8ac")
.build();
Call call = client.newCall(request);
try {
Response response = call.execute();
// System.out.println(Objects.requireNonNull(response.body()).string());
SimpleModule module = new SimpleModule();
module.addDeserializer(ZonedDateTime.class, new ZonedDateTimeDeserializer());
// module.addDeserializer(Parent.class, new ParentDeserializer());
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(module);
Database database = objectMapper.readValue(Objects.requireNonNull(response.body()).string(), Database.class);
System.out.println(database.toString());
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void testBlock(){
OkHttpClient client = new OkHttpClient();
okhttp3.Request request = new Request.Builder()
.addHeader("Authorization", "Bearer secret_56Ev2TSAfi62MVHi0W5IZ5gYlKEiAtU0FS46jg22Jzh")
.addHeader("Notion-Version", "2021-05-13")
.url("https://api.notion.com/v1/blocks/f1ea3ded442a449bb79185c41fefbd02")
.build();
Call call = client.newCall(request);
try {
Response response = call.execute();
// System.out.println(Objects.requireNonNull(response.body()).string());
SimpleModule module = new SimpleModule();
module.addDeserializer(ZonedDateTime.class, new ZonedDateTimeDeserializer());
// module.addDeserializer(Parent.class, new ParentDeserializer());
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(module);
ParagraphBlock block = (ParagraphBlock) objectMapper.readValue(Objects.requireNonNull(response.body()).string(), Block.class);
System.out.println(block.toString());
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}