package com.jaybon.movieapp;
import java.util.List;
import lombok.Data;
@Data
public class YtsData {
private String status;
private String status_message;
private MyData data;
@Data
public class MyData { // 외부에서 접근할 필요가 있는 것은 public
private int movie_count;
private int limit;
private int page_number;
private List<Movie> movies;
@Data
class Movie{
private String title;
private float rating;
private String medium_cover_image;
}
}
}
레트로핏 서비스(레파지토리) 예시
package com.jaybon.movieapp;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.GET;
import retrofit2.http.Path;
import retrofit2.http.Query;
// YtsService 또는 레파지토리로 만들면된다
public interface YtsService {
@GET("list_movies.json")
Call<YtsData> 영화목록가져오기(
@Query("sort_by") String sort_by,
@Query("limit") int limit,
@Query("page") int page
);
// onCreate에서 안만들고 여기서 바로 만들어버림
// 서비스가 많아지면 컨피그 인터페이스 파일 만들어서 세팅
public static final Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://yts.mx/api/v2/")
.addConverterFactory(GsonConverterFactory.create())
.build();
}
package com.jaybon.retrofit2ex01;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Yts {
public String status;
public String statusMessage;
public Data data;
public Meta meta;
@lombok.Data
public class Data {
public long movieCount;
public long limit;
public long pageNumber;
public List<Movie> movies = null;
@lombok.Data
public class Movie {
public long id;
public String url;
public String imdbCode;
public String title;
public String titleEnglish;
public String titleLong;
public String slug;
public long year;
public double rating;
public long runtime;
public List<String> genres = null;
public String summary;
public String descriptionFull;
public String synopsis;
public String ytTrailerCode;
public String language;
public String mpaRating;
public String backgroundImage;
public String backgroundImageOriginal;
public String smallCoverImage;
public String mediumCoverImage;
public String largeCoverImage;
public String state;
public List<Torrent> torrents = null;
public String dateUploaded;
public long dateUploadedUnix;
@lombok.Data
public class Torrent {
public String url;
public String hash;
public String quality;
public String type;
public long seeds;
public long peers;
public String size;
public long sizeBytes;
public String dateUploaded;
public long dateUploadedUnix;
}
}
}
@lombok.Data
public class Meta {
public long serverTime;
public String serverTimezone;
public long apiVersion;
public String executionTime;
}
}
package com.jaybon.retrofit2ex01;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class User {
public long id;
public String username;
public String password;
public String email;
public Object profile;
public String createDate;
}