package edu.deanza.calendar.models;

import org.joda.time.DateTime;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Sara on 5/28/2016.
 */
public class Event {

    protected String name, description, location;
    protected DateTime startTime, endTime;

    // TODO: implement `categories` field

    public Event() {}

    public Event(String name, String description, String location, String startTime,
                 String endTime) {
        this.name = name;
        this.description = description;
        this.location = location;
        this.startTime = DateTime.parse(startTime);
        this.endTime = DateTime.parse(endTime);

    }

    public static Event fromJson(JSONObject eventJson) {
        Event e = new Event();
        try {
            e.name = eventJson.getString("name");
            e.description = eventJson.getString("description");
            e.location = eventJson.getString("location");
            e.startTime = DateTime.parse(eventJson.getString("start_time"));
            e.endTime = DateTime.parse(eventJson.getString("end_time"));
        }
        catch (JSONException ex) {
            ex.printStackTrace();
            return null;
        }
        return e;
    }

    public String getName() {
        return name;
    }

    public String getDescription() {
        return description;
    }

    public String getLocation() {
        return location;
    }

    public DateTime getStartTime() {
        return startTime;
    }

    public DateTime getEndTime() {
        return endTime;
    }

}
@@ -61,16 +61,43 @@
 teTime;%0A
+import org.json.JSONArray;%0A
 import o
@@ -148,16 +148,45 @@
 bject;%0A%0A
+import java.util.ArrayList;%0A%0A
 /**%0A * C
@@ -772,25 +772,25 @@
 NObject 
-eventJson
+jsonEvent
 ) %7B%0A    
@@ -851,25 +851,25 @@
 .name = 
-eventJson
+jsonEvent
 .getStri
@@ -904,33 +904,33 @@
 scription = 
-eventJson
+jsonEvent
 .getString(%22
@@ -969,25 +969,25 @@
 ation = 
-eventJson
+jsonEvent
 .getStri
@@ -1039,33 +1039,33 @@
 eTime.parse(
-eventJson
+jsonEvent
 .getString(%22
@@ -1122,17 +1122,17 @@
 rse(
-eventJson
+jsonEvent
 .get
@@ -1283,32 +1283,501 @@
 eturn e;%0A    %7D%0A%0A
+    public static ArrayList%3CEvent%3E fromJson(JSONArray jsonEvents) %7B%0A        ArrayList%3CEvent%3E events = new ArrayList%3CEvent%3E(jsonEvents.length());%0A        JSONObject jsonEvent;%0A        for (int i = 0; i %3C jsonEvents.length(); i++) %7B%0A            JSONObject jsonEvent = jsonEvents.getJSONObject(i);%0A            Event event = Event.fromJson(jsonEvent);%0A%0A            if (event != null) %7B%0A                events.add(event)%0A            %7D%0A        %7D%0A        return events%0A    %7D%0A%0A
     public Strin

Add a `fromJson` which returns an ArrayList