프로젝트 개요

기능

목적

방법

1. Leopold 공지사항 가져오기

참고

retrofit2 3요소

  1. interface
public interface LeopoldApi{

    @GET("Shop/Board.php?BoTable=Notice")
		Call<ResponseBody> getLeopoldNotice();
}
  1. retrofit2 구현
@Component
@Slf4j
public class LeopoldApiCaller {
    private final LeopoldApileopoldApi;

    public LeopoldApiCaller(@Value("${api.leopold.base-url}") StringbaseUrl) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(baseUrl)
                .build();

        leopoldApi = retrofit.create(LeopoldApi.class);
    }

    public String getLeopoldNotice() {
        try {
            var call = leopoldApi.getLeopoldNotice();

            return call.execute().body().string();

        } catch (IOExceptione) {
log.error("Get Leopold Notice Exception : " +e.getMessage());
            throw new RuntimeException("Get Leopold Notice Exception : " +e.getMessage());
        }
    }
}