Hello World: Google Calanders

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

  1. add a new calender
    google calander
  2. go to calender settings
    calander settings
  3. Find the ID at the very bottom
    calander id

 

So Here is the basics of how we’re going to do this…

  1.  We create a new event storing…
    1. User
    2. Project
    3. The Start Time as the Event Start, Stop Time = Start Time
  2. On Clock Out We find
    1. All events that have the Github User (Sorted by startdate, descending)
    2. Get The Last one
      1. (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"
}

Next we want to request

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

Hello World: Github

So I need to create an application to interact with Github
What I want…

  1. The Current Users Available Repos-Save the User ID
  2. Ability to access a specific Repo-Save the Repo ID
  3. Ability to show work done on that repo

Following the API, here are the basics

GET https://api.github.com/users/formula1/repos with a header specifying version 3

Click to get Current Repos
Click for something pretty
Click to hide

Now this is good for just me, but what about anyone who want to clock in? I need to authenticate… I’ll get to this later

Now, to be able to choose a repo and see the work Click Here

Now the instance work isn’t nearly as important since I can’t quantify that quite same as I can quantify times. However, that is possible as well.

 

Heres the Source code. Simple but straight forward.

jQuery(function(){ jQuery(".githubrepo").click(function(e){  e.preventDefault(); 
 jQuery.ajax({
 url: "https://api.github.com/users/formula1/repos",
 type: "GET",
 beforeSend: function(xhr){
 xhr.setRequestHeader('Accept','application/vnd.github.v3.full');
 },
}).done(function(content){ 
 jQuery("#github-repos-example").text(JSON.stringify(content)); 
 }); 
});
jQuery(".githubpretty").click(function(e){ 
 e.preventDefault(); 
 jQuery.ajax({
 url: "https://api.github.com/users/formula1/repos",
 type: "GET",
 beforeSend: function(xhr){
 xhr.setRequestHeader('Accept','application/vnd.github.v3.full');
 },
}).done(function(content){ 
 for(var i=0;i<content.length;i++){
 jQuery("#github-repos-example").append("<span style='display:inline-block; padding:10px; background:#000; color: #FFF;margin:1px;'>"+content[i].full_name+"</span>");
 }
 }); 
});

jQuery(".githubhide").click(function(e){
e.preventDefault();
 jQuery("#github-repos-example").text("");
});
jQuery(".githubproj").click(function(e){
 e.preventDefault(); 
 jQuery.ajax({
 url: "https://api.github.com/users/formula1/repos",
 type: "GET",
 beforeSend: function(xhr){
 xhr.setRequestHeader('Accept','application/vnd.github.v3.full');
 },
 }).done(function(content){ 
 jQuery("#github-repos-example2").text("");
 for(var i=0;i<content.length;i++){
 jQuery("#github-repos-example2").append("<a href='"+content[i].url+"/commits' style='display:inline-block; padding:10px; background:#000; color: #FFF;margin:1px;'>"+content[i].full_name+"</a>"
 );
 }
 jQuery("#github-repos-example2>a").click(function(e){
 e.preventDefault();
 jQuery.ajax({
 url: jQuery(this).attr("href"),
 type: "GET",
 beforeSend: function(xhr){
 xhr.setRequestHeader('Accept','application/vnd.github.v3.full');
 },
 }).done(function(content){ 
 jQuery("#github-repos-example2").text("");
 for(var i=0;i<content.length;i++){
 jQuery("#github-repos-example2").append("<div style='border:1px solid #000;'><span>Date: "+content[i].commit.committer.date+"</span><br/><span>Name: "+content[i].commit.committer.name+"</span><br/><span>Message: "+content[i].commit.message+"</span></div>"
 )
 }
 });
 }); 
 }); 
});
});


 

A ReEntry to WordPress

I build wordpress for clients mostly, but had big plans for my own website. However, after a month of work and a lot of research I’ve come to understand what it really means to… create a content management system. There are many things to keep in mind, access to your database, providing a nice looking interface. Making things simple yet also allowing complete customization. The User Object. Which should be static methods, which should be instance? There is a lot too it, and I finally had decided that getting my website up and running is far more important than spending years on a website that (no offense to websites) is not very high on my priority list.

What I will say though is
1) CMS’ are meant to be easy to install, easy to begin and easy to use
-Wordpress is absolutely adorable compared to what I had been working on so hard for most of my workday.
2) CMS’s data are meant to be transportable
-Now wordpress isn’t necessarilly transportable, however you can definitely export your data as a solid XML file and due to its popularity importable as well
-for my own work, its definitely obvious I won’t be accessing the data quite so soon. Exporting to XML is the easy part, importing is a completely seperate beast
3) If your going to make a user interface make you can use it again
-for me I wanted to use XSL badly, and I still do. But the complexity in automation turned an interesting idea into a beast of its own. I’ll talk about it later when I get back into it. However, the important parts isn’t the XSL but rather the HTML. css and javascript
4) Routing is one if not the most important part of a CMS
-User Permissions are based off what is asked for
-Automation is very very important when dealing with an unknown amount of objects with unknown methods
-These are two things that held me back the most

Now I can’t say I want to use wordpress, but I definitely prefer it currently over slaving away for hours inorder to give myself more hurdles. Having the requirements change, introducing new technology mid project, these are things I’ll have to deal regardless. However, to me, finishing something is far more important than making it perfect.