public FirestoreService() { uid = App.User.id; notificationManager = DependencyService.Get <INotificationManager>(); googleService = new GoogleService(); firebaseFunctionsService = new FirebaseFunctionsService(); }
public static async Task <bool> LoadTodaysEvents() { App.User.CalendarEvents.Clear(); //Call Google API var googleService = new GoogleService(); int publicYear = DateTime.Now.Year; int publicMonth = DateTime.Now.Month; int publicDay = DateTime.Now.Day; string timeZoneOffset = DateTimeOffset.Now.ToString(); string[] timeZoneOffsetParsed = timeZoneOffset.Split('-'); int timeZoneNum = Int32.Parse(timeZoneOffsetParsed[1].Substring(0, 2)); DateTime currentTimeinUTC = DateTime.Now.ToUniversalTime(); int uTCHour = (currentTimeinUTC.Hour - timeZoneNum); int currentLocalUTCMinute = currentTimeinUTC.Minute; var jsonResult = await googleService.GetAllTodaysEventsList(publicYear, publicMonth, publicDay, timeZoneNum); //var jsonResult = await googleService.GetEventsList(); //Console.WriteLine("jsonResult event: " + jsonResult); //Return error if result is empty if (jsonResult == null) { return(false); } //Parse the json using EventsList Method try { var parsedResult = JsonConvert.DeserializeObject <Methods.GetEventsListMethod>(jsonResult); //Separate out just the EventName foreach (EventsItems events in parsedResult.Items) { App.User.CalendarEvents.Add(events); Console.WriteLine(events.EventName.ToString()); } } catch (NullReferenceException e) { //LoginPage.accessToken = LoginPage.refreshToken; //await Navigation.PopAsync(); //Console.WriteLine(LoginPage.accessToken); return(false); } return(true); }
public async Task <string> GetAllTodaysEventsList(int publicYear, int publicMonth, int publicDay, int timeZoneNum) { //Make HTTP Request string baseUri = "https://www.googleapis.com/calendar/v3/calendars/primary/events?orderBy=startTime&singleEvents=true&"; string monthString; string dayString; string paddedTimeZoneNum; //---------- ADD ZERO PADDING AND UTC FIX if (timeZoneNum < 10) { paddedTimeZoneNum = timeZoneNum.ToString().PadLeft(2, '0'); } else { paddedTimeZoneNum = timeZoneNum.ToString(); } if (publicMonth < 10) { monthString = publicMonth.ToString().PadLeft(2, '0'); } else { monthString = publicMonth.ToString(); } if (publicDay < 10) { dayString = publicDay.ToString().PadLeft(2, '0'); } else { dayString = publicDay.ToString(); } string timeMaxMin = String.Format("timeMax={0}-{1}-{2}T23%3A59%3A59-{3}%3A00&timeMin={0}-{1}-{2}T00%3A00%3A01-{3}%3A00", publicYear, monthString, dayString, paddedTimeZoneNum); string fullURI = baseUri + timeMaxMin; //Console.WriteLine(fullURI); var request = new HttpRequestMessage(); request.RequestUri = new Uri(fullURI); request.Method = HttpMethod.Get; //Format Headers of Request with included Token string bearerString = string.Format("Bearer {0}", App.User.access_token); request.Headers.Add("Authorization", bearerString); request.Headers.Add("Accept", "application/json"); var client = new HttpClient(); HttpResponseMessage response = await client.SendAsync(request); HttpContent content = response.Content; var json = await content.ReadAsStringAsync(); //Console.WriteLine(json); JObject jsonParsed = JObject.Parse(json); if (jsonParsed.ContainsKey("error")) { var googleService = new GoogleService(); if (await RefreshToken()) { return(await googleService.GetAllTodaysEventsList(publicYear, publicMonth, publicDay, timeZoneNum)); } } return(json); }
public static async Task <List <List <string> > > GetPhotos() { //Make HTTP Request var request = new HttpRequestMessage(); request.RequestUri = new Uri("https://photoslibrary.googleapis.com/v1/mediaItems?pageSize=100"); request.Method = HttpMethod.Get; //Format Headers of Request with included Token string bearerString = string.Format("Bearer {0}", App.User.access_token); request.Headers.Add("Authorization", bearerString); request.Headers.Add("Accept", "application/json"); var client = new HttpClient(); HttpResponseMessage response = await client.SendAsync(request); HttpContent content = response.Content; var json = await content.ReadAsStringAsync(); //return json; //Deserialize JSON Result var result = JsonConvert.DeserializeObject <ProjectCaitlin.Methods.GetPhotoAlbumMethod>(json); //Create itemList var itemList = new List <List <string> >(); //var itemMap = new Dictionary<string, string>(); String creationTime = ""; String storePicUri = ""; String date = ""; String thumbNailAlbumUri = ""; String description = ""; String id = ""; //String note = ""; try { foreach (var product in result.MediaItems) { var subList = new List <string>(); DateTimeOffset GreenwichMeanTime = product.MediaMetadata.CreationTime; //Google photo api sends time in GreenwichMeanTime. DateTimeOffset utcTime = GreenwichMeanTime.ToLocalTime(); //convert GreenwichMeanTime to local time. //creationTime = utcTime.ToString(); creationTime = utcTime.ToString(); date = creationTime.Substring(0, creationTime.IndexOf(" "));// date = yyyy/mm/dd creationTime = utcTime.TimeOfDay.ToString(); id = product.Id; string fileName = product.Filename; storePicUri = product.BaseUrl.ToString(); description = product.Description + ""; App.User.allDates.Add(date); subList.Add(product.BaseUrl.ToString()); subList.Add(date); subList.Add(description); subList.Add(creationTime); subList.Add(id); bool post = true; foreach (photo photo in App.User.FirebasePhotos) { if (id.Equals(photo.id)) { post = false; } } // If there is a photo in Google but not in Firebase, post it. if (post) { //Post photo to Firebase await FirebaseFunctionsService.PostPhoto(id, description, " "); subList.Add(""); } else { //Get photo from Firebase and add note photo photo = await FirebaseFunctionsService.GetPhoto(id); subList.Add(photo.note); } App.User.photoURIs.Add(subList); itemList.Add(subList); } } catch (NullReferenceException e) { var googleService = new GoogleService(); if (await googleService.RefreshToken()) { Console.WriteLine("RefreshToken Done!"); App.User.photoURIs = await GooglePhotoService.GetPhotos(); } } if (itemList.Count == 0) { return(new List <List <string> >()); } else { return(itemList); } }