// // GoogleHelpers.cs // // Author: // Paul Schneider // // Copyright (c) 2015 GNU GPL // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . using System; using Yavsc.Model.Google; using System.Web.Profile; using System.Configuration; using System.Web; namespace Yavsc.Helpers.Google { /// /// Google helpers. /// public static class GoogleHelpers { /// /// Gets the events. /// /// The events. /// Profile. /// Mindate. /// Maxdate. public static CalendarEventList GetEvents(this ProfileBase profile, DateTime mindate, DateTime maxdate) { string gcalid = (string) profile.GetPropertyValue ("gcalid"); if (string.IsNullOrWhiteSpace (gcalid)) throw new ArgumentException ("NULL gcalid"); CalendarApi c = new CalendarApi (clientApiKey); string creds = OAuth2.GetFreshGoogleCredential (profile); return c.GetCalendar (gcalid, mindate, maxdate, creds); } /// /// Gets the calendars. /// /// The calendars. /// Profile. public static CalendarList GetCalendars (this ProfileBase profile) { string cred = OAuth2.GetFreshGoogleCredential (profile); CalendarApi c = new CalendarApi (clientApiKey); return c.GetCalendars (cred); } private static string clientId = ConfigurationManager.AppSettings ["GOOGLE_CLIENT_ID"]; private static string clientSecret = ConfigurationManager.AppSettings ["GOOGLE_CLIENT_SECRET"]; private static string clientApiKey = ConfigurationManager.AppSettings ["GOOGLE_API_KEY"]; /// /// Login the specified response, state and callBack. /// /// Response. /// State. /// Call back. public static void Login(this HttpResponseBase response, string state, string callBack) { OAuth2 oa = new OAuth2 (callBack, clientId,clientSecret); oa.Login (response, state); } /// /// Cals the login. /// /// Response. /// State. /// Call back. public static void CalLogin(this HttpResponseBase response, string state, string callBack) { OAuth2 oa = new OAuth2 (callBack,clientId,clientSecret); oa.GetCalendarScope (response, state); } /// /// Creates the O auth2. /// /// The O auth2. /// Call back. public static OAuth2 CreateOAuth2(string callBack) { return new OAuth2 (callBack,clientId,clientSecret); } } }