first implementation of api.media.ccc.de-bindings

This commit is contained in:
Felix 2017-03-17 23:21:46 +01:00
parent 444b6f6bad
commit d24b489daf
7 changed files with 679 additions and 0 deletions

View file

@ -0,0 +1,162 @@
package de.nicidienase.chaosflix.entities;
import com.orm.SugarRecord;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
* Created by felix on 11.03.17.
*/
public class Conference extends SugarRecord{
String acronym;
String aspectRation;
String title;
String slug;
String webgen_location;
String scheduleUrl;
String logoUrl;
String imagesUrl;
String recordingsUrl;
String url;
String updatedAt;
List<Event> events;
public Conference() {
}
public Conference(String acronym, String aspectRation, String title, String slug,
String webgen_location, String scheduleUrl, String logoUrl,
String imagesUrl, String recordingsUrl, String url,
String updatedAt, List<Event> events) {
this.acronym = acronym;
this.aspectRation = aspectRation;
this.title = title;
this.slug = slug;
this.webgen_location = webgen_location;
this.scheduleUrl = scheduleUrl;
this.logoUrl = logoUrl;
this.imagesUrl = imagesUrl;
this.recordingsUrl = recordingsUrl;
this.url = url;
this.updatedAt = updatedAt;
this.events = events;
}
public HashMap<String, List<Event>> getEventsByTags(){
HashMap<String, List<Event>> result = new HashMap<>();
for(Event event: this.getEvents()){
for(String tag: event.getTags()){
List<Event> list;
if(result.keySet().contains(tag)){
list = result.get(tag);
} else {
list = new LinkedList<>();
result.put(tag,list);
}
list.add(event);
}
}
return result;
}
public String getAcronym() {
return acronym;
}
public void setAcronym(String acronym) {
this.acronym = acronym;
}
public String getAspectRation() {
return aspectRation;
}
public void setAspectRation(String aspectRation) {
this.aspectRation = aspectRation;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getSlug() {
return slug;
}
public void setSlug(String slug) {
this.slug = slug;
}
public String getWebgen_location() {
return webgen_location;
}
public void setWebgen_location(String webgen_location) {
this.webgen_location = webgen_location;
}
public String getScheduleUrl() {
return scheduleUrl;
}
public void setScheduleUrl(String scheduleUrl) {
this.scheduleUrl = scheduleUrl;
}
public String getLogoUrl() {
return logoUrl;
}
public void setLogoUrl(String logoUrl) {
this.logoUrl = logoUrl;
}
public String getImagesUrl() {
return imagesUrl;
}
public void setImagesUrl(String imagesUrl) {
this.imagesUrl = imagesUrl;
}
public String getRecordingsUrl() {
return recordingsUrl;
}
public void setRecordingsUrl(String recordingsUrl) {
this.recordingsUrl = recordingsUrl;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(String updatedAt) {
this.updatedAt = updatedAt;
}
public List<Event> getEvents() {
return events;
}
public void setEvents(List<Event> events) {
this.events = events;
}
}

View file

@ -0,0 +1,21 @@
package de.nicidienase.chaosflix.entities;
import com.orm.SugarRecord;
import java.util.List;
/**
* Created by felix on 17.03.17.
*/
public class Conferences extends SugarRecord{
List<Conference> conferences;
public List<Conference> getConferences() {
return conferences;
}
public void setConferences(List<Conference> conferences) {
this.conferences = conferences;
}
}

View file

@ -0,0 +1,185 @@
package de.nicidienase.chaosflix.entities;
import com.orm.SugarRecord;
import java.util.Date;
import java.util.List;
/**
* Created by felix on 11.03.17.
*/
public class Event extends SugarRecord {
String guid;
String title;
String subtitle;
String slug;
String link;
String description;
String originalLanguage;
List<String> persons;
List<String> tags;
Date date;
Date releaseDate;
Date updatedAt;
long length;
String thumbUrl;
String posterUrl;
String frontendLink;
String url;
String conferenceUrl;
List<Recording> recordings;
public String getGuid() {
return guid;
}
public void setGuid(String guid) {
this.guid = guid;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getSubtitle() {
return subtitle;
}
public void setSubtitle(String subtitle) {
this.subtitle = subtitle;
}
public String getSlug() {
return slug;
}
public void setSlug(String slug) {
this.slug = slug;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getOriginalLanguage() {
return originalLanguage;
}
public void setOriginalLanguage(String originalLanguage) {
this.originalLanguage = originalLanguage;
}
public List<String> getPersons() {
return persons;
}
public void setPersons(List<String> persons) {
this.persons = persons;
}
public List<String> getTags() {
return tags;
}
public void setTags(List<String> tags) {
this.tags = tags;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public Date getReleaseDate() {
return releaseDate;
}
public void setReleaseDate(Date releaseDate) {
this.releaseDate = releaseDate;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public long getLength() {
return length;
}
public void setLength(long length) {
this.length = length;
}
public String getThumbUrl() {
return thumbUrl;
}
public void setThumbUrl(String thumbUrl) {
this.thumbUrl = thumbUrl;
}
public String getPosterUrl() {
return posterUrl;
}
public void setPosterUrl(String posterUrl) {
this.posterUrl = posterUrl;
}
public String getFrontendLink() {
return frontendLink;
}
public void setFrontendLink(String frontendLink) {
this.frontendLink = frontendLink;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getConferenceUrl() {
return conferenceUrl;
}
public void setConferenceUrl(String conferenceUrl) {
this.conferenceUrl = conferenceUrl;
}
public List<Recording> getRecordings() {
return recordings;
}
public void setRecordings(List<Recording> recordings) {
this.recordings = recordings;
}
}

View file

@ -0,0 +1,147 @@
package de.nicidienase.chaosflix.entities;
import com.orm.SugarRecord;
import java.util.Date;
/**
* Created by felix on 17.03.17.
*/
public class Recording extends SugarRecord {
int size;
int length;
String mime_type;
String language;
String filename;
String state;
String folder;
boolean high_quality;
int width;
int height;
String updated_at;
String recording_url;
String url;
String event_url;
String conference_url;
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public String getMime_type() {
return mime_type;
}
public void setMime_type(String mime_type) {
this.mime_type = mime_type;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getFolder() {
return folder;
}
public void setFolder(String folder) {
this.folder = folder;
}
public boolean isHigh_quality() {
return high_quality;
}
public void setHigh_quality(boolean high_quality) {
this.high_quality = high_quality;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public String getUpdated_at() {
return updated_at;
}
public void setUpdated_at(String updated_at) {
this.updated_at = updated_at;
}
public String getRecording_url() {
return recording_url;
}
public void setRecording_url(String recording_url) {
this.recording_url = recording_url;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getEvent_url() {
return event_url;
}
public void setEvent_url(String event_url) {
this.event_url = event_url;
}
public String getConference_url() {
return conference_url;
}
public void setConference_url(String conference_url) {
this.conference_url = conference_url;
}
}

View file

@ -0,0 +1,49 @@
package de.nicidienase.chaosflix.network;
import java.util.List;
import de.nicidienase.chaosflix.entities.Conference;
import de.nicidienase.chaosflix.entities.Conferences;
import de.nicidienase.chaosflix.entities.Event;
import de.nicidienase.chaosflix.entities.Recording;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.Path;
/**
* Created by felix on 17.03.17.
*/
public class MediaCCCClient implements MediaCCCService{
private final MediaCCCService service;
public MediaCCCClient() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.media.ccc.de")
.addConverterFactory(GsonConverterFactory.create())
.build();
service = retrofit.create(MediaCCCService.class);
}
@Override
public Call<Conferences> listConferences() {
return service.listConferences();
}
@Override
public Call<Conference> getConference(@Path("id") int id) {
return service.getConference(id);
}
@Override
public Call<Event> getEvent(@Path("id") int id) {
return service.getEvent(id);
}
@Override
public Call<Recording> getRecording(@Path("id") int id) {
return service.getRecording(id);
}
}

View file

@ -0,0 +1,31 @@
package de.nicidienase.chaosflix.network;
import java.util.List;
import de.nicidienase.chaosflix.entities.Conference;
import de.nicidienase.chaosflix.entities.Conferences;
import de.nicidienase.chaosflix.entities.Event;
import de.nicidienase.chaosflix.entities.Recording;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;
/**
* Created by felix on 17.03.17.
*/
public interface MediaCCCService {
@GET("public/conferences")
Call<Conferences> listConferences();
@GET("public/conferences/{id}")
Call<Conference> getConference(@Path("id") int id);
@GET("public/events/{id}")
Call<Event> getEvent(@Path("id") int id);
@GET("public/recordings/{id}")
Call<Recording> getRecording(@Path("id") int id);
}

View file

@ -0,0 +1,84 @@
package de.nicidienase.chaosflix;
import static org.junit.Assert.*;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import de.nicidienase.chaosflix.entities.Conference;
import de.nicidienase.chaosflix.entities.Conferences;
import de.nicidienase.chaosflix.entities.Event;
import de.nicidienase.chaosflix.entities.Recording;
import de.nicidienase.chaosflix.network.MediaCCCClient;
/**
* Created by felix on 17.03.17.
*/
public class MediaCCCClientTest{
@Test
public void getConferenceTest(){
try {
Conference conference = new MediaCCCClient().getConference(101).execute().body();
assertEquals(conference.getAcronym(),"33c3");
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void getEventTest(){
try {
Event event = new MediaCCCClient().getEvent(3674).execute().body();
assertEquals(event.getGuid(),"bfc2ab1f-8384-4d7d-801a-dde8c81e039c");
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void getEventRecordingsTest(){
try {
Event event = new MediaCCCClient().getEvent(3674).execute().body();
assertEquals(event.getRecordings().size(),9);
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void getRecordingTest(){
try {
Recording recording = new MediaCCCClient().getRecording(14142).execute().body();
assertEquals(recording.getUpdated_at(), "2016-12-29T03:16:16.105+01:00");
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void getConferencEventListTest(){
try {
Conferences conferences = new MediaCCCClient().listConferences().execute().body();
assertEquals(99,conferences.getConferences().size());
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void eventTagsTest(){
try {
Conference conference = new MediaCCCClient().getConference(101).execute().body();
assertEquals(12,conference.getEventsByTags().keySet().size());
} catch (IOException e) {
e.printStackTrace();
}
}
}