Import external ICS with EWS - calendar

Using Exchange Web Services (EWS), I try to import an ICS from URL.
I followed the official documentation : Use the EWS Managed API to import an appointment from an iCal file by using the MIME stream
I'm using EWS Java Api with the following code
var icsApp = new Appointment(ews);
var url = "https://calendar.google.com/calendar/ical/fnb4irrd2df506r50u6fruhqfo%40group.calendar.google.com/public/basic.ics";
byte [] icsContent = IOUtils.toByteArray(new URI(url));
icsApp.setMimeContent(new MimeContent("UTF-8", icsContent));
icsApp.save(edtCalendar.getId(), SendInvitationsMode.SendToNone);
But I don't understand how I can schedule a refresh startegy.
Do Exchange server support a this feature ?
Regards,
Arnaud

The ics you are referencing contains multiple events, but the EWS method you are using creates only a single event (the first).
If you want to import all events, you have to parse them (there are libraries for most languages) or split the vevents and create multiple appointments.
There is no option to refresh the ics file as the Exchange does not support it directly, you would have to implement that yourself.

Related

Best SERVERLESS way to feed data from multiple Chrome extensions to a single Google Spreadsheet

I have a Chrome browser plugin which performs like a social media posts bookmarks collector (a click on a post captures it's author username, text, date, permalink and the plugin user who owns it). I'm looking for the most efficient, safest and SERVERLESS way to have [potentially] thousands of plugin end-users update, for each individual click on a post, a line in a Google spreadsheet.
With my limited knowledge I narrowed the options to webhooks:
Create a Google Apps simple webhook app that will listen to plugin packets.
Have the end-user plugins send each social-media post click data in JSON to the webhook.
Have the webhook Google App publish an RSS feed with all the data collected
Have the Google Spreadsheet regularly check for new RSS entries and update a new line for each.
What i'm not sure of is 1) whether a simple webhook can be created using Google Apps? 2) can this method be secure enough to prevent non-plugin entries to the RSS feed? and 3) is there a simpler more efficient way of achieving this end?
Your help will be much appreciated :-)
Thanks.
You can easily create Webhooks in Google Apps Script through the use of Webapps. As an example:
function doPost(e) {
if (e.postData && e.postData.type == 'application/json') {
var data = JSON.parse(e.postData.contents);
var author = data['author'];
var text = data['text'];
var date = data['date'];
var permalink = data['permalink'];
var user = data['user'];
// (...)
}
This example code will parse the data received through a JSON post request. Afterwards, you can insert it to your Spreadsheet and generate an RSS feed using XmlService (for more information on how to do it see this blog post). The RSS feed can be served using the doGet() method.

google apps from app engine

I want to produce a Google Apps document based on a (Google doc) template stored on the users Google Drive and some XML data held by a servlet running on Google App Engine.
Preferably I want to run as much as possible on the GAE. Is it possible to run Apps Service APIs on GAE or download/manipulate Google doc on GAE? I have not been able to find anything suitable
One alternative is obviously to implement the merge functionality using an Apps Script transferring the XML as parameters and initiate the script through http from GAE, but it just seem somewhat awkward in comparison.
EDIT:
Specifically I am looking for the replaceText script functionality, as shown in the Apps script snippet below, to be implemented in GAE. Remaining code is supported through Drive/Mail API, I guess..
// Get document template, copy it as a new temp doc, and save the Doc’s id
var copyId = DocsList.getFileById(providedTemplateId)
.makeCopy('My-title')
.getId();
var copyDoc = DocumentApp.openById(copyId);
var copyBody = copyDoc.getActiveSection();
// Replace place holder keys,
copyBody.replaceText("CustomerAddressee", fullName);
var todaysDate = Utilities.formatDate(new Date(), "GMT+2", "dd/MM-yyyy");
copyBody.replaceText("DateToday", todaysDate);
// Save and close the temporary document
copyDoc.saveAndClose();
// Convert temporary document to PDF by using the getAs blob conversion
var pdf = DocsList.getFileById(copyId).getAs("application/pdf");
// Attach PDF and send the email
MailApp.sendEmail({
to: email_address,
subject: "Proposal",
htmlBody: "Hi,<br><br>Here is my file :)<br>Enjoy!<br><br>Regards Tony",
attachments: pdf});
As you already found out, apps script is currently the only one that can access an api to modify google docs. All other ways cannot do it unless you export to another format (like pdf or .doc) then use libraries that can modify those, then reupload the new file asking to convert to a google doc native format, which in some cases would loose some format/comments/named ranges and other google doc features. So like you said, if you must use the google docs api you must call apps script (as a content service). Also note that the sample apps script code you show is old and uses the deptecated docsList so you need to port it to the Drive api.
Apps script pretty much piggy backs on top of the standard published Google APIs. Increasingly the behaviours are becoming more familiar.
Obviously apps script is js based and gae not. All the APIs apart from those related to script running are available in the standard gae client runtimes.
No code to check here so I'm afraid generic answer is all I have.
I see now it can be solved by using the Google Drive API to export (download) the Google Apps Doc file as PDF (or other formats) to GAE, and do simple replace-text editing using e.g. the iText library

How to use Bedework server as a service for another system

For my application I need to use an open source calendar server. After some research I selected Bedework Server for my task. Basically what I want is to use this server to handle my application's calendar events. Even though I have setup a local server using quick start package, I kinda still confused on how I can use this. I can create events using it's web UI. But I want to use this as a service from my server (Something like a REST service). I read their documentation but I could not find anything that will help. I am really grateful if you can help me on this. Thanks in advance.
You can access the server using the CalDAV protocol. This is a standard REST protocol which specifies how you create/query/delete events and todos. It is the same protocol the Calendar or Reminders apps on OS X and iOS use to talk to the server.
The CalConnect CalDAV website is a good entry point to learn more about this.
If you are still looking this, you can try using any CalDAV Client Libraries -
CalDAV-libraries
I tried CalDAV4j library. For all basic use cases, it works fine.
There is also a demo github project on this library developed to list down the events in the server -
list-events-caldav4j-example
You can make use of the ListCalendarTest.java in the project and give appropriate endpoints to the Host configuration. For Example (for Bedework) -
HttpClient httpClient = new HttpClient();
// I tried it with zimbra - but I had no luck using google calendar
httpClient.getHostConfiguration().setHost("localhost", 8080, "http");
String username = "vbede";
UsernamePasswordCredentials httpCredentials = new UsernamePasswordCredentials(username, "bedework");
...
...
CalDAVCollection collection = new CalDAVCollection("/ucaldav/user/" + username + "/calendar",
(HostConfiguration) httpClient.getHostConfiguration().clone(), new CalDAV4JMethodFactory(),
CalDAVConstants.PROC_ID_DEFAULT);
...
...
GenerateQuery gq = new GenerateQuery();
// TODO you might want to adjust the date
gq.setFilter("VEVENT [20131001T000000Z;20131010T000000Z] : STATUS!=CANCELLED");
CalendarQuery calendarQuery = gq.generate();

How to use generated clientid with Google cloud endpoints for authenticating 3rd party users without redeploying app

In my case we work with other companies which would consume our APIs along with our internal javascript client. I think we need to create a web client id for javascript client. But when exposing APIs externally, is it correct to generate new web client id per company? If so do we have to update clientid each time and redeploy application?
I'm following this documentation and in their example client ids are hardcoded, if I need to give access to new 3rd party users, then I need to generate new client id for them but I'd expect to not redeploy application.
Update: I've created a feature request as per #Alex's suggestion below.
Unfortunately the docs at https://cloud.google.com/appengine/docs/python/endpoints/auth very specifically say, and I quote,
Because the allowed_client_ids must be specified at build time, you
must rebuild and redeploy your API backend after adding or changing
any client IDs in the authorized list of allowed_client_ids or
audiences
so it appears that your perfectly-reasonable use case is very explicitly not covered at this time.
I recommend you visit said page and enter a feature request via the "Write Feedback" link (around the upper right corner of the page) as well as entering a feature request on the Endpoints component of the App Engine feature tracker, https://code.google.com/p/googleappengine/issues/list?can=2&q=component=Endpoints&colspec=ID%20Type%20Component%20Status%20Stars%20Summary%20Language%20Priority%20Owner%20Log -- we monitor both, but with different processes, so trying both is best.
Sorry to be a bearer of bad news. For now, it seems the only workaround is to distribute to the other companies one of a bunch of client ids generated in advance (you can only change the valid bunch when you re-deploy, sigh) and perhaps add some extra, app-layer authorization check of your own -- exactly the kind of work endpoints should be doing on your behalf:-(.
You can use an asterisk as the client ID, that will allow any client to call it without redeploying your API backend. Not sure if this is a documented feature or not, but it works (at least) with both Python and Java.
#Api(name = "myapi",
version = "v1",
scopes = {"https://www.googleapis.com/auth/userinfo.email"},
description = "My flashy API",
clientIds = {"*"})
public class MyAPI { ... }

OSB Java callout to core java class

I have a simple java call out to decode a base64 string. The java looks like this
import javax.xml.bind.DatatypeConverter;
public final class DecodeBase64 {
public static byte[] decode(String base64string) {
return DatatypeConverter.parseBase64Binary(base64string);
}
}
Then I was thinking that since DatatypeConverter.parseBase64Binary is static why not call it directly. This way I can avoid having to deploy my jar.
I cannot however seem to find a way to call a core java class from the OSB java callout.
Is this possible? Is it even feasible?
I don't believe it would be possible to make that, as you can see from the documentation on Java Callouts, you first need to specify the .jar that you will use to make the callout. There's likely a ton of existing libraries, etc., in the classpath in OSB that Oracle et al wouldn't want to blindly expose, but I think you should be able to import and use in a .jar pretty easily.
Section 21.20 - Adding Java Callouts - http://docs.oracle.com/cd/E14571_01/doc.1111/e15867/proxy_actions.htm#i1321171
if you are looking to do Base64 conversion for setting Basic authorization while calling an external system or validating the input authorization header, then OSB has an inbuilt feature called "Service Accounts" which when combined with Business services / proxy services can convert your username / password into a Base64 format.
if you are looking to convert data into Base64 format for some other reason, then i am afraid, you cannot do so in OSB without making a java callout.
This is not possible . You have to import the jar

Resources