-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBookableAvailability.java
More file actions
85 lines (67 loc) · 2.29 KB
/
BookableAvailability.java
File metadata and controls
85 lines (67 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package bookingbugAPI.models;
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
import com.theoryinpractise.halbuilder.api.ContentRepresentation;
import com.theoryinpractise.halbuilder.api.ReadableRepresentation;
import helpers.HttpServiceResponse;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
/**
* Created by sebi on 26.02.2016.
*/
public class BookableAvailability extends BBRoot {
public BookableAvailability(HttpServiceResponse httpServiceResponse){
super(httpServiceResponse);
}
public BookableAvailability(HttpServiceResponse httpServiceResponse, String auth_token){
super(httpServiceResponse);
this.auth_token = auth_token;
}
public BookableAvailability() {}
public String getName(){
return get("name");
}
public String getEvent_id(){
return get("event_id");
}
public String getDate(){
return get("date");
}
public Date getDateTimeObj(){
Date datetime = null;
try {
datetime = new ISO8601DateFormat().parse(get("date"));
} catch (ParseException | NullPointerException e) {
//e.printStackTrace();
log.warning("Cannot parse datetime format: " + e.toString());
}
return datetime;
}
public ArrayList<AvailTime> getAvailTimes(){
ArrayList<ReadableRepresentation> times_reps = new ArrayList<>(getRep().getResourcesByRel("times"));
ArrayList<AvailTime> times = new ArrayList<>();
for (ReadableRepresentation rep : times_reps) {
AvailTime timeObj = new AvailTime();
timeObj.time_minutes = Integer.parseInt((String) rep.getValue("time"));
timeObj.avail = Integer.parseInt((String) rep.getValue("avail")) == 1 ? true : false;
timeObj.price = Integer.parseInt((String) rep.getValue("price"));
times.add(timeObj);
}
return times;
}
public static class AvailTime {
int time_minutes;
boolean avail;
int price;
public int getTime_minutes() {
return time_minutes;
}
public boolean isAvail() {
return avail;
}
public int getPrice() {
return price;
}
}
}