Skip to content

Commit 49f7312

Browse files
committed
Merge pull request #6 from ccpmark/feature/free-busy-spaces
Free-busy spaces
2 parents 7347aa7 + 37f4e20 commit 49f7312

5 files changed

Lines changed: 224 additions & 4 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.robinpowered.sdk.model;
2+
3+
import org.joda.time.DateTime;
4+
5+
import java.util.List;
6+
7+
/**
8+
* A period of time that a {@link Space} is unavailable for. <p>
9+
*
10+
* Contains a grouping of all events that occur within this unavailable block of time. When the
11+
* gap between events is shorter than the duration requested, the events will be grouped
12+
* together in a single Busy container.
13+
*/
14+
public class Busy {
15+
16+
/**
17+
* Constants
18+
*/
19+
20+
public static final String MIME_TYPE = "vnd.robinpowered.busy.v1";
21+
22+
23+
/**
24+
* Properties
25+
*/
26+
27+
private DateTime from;
28+
private DateTime to;
29+
private List<SimpleEvent> events;
30+
31+
32+
/**
33+
* Methods
34+
*/
35+
36+
/**
37+
* Constructor.
38+
*
39+
* @param from The start of the busy period.
40+
* @param to The end of the busy period.
41+
* @param events The {@link Event Events} occurring throughout the busy period.
42+
*/
43+
public Busy(DateTime from, DateTime to, List<SimpleEvent> events) {
44+
this.from = from;
45+
this.to = to;
46+
this.events = events;
47+
}
48+
49+
public static String getMimeType() {
50+
return MIME_TYPE;
51+
}
52+
53+
public List<SimpleEvent> getSimpleEvents() {
54+
return events;
55+
}
56+
57+
public DateTime getFrom() {
58+
return from;
59+
}
60+
61+
public DateTime getTo() {
62+
return to;
63+
}
64+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.robinpowered.sdk.model;
2+
3+
import java.util.List;
4+
5+
/**
6+
* An interface for Free-busy information returned for different models.
7+
*/
8+
public interface FreeBusy {
9+
10+
/**
11+
* Returns a list of {@link Busy} intervals for which the given model is unavailable.
12+
*
13+
* @return A list of {@link Busy} intervals.
14+
*/
15+
List<Busy> getBusy();
16+
17+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.robinpowered.sdk.model;
2+
3+
import java.util.List;
4+
5+
/**
6+
* Free-busy information returned for a given {@link Space} across a requested period of time. <p>
7+
*
8+
* Free-busy information describes the availability of a {@link Space} throughout a period of time
9+
* by returning a set of {@link Busy} intervals which contain all events which overlap the requested
10+
* period of time. The given space is available for the requested duration during any gaps between
11+
* {@link Busy} models.
12+
*/
13+
public class FreeBusySpace implements ApiResponseModel, FreeBusy {
14+
15+
/**
16+
* Constants
17+
*/
18+
19+
public static final String MIME_TYPE = "vnd.robinpowered.free-busy-space.v1";
20+
21+
22+
/**
23+
* Properties
24+
*/
25+
26+
private boolean hasPresence;
27+
private Space space;
28+
private List<Busy> busy;
29+
30+
31+
/**
32+
* Methods
33+
*/
34+
35+
public FreeBusySpace(boolean hasPresence, Space space, List<Busy> busy) {
36+
this.hasPresence = hasPresence;
37+
this.space = space;
38+
this.busy = busy;
39+
}
40+
41+
@Override
42+
public String getMimeType() {
43+
return MIME_TYPE;
44+
}
45+
46+
public boolean hasPresence() {
47+
return hasPresence;
48+
}
49+
50+
public Space getSpace() {
51+
return space;
52+
}
53+
54+
public List<Busy> getBusy() {
55+
return busy;
56+
}
57+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.robinpowered.sdk.model;
2+
3+
import com.google.common.base.Objects;
4+
5+
import org.joda.time.DateTime;
6+
7+
/**
8+
* A simplified {@link Event}.
9+
*
10+
* <p>
11+
* A simplified version of an event containing start and end times, as well as a matching ID for
12+
* referencing the associated {@link Event}.
13+
*/
14+
public class SimpleEvent implements ApiResponseModel {
15+
16+
/**
17+
* Constants
18+
*/
19+
20+
public static final String MIME_TYPE = "vnd.robinpowered.simple-event.v1";
21+
22+
23+
/**
24+
* Properties
25+
*/
26+
27+
private int id;
28+
private DateTime startedAt;
29+
private DateTime endedAt;
30+
31+
32+
/**
33+
* Methods
34+
*/
35+
36+
/**
37+
* Constructs a SimpleEvent.
38+
*
39+
* @param id The id of the event.
40+
* @param startedAt When the event started.
41+
* @param endedAt When the event ended.
42+
*/
43+
public SimpleEvent(int id, DateTime startedAt, DateTime endedAt) {
44+
this.id = id;
45+
this.startedAt = startedAt;
46+
this.endedAt = endedAt;
47+
}
48+
49+
@Override
50+
public boolean equals(Object that) {
51+
if (this == that) return true;
52+
if (that == null || !(that instanceof SimpleEvent)) return false;
53+
return Objects.equal(id, ((SimpleEvent) that).id);
54+
}
55+
56+
@Override
57+
public String getMimeType() {
58+
return MIME_TYPE;
59+
}
60+
61+
public int getId() {
62+
return id;
63+
}
64+
65+
public DateTime getStartedAt() {
66+
return startedAt;
67+
}
68+
69+
public DateTime getEndedAt() {
70+
return endedAt;
71+
}
72+
}

src/main/java/com/robinpowered/sdk/service/EventService.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
import com.robinpowered.sdk.http.DELETE;
44
import com.robinpowered.sdk.model.ApiResponse;
55
import com.robinpowered.sdk.model.Event;
6+
import com.robinpowered.sdk.model.FreeBusySpace;
67
import com.robinpowered.sdk.model.User;
8+
9+
import java.io.IOException;
10+
import java.util.List;
11+
import java.util.Map;
12+
713
import retrofit.Callback;
814
import retrofit.http.Body;
915
import retrofit.http.GET;
@@ -12,10 +18,6 @@
1218
import retrofit.http.Path;
1319
import retrofit.http.QueryMap;
1420

15-
import java.io.IOException;
16-
import java.util.List;
17-
import java.util.Map;
18-
1921
public interface EventService {
2022

2123
// Sync
@@ -92,6 +94,14 @@ public interface EventService {
9294
@POST("/spaces/{spaceId}/events")
9395
void bookSpace(@Path("spaceId") int spaceId, @Body Event.Booking eventBooking, Callback<ApiResponse<Event>> callback);
9496

97+
// Sync
98+
@GET("/free-busy/spaces")
99+
ApiResponse<List<FreeBusySpace>> getFreeBusyForSpaces(@QueryMap Map<String, Object> options) throws IOException;
100+
101+
// Async
102+
@GET("/free-busy/spaces")
103+
void getFreeBusyForSpaces(@QueryMap Map<String, Object> options, Callback<ApiResponse<List<FreeBusySpace>>> callback);
104+
95105

96106
/**
97107
* For users

0 commit comments

Comments
 (0)