Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bertrandmartel/gcalendar-notification-server
Google calendar embedded notification server
https://github.com/bertrandmartel/gcalendar-notification-server
Last synced: 4 days ago
JSON representation
Google calendar embedded notification server
- Host: GitHub
- URL: https://github.com/bertrandmartel/gcalendar-notification-server
- Owner: bertrandmartel
- License: mit
- Created: 2015-08-09T19:41:39.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-12-25T23:38:40.000Z (almost 8 years ago)
- Last Synced: 2023-03-01T16:41:52.535Z (over 1 year ago)
- Language: Java
- Size: 1.5 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Google Calendar event notification server #
http://bertrandmartel.github.io/gcalendar-notification-serverLast update on 09/08/2015
Embedded google calendar event notification server through Google Calendar API (Oauth2.0)
This project is an alternative for "end device" to Google Calendar push notification (https://developers.google.com/google-apps/calendar/v3/push?hl=en) where you need to have a domain receiving your notifications which force your application to have a back end realizing the job for your client.
2 parts are featured :
* gcalendar-notification-lib which is library you would used to manage Google Calendar API and process events notifications
* gcalendar-notification-webserver which is a server implementation and message process management which expose its API for a web clientIf you have your own server implementation, you can integrate gcalendar-notification-lib separately without the server part
What does it do ?
* receive notifications of all events you have subscribed through gcalendar-notification-lib APIs that are pushed to a web client
* subscribe/unsubscribe to a precise event
* create an event (with date start, date end and summary)
* delete an event
* retrieve list of Google calendar events for a specific date time range and optionnal text filter
* retrieve basic user profile information
* request an access token that will be used to request Google API for the scope Profile and Calendar
* revoke an access token (if you want to)
* register through Oauth2.0[ ! ] Event creation is very basic for now (date start / date begin and summary) but is a good medium to test notifications
Run the testing server app
``git clone [email protected]:bertrandmartel/gcalendar-notification-server.git``
``cd gcalendar-notification-server/gcalendar-notification-webserver/release``
``java -jar gcalendar-notification-client-webserver-1.0.jar webPath=/gcalendar-notification-server/web clientId= clientSecret=``
_ replace with your path prior to gcalendar-notification-webserver
_ replace and with the ones you got from google developper console* go to you browser : http://localhost:4242/gcalendar
* now you can click on "start registration" button to request registration. You will see a verification url appear and a user code.
If you dont see these two features appear maybe you have a problem with your client id / client secret
* go to specified URL and authorize access from Google API.
* once it is done, you can click on "request token" button, and shortly a token will appear
![screenshot](https://raw.github.com/bertrandmartel/gcalendar-notification-server/master/sh.png)
* From this moment you will have access to "user profile", "calendar events", "create event" and "delete event" buttons
* You can create a fake event of your own with "create event" button putting the date time range of your choice
* You can subscribe to events to come (even events already existing) and you will see a notification coming to your window when event will be about to start (60 seconds befor event) or when the event has actually started
In your console you can see talk between client and server :
![screenshot](https://raw.github.com/bertrandmartel/gcalendar-notification-server/master/sh2.png)Oauth2.0 for device registration
```
String yourOwnClientId="812741506391-h38jh0j4fv0ce1krdkiq0hfvt6n5amrf.apps.googleusercontent.com";
String yourClientSecret="1912308409123890";
```Now you can instantiate ``AuthenticationManager`` class :
```
CalendarNotifManager calendarNotifManager = new CalendarNotifManager(yourOwnClientId, yourClientSecret);
```Then you can request authentication :
```
calendarNotifManager.requestDeviceAuth(new IOauthDeviceResponseListener() {@Override
public void onResponseReceived(OauthForDeviceResponse response) {
/* callback called when response is received from server*/}
});
```Description of ``OauthForDeviceResponse`` :
* ``getVerificationUrl()`` : url from which user will log and therefore authorize your server to request token
* ``getUserCode()`` : code that user will reproduce exactly in the latter verification url
* ``getDeviceCode()`` : code identifying your server which is viewed as an end device requesting google api
* ``getExpiringBefore()`` : life time of your usercode in seconds
* ``getInterval()`` : time interval between a next attempt in secondsThe verification url is displayed to the user via a web client.
The user will reproduce the user code from the same web client and authorize the server to request token.
From this point you will be able to request token.The whole authentication process is described in https://developers.google.com/identity/protocols/OAuth2ForDevices
Request for access token
```
calendarNotifManager.requestToken(new IRequestTokenListener() {@Override
public void onRequestTokenReceived(OauthToken token) {
//access token is received
}@Override
public void onRequestTokenError(String description) {
//an error occured requesting access token
}
});
```Once you have received a token you can access Google calendar API and profile.
Request user profile
```
calendarNotifManager.getUserProfileManager().getUserProfile(new IUserProfileListener() {@Override
public void onSuccess(UserProfile userProfile) {// user profile received succcessfully :
//userProfile.getGender()
//userProfile.getDisplayName()
//userProfile.getFamilyName()
//userProfile.getGivenName()
//userProfile.getLanguage()
}@Override
public void onError(String description) {
//an error occured requesting user profile
}
});
```Request calendar events
You can request event with date time range from ``dateBegin`` to ``dateEnd`` with these two values in String timestamp format according RFC 3339 (ex: 2015-08-06T23:30:20+02:00)
You can optionnaly add a text filter```
calendarNotifManager.getCalendarManager().getEventList(dateBegin, dateEnd, searchText, new IEventListListener() {@Override
public void onEventListReceived(List calendarEventList) {
//list of calendar events retrieved
}@Override
public void onError(String description) {
//an error occured requesting calendar events
}
});
```Here is description of one event in List retrieved :
* ``String getEventId()`` : event identifier
* ``String getStatus()``: event status
* ``String getDateCreated()`` : creation date of the event
* ``String getDateUpdated()`` : date of event udpate
* ``String getSummary()`` : event summary
* ``String getCreatorEmail()`` : event creator email
* ``String getCreatorDisplayName()`` : event creator display name
* ``boolean isCreatorSelf()`` : true if the event was created by calendar's owner
* ``String getOrganizerEmail()`` : event organizer email
* ``String getOrganizerDisplayName()`` : event organizer display name
* ``boolean isOrganizerSelf()`` : true if event organizer is calendar's owner
* ``String getDateStart()`` : event date start
* ``String getDateEnd()`` : event date end
* ``String getDateTimeStart()`` : event date and time start
* ``String getDateTimeEnd()`` : event date and time end
* ``boolean isSubscribed()`` : define if this event is subscribed or not (you will receive notification if true)Create event
You can create an event with begin and end date time of this event in String timestamp format according to RFC 3339 (ex: 2015-08-06T23:30:20+02:00) and precise a summary for this event.
```
calendarNotifManager.getCalendarManager().createEvent(dateBegin, dateEnd, summary, new ICreateEventListener() {@Override
public void onCreateSuccess(String id) {
// event has been successfully created. The event id is returned on creation success
}@Override
public void onError(String description) {
//an error occured during event creation
}});
```Delete event
You can delete an evetn by ``eventId``
```
calendarNotifManager.getCalendarManager().deleteEvent(eventId, new IDeleteEventListener() {@Override
public void onSuccess() {
//event has been deleted
}@Override
public void onError(String description) {
//an error occured during deletion process
}
});
```Event notification : subscription
You can be notified for a specified event referenced by its ``eventId``. You will be notified when the event start and you can parameter the time in seconds before it actually starts when you want to be notified.
If you want to be notified one minute before the event start replace ``timeAboutToStart`` by 60
```
calendarNotifManager.getNotificationManager().subscribeEvent(eventId, timeAboutToStart, new IEventListener() {@Override
public void onEventStart(String eventId, String summary) {
//called when the event start
}@Override
public void onEventAboutToStart(String eventId, String summary) {
//called when the event is about to start (if you put a value >0 for timeAboutToStart parameter)
}
});
```Unsubscribtion
```
calendarNotifManager.getNotificationManager().unsubscribeEvent(eventId);
```Get an Oauth2.0 token from Google developper console
For your application to be abled to request token for Oauth2.0 google API, you have to get one Oauth2.0 token from https://console.developers.google.com
* First create a project
* in "credentials" tab "create a new client ID" choose "installed application",quote "other" and "create client ID"
* in "consent screen" tab choose tour email address and a product name (it should apparently match your project id name but I may be wrong here)Now in "crendentials" tab you should have an Oauth2.0 token client ID that looks like :
``812741506391-h38jh0j4fv0ce1krdkiq0hfvt6n5amrf.apps.googleusercontent.com``* In "API" tab select "Google + API" and enable it
* In "API" tab select "Calendar API" and enable itExternal JAVA Library
* json-simple : http://code.google.com/p/json-simple/
* clientsocket : https://github.com/bertrandmartel/socket-multiplatform/tree/master/client/socket-client/java
* http-endec : https://github.com/bertrandmartel/http-endec-java
* serversocket : https://github.com/bertrandmartel/socket-multiplatform/tree/master/server/server-socket/blocking/java
* websocket-java : https://github.com/bertrandmartel/websocket-java
External UI features
* datetimepicker : https://github.com/xdan/datetimepicker by Chupurnov Valeriy
* notification message using css3 : https://dhirajkumarsingh.wordpress.com/2012/05/06/cool-notification-messages-with-css3-jquery/
TODO
* stock raw configuration of events subscribed
* improve "create event" input arguments (attendees / place ...)
* configurable polling of "getEventList" API in case of concurrent modifications