So, the second main technology I’d like to use is google calenders
Lets have a look at their API 🙂
Now to start out, just looking at the google calender we can see that we can add an event to a previous date as well as edit previous actions. This looks good so far
In all We’re going to be looking for
1) Ability to add an event
2) Ability to edit an event
3) Ability to store Arbitrary Data about what we’re working on
4) Ability to specify a user either based on email address or even better a generic name
Our calander is going to be dependent on the company that uses it as a result we’ll be interested in using
https://www.googleapis.com/calendar/v3/calendars/{your calander id}/events/{the event id}?parameters
as our main Rest Query
To find the calender id
- add a new calender
- go to calender settings
- Find the ID at the very bottom
So Here is the basics of how we’re going to do this…
- Â We create a new event storing…
- User
- Project
- The Start Time as the Event Start, Stop Time = Start Time
- On Clock Out We find
- All events that have the Github User (Sorted by startdate, descending)
- Get The Last one
- (Start time == Stop Time)?Set Stop Time = Date.Now():This user can’t clock out;
Looks good
So First we want to be able to Create events on our calander
Attendee[].email = github email
Attendee[].displayname = github username
summery = github project name
start = date.now()
end = date.now()
(One thing I love about google api’s is they make it real easy for you to try something out)
now Originally, I planned to store the information in attendees and title. But as it turns out, you can’t query attendees nor title… So……
Extended Properties it is!
POST https://www.googleapis.com/calendar/v3/calendars/{your calander ID}/events?key={Your Api Key} { "end":{"dateTime":"2014-1-7T13:31:00-08:00"}, "start:{"dateTime":"2014-1-7T13:31:00-08:00"}, "extendedProperties":{ "shared" : { "user":"github-username", "project":"github-repo" } }, "summary": "git-username worked on github-repo" }
Important to note we want singleEvents to be true in order for us to be able to sort properly and we want to sort by startTime
GET https://www.googleapis.com/calendar/v3/calendars/{google calander id}/events?orderBy=startTime&sharedExtendedProperty=User%3DGU&singleEvents=true&sortorder=descending&key={your api key}
Success, but there’s one problem, the sort order…
currently its ascending which means we’ll get the very first clock in that’s ever be done is the first we’ll receive. When we have 50+ clockins this will be an issue since we’ll have to go through the pages to find the very last clockin.  However, a little research shows we can set the sort order to be descending
Next Thing We Want to do is update on clock out, this will be an update to change its end time
Using the first item (root.items[0]) we’ll grab its ID and make an update, after taking a look at the update though we see we are forced to supply the start time and the end time. Thats more information than we truelly desire to redeliver, as a result we can instead use patch
PATCH https://www.googleapis.com/calendar/v3/calendars/{your calander id}/events/{the event id}?key={your api key} { "end": { "dateTime": "2014-1-7T15:03:00-08:00" } }
And We have it! Clocking in and Clocking out!
There’s other ways we could have done this, for example we could have stored the ID after clockin locally. However if the user changes computers or etc, then we run into an issue. that being said, we can always change that later