/// <summary> /// Real-Time Scheduling example. /// </summary> private static void RealTimeSchedulingExample() { Console.Write("Enter Client id: "); var clientId = Console.ReadLine(); Console.Write("Enter Secret: "); var clientSecret = Console.ReadLine(); Console.Write("Enter Account id for availablity: "); var sub = Console.ReadLine(); Console.Write("Enter calendar id for availablity: "); var calendarId = Console.ReadLine(); string redirectUrl = "http://example.com/redirectUri"; string scope = "read_events create_event"; string eventId = "testEventId"; string summary = "Test Summary"; DateTimeOffset start = DateTime.Now; DateTimeOffset end = DateTime.Now + new TimeSpan(2, 0, 0); var client = new CronofyOAuthClient(clientId, clientSecret); var upsertEventRequest = new UpsertEventRequestBuilder() .EventId(eventId) .Summary(summary) .Build(); var availabilityRequest = new AvailabilityRequestBuilder() .AddParticipantGroup(new ParticipantGroupBuilder().AddMember(sub).AllRequired()) .AddAvailablePeriod(start, end) .RequiredDuration(60) .Build(); var request = new RealTimeSchedulingRequestBuilder() .OAuthDetails(redirectUrl, scope) .Timezone("Etc/UTC") .UpsertEventRequest(upsertEventRequest) .AvailabilityRequest(availabilityRequest) .AddTargetCalendar(sub, calendarId) .Build(); var actualUrl = client.RealTimeScheduling(request); Console.WriteLine(actualUrl); Process.Start(actualUrl); }
public void CanUpsertEventWithPrivateFlag(bool eventPrivate) { const string eventId = "qTtZdczOccgaPncGJaCiLg"; const string summary = "Board meeting"; const string description = "Discuss plans for the next quarter"; const string startTimeString = "2014-08-05 15:30:00Z"; const string endTimeString = "2014-08-05 17:00:00Z"; const string locationDescription = "Board room"; const string transparency = Transparency.Opaque; Http.Stub( HttpPost .Url("https://api.cronofy.com/v1/calendars/" + CalendarId + "/events") .RequestHeader("Authorization", "Bearer " + AccessToken) .RequestHeader("Content-Type", "application/json; charset=utf-8") .RequestBodyFormat( "{{\"event_id\":\"{0}\"," + "\"event_private\":{7}," + "\"summary\":\"{1}\"," + "\"description\":\"{2}\"," + "\"start\":{{\"time\":\"{3}\",\"tzid\":\"Etc/UTC\"}}," + "\"end\":{{\"time\":\"{4}\",\"tzid\":\"Etc/UTC\"}}," + "\"location\":{{\"description\":\"{5}\"}}," + "\"transparency\":\"{6}\"" + "}}", eventId, summary, description, startTimeString, endTimeString, locationDescription, transparency, eventPrivate.ToString().ToLower()) .ResponseCode(202) ); var builder = new UpsertEventRequestBuilder() .EventId(eventId) .Summary(summary) .Description(description) .Start(new DateTime(2014, 8, 5, 15, 30, 0, DateTimeKind.Utc)) .End(new DateTime(2014, 8, 5, 17, 0, 0, DateTimeKind.Utc)) .Location(locationDescription) .Transparency(transparency) .EventPrivate(eventPrivate); Client.UpsertEvent(CalendarId, builder); }
public static void UpsertEvent(string eventId, string calendarId, string summary, string description, DateTime start, DateTime end, Cronofy.Location location = null) { var buildingEvent = new UpsertEventRequestBuilder() .EventId(eventId) .Summary(summary) .Description(description) .Start(start) .End(end); if (location != null) { buildingEvent.Location(location.Description, String.IsNullOrEmpty(location.Latitude) ? null : location.Latitude, String.IsNullOrEmpty(location.Longitude) ? null : location.Longitude); } var builtEvent = buildingEvent.Build(); try { CronofyAccountRequest(() => { AccountClient.UpsertEvent(calendarId, builtEvent); }); var successLog = "UpsertEvent success - eventId=`{eventId}` - calendarId=`{calendarId}` - summary=`{summary}` - description=`{description}` - start=`{start}` - end=`{end}`"; if (location != null && !(String.IsNullOrEmpty(location.Latitude) || String.IsNullOrEmpty(location.Longitude))) { successLog += String.Format(" - location.lat=`{0}` - location.long=`{1}`", location.Latitude, location.Longitude); } LogHelper.Log(successLog); } catch (CronofyException) { var failureLog = "UpsertEvent failure - eventId=`{eventId}` - calendarId=`{calendarId}` - summary=`{summary}` - description=`{description}` - start=`{start}` - end=`{end}`"; if (location != null && !(String.IsNullOrEmpty(location.Latitude) || String.IsNullOrEmpty(location.Longitude))) { failureLog += String.Format(" - location.lat=`{0}` - location.long=`{1}`", location.Latitude, location.Longitude); } LogHelper.Log(failureLog); throw; } }
public void CanUpsertRemindersWithCreateOnly() { const string eventId = "qTtZdczOccgaPncGJaCiLg"; const string summary = "Board meeting"; const string description = "Discuss plans for the next quarter"; const string startTimeString = "2014-08-05"; const string endTimeString = "2014-08-06"; var reminders = new[] { 10, 0, 30 }; Http.Stub( HttpPost .Url("https://api.cronofy.com/v1/calendars/" + CalendarId + "/events") .RequestHeader("Authorization", "Bearer " + AccessToken) .RequestHeader("Content-Type", "application/json; charset=utf-8") .RequestBodyFormat( "{{\"event_id\":\"{0}\"," + "\"reminders_create_only\":true," + "\"summary\":\"{1}\"," + "\"description\":\"{2}\"," + "\"start\":{{\"time\":\"{3}\",\"tzid\":\"Etc/UTC\"}}," + "\"end\":{{\"time\":\"{4}\",\"tzid\":\"Etc/UTC\"}}," + "\"reminders\":[{{\"minutes\":10}},{{\"minutes\":0}},{{\"minutes\":30}}]" + "}}", eventId, summary, description, startTimeString, endTimeString) .ResponseCode(202) ); var builder = new UpsertEventRequestBuilder() .EventId(eventId) .Summary(summary) .Description(description) .Start(new Date(2014, 8, 5)) .End(new Date(2014, 8, 6)) .Reminders(reminders) .RemindersCreateOnly(true); Client.UpsertEvent(CalendarId, builder); }
public void CanUpsertEventWithSeparateTimeZoneIds() { const string eventId = "qTtZdczOccgaPncGJaCiLg"; const string summary = "Board meeting"; const string description = "Discuss plans for the next quarter"; const string startTimeString = "2014-08-05 15:30:00Z"; const string endTimeString = "2014-08-05 17:00:00Z"; const string startTimeZoneId = "Europe/London"; const string endTimeZoneId = "America/Chicago"; Http.Stub( HttpPost .Url("https://api.cronofy.com/v1/calendars/" + CalendarId + "/events") .RequestHeader("Authorization", "Bearer " + AccessToken) .RequestHeader("Content-Type", "application/json; charset=utf-8") .RequestBodyFormat( "{{\"event_id\":\"{0}\"," + "\"summary\":\"{1}\"," + "\"description\":\"{2}\"," + "\"start\":{{\"time\":\"{3}\",\"tzid\":\"{4}\"}}," + "\"end\":{{\"time\":\"{5}\",\"tzid\":\"{6}\"}}" + "}}", eventId, summary, description, startTimeString, startTimeZoneId, endTimeString, endTimeZoneId) .ResponseCode(202) ); var builder = new UpsertEventRequestBuilder() .EventId(eventId) .Summary(summary) .Description(description) .Start(new DateTime(2014, 8, 5, 15, 30, 0, DateTimeKind.Utc)) .StartTimeZoneId(startTimeZoneId) .End(new DateTime(2014, 8, 5, 17, 0, 0, DateTimeKind.Utc)) .EndTimeZoneId(endTimeZoneId); Client.UpsertEvent(CalendarId, builder); }
public void CanUpsertColor() { const string eventId = "qTtZdczOccgaPncGJaCiLg"; const string summary = "Board meeting"; const string description = "Discuss plans for the next quarter"; const string startTimeString = "2014-08-05"; const string endTimeString = "2014-08-06"; const string color = "#49BED8"; Http.Stub( HttpPost .Url("https://api.cronofy.com/v1/calendars/" + CalendarId + "/events") .RequestHeader("Authorization", "Bearer " + AccessToken) .RequestHeader("Content-Type", "application/json; charset=utf-8") .RequestBodyFormat( "{{\"event_id\":\"{0}\"," + "\"summary\":\"{1}\"," + "\"description\":\"{2}\"," + "\"start\":{{\"time\":\"{3}\",\"tzid\":\"Etc/UTC\"}}," + "\"end\":{{\"time\":\"{4}\",\"tzid\":\"Etc/UTC\"}}," + "\"color\":\"{5}\"" + "}}", eventId, summary, description, startTimeString, endTimeString, color) .ResponseCode(202) ); var builder = new UpsertEventRequestBuilder() .EventId(eventId) .Summary(summary) .Description(description) .Start(new Date(2014, 8, 5)) .End(new Date(2014, 8, 6)) .Color(color); Client.UpsertEvent(CalendarId, builder); }
public void CanUpsertExternalEvent() { const string eventUid = "external_event_id"; const string summary = "Board meeting"; const string description = "Discuss plans for the next quarter"; const string startTimeString = "2014-08-05 15:30:00Z"; const string endTimeString = "2014-08-05 17:00:00Z"; const string locationDescription = "Board room"; Http.Stub( HttpPost .Url("https://api.cronofy.com/v1/calendars/" + calendarId + "/events") .RequestHeader("Authorization", "Bearer " + AccessToken) .RequestHeader("Content-Type", "application/json; charset=utf-8") .RequestBodyFormat( "{{\"event_uid\":\"{0}\"," + "\"summary\":\"{1}\"," + "\"description\":\"{2}\"," + "\"start\":{{\"time\":\"{3}\",\"tzid\":\"Etc/UTC\"}}," + "\"end\":{{\"time\":\"{4}\",\"tzid\":\"Etc/UTC\"}}," + "\"location\":{{\"description\":\"{5}\"}}" + "}}", eventUid, summary, description, startTimeString, endTimeString, locationDescription) .ResponseCode(202) ); var builder = new UpsertEventRequestBuilder() .EventUid(eventUid) .Summary(summary) .Description(description) .Start(new DateTime(2014, 8, 5, 15, 30, 0, DateTimeKind.Utc)) .End(new DateTime(2014, 8, 5, 17, 0, 0, DateTimeKind.Utc)) .Location(locationDescription); Client.UpsertEvent(calendarId, builder); }
public void CantUpsertWithInvalidTransparency() { const string eventId = "qTtZdczOccgaPncGJaCiLg"; const string summary = "Board meeting"; const string startTimeString = "2014-08-05 15:30:00Z"; const string endTimeString = "2014-08-05 17:00:00Z"; const string transparency = Transparency.Unknown; Http.Stub( HttpPost .Url("https://api.cronofy.com/v1/calendars/" + CalendarId + "/events") .RequestHeader("Authorization", "Bearer " + AccessToken) .RequestHeader("Content-Type", "application/json; charset=utf-8") .RequestBodyFormat( "{{\"event_id\":\"{0}\"," + "\"summary\":\"{1}\"," + "\"start\":{{\"time\":\"{2}\",\"tzid\":\"Etc/UTC\"}}," + "\"end\":{{\"time\":\"{3}\",\"tzid\":\"Etc/UTC\"}}," + "\"transparency\":\"{4}\"" + "}}", eventId, summary, startTimeString, endTimeString, transparency) .ResponseCode(202) ); Assert.Throws <ArgumentException>(() => { var builder = new UpsertEventRequestBuilder() .EventId(eventId) .Summary(summary) .Start(new DateTime(2014, 8, 5, 15, 30, 0, DateTimeKind.Utc)) .End(new DateTime(2014, 8, 5, 17, 0, 0, DateTimeKind.Utc)) .Transparency(transparency); Client.UpsertEvent(CalendarId, builder); }); }
public void CanUpsertAllDayEvent() { const string eventId = "qTtZdczOccgaPncGJaCiLg"; const string summary = "Board meeting"; const string description = "Discuss plans for the next quarter"; const string startTimeString = "2014-08-05"; const string endTimeString = "2014-08-06"; Http.Stub( HttpPost .Url("https://api.cronofy.com/v1/calendars/" + calendarId + "/events") .RequestHeader("Authorization", "Bearer " + AccessToken) .RequestHeader("Content-Type", "application/json; charset=utf-8") .RequestBodyFormat( "{{\"event_id\":\"{0}\"," + "\"summary\":\"{1}\"," + "\"description\":\"{2}\"," + "\"start\":{{\"time\":\"{3}\",\"tzid\":\"Etc/UTC\"}}," + "\"end\":{{\"time\":\"{4}\",\"tzid\":\"Etc/UTC\"}}" + "}}", eventId, summary, description, startTimeString, endTimeString) .ResponseCode(202) ); var builder = new UpsertEventRequestBuilder() .EventId(eventId) .Summary(summary) .Description(description) .Start(new Date(2014, 8, 5)) .End(new Date(2014, 8, 6)); Client.UpsertEvent(calendarId, builder); }
/// <summary> /// Add To Calendar example. /// </summary> private static void AddToCalendarExample() { Console.Write("Enter Client id: "); var clientId = Console.ReadLine(); Console.Write("Enter Secret: "); var clientSecret = Console.ReadLine(); string redirectUrl = "http://example.com/redirectUri"; string scope = "read_events create_event"; string eventId = "testEventId"; string summary = "Test Summary"; DateTimeOffset start = DateTime.Now; DateTimeOffset end = DateTime.Now + new TimeSpan(2, 0, 0); var client = new CronofyOAuthClient(clientId, clientSecret); var upsertEventRequest = new UpsertEventRequestBuilder() .EventId(eventId) .Summary(summary) .Start(start) .End(end) .Build(); var request = new AddToCalendarRequestBuilder() .OAuthDetails(redirectUrl, scope) .UpsertEventRequest(upsertEventRequest) .Build(); var actualUrl = client.AddToCalendar(request); Console.WriteLine(actualUrl); Process.Start(actualUrl); }
public void CanGetOAuthUrlWithAvailabilityTargetCalendarsAndHourFormat() { var start = new DateTime(2014, 8, 5, 15, 30, 0, DateTimeKind.Utc); var end = new DateTime(2014, 8, 5, 16, 30, 0, DateTimeKind.Utc); var client = new CronofyOAuthClient(clientId, clientSecret); var http = new StubHttpClient(); client.HttpClient = http; var upsertEventRequestWithoutStartAndEnd = new UpsertEventRequestBuilder() .EventId("testEventId") .Summary("Test Summary") .Build(); var sequenceBuilder = new SequenceRequestBuilder() .RequiredDuration(60) .Ordinal(1) .SequenceId("First Event") .Event(upsertEventRequestWithoutStartAndEnd) .AddRequiredParticipant("acc_567236000909002") .AddRequiredParticipant("acc_678347111010113"); var availabilityRequest = new SequencedAvailabilityRequestBuilder() .AddSequence(sequenceBuilder) .AddAvailablePeriod(start, end) .Build(); var expectedUrl = "http://test.com"; http.Stub( HttpPost .Url("https://api.cronofy.com/v1/real_time_sequencing") .JsonRequest(@" { ""availablity"":{ ""sequence"":[ { ""ordinal"":1, ""sequence_id"":""First Event"", ""event"":{ ""event_id"":""testEventId"", ""summary"":""Test Summary"" }, ""participants"":[ { ""members"":[ { ""sub"":""acc_567236000909002"" }, { ""sub"":""acc_678347111010113"" } ], ""required"":""all"" } ], ""required_duration"":{ ""minutes"":60 }, ""available_periods"":[ ] } ], ""available_periods"":[ { ""start"":""2014-08-05 15:30:00Z"", ""end"":""2014-08-05 16:30:00Z"" } ] }, ""client_id"":""abcdef123456"", ""client_secret"":""s3cr3t1v3"", ""oauth"":{ ""redirect_uri"":""http://example.com/redirectUri"", ""scope"":""test_scope"" }, ""event"":{ ""event_id"":""testEventId"", ""summary"":""Test Summary"" }, ""target_calendars"":[ { ""sub"":""sub"", ""calendar_id"":""calendarId"" } ], ""formatting"":{ ""hour_format"":""H"" }, ""tzid"":""Etc/UTC"" }") .ResponseCode(200) .ResponseBodyFormat("{{\"url\":\"{0}\"}}", expectedUrl) ); var request = new RealTimeSequencingRequestBuilder() .OAuthDetails("http://example.com/redirectUri", "test_scope") .Timezone("Etc/UTC") .UpsertEventRequest(upsertEventRequestWithoutStartAndEnd) .SequencedAvailabilityRequest(availabilityRequest) .AddTargetCalendar("sub", "calendarId") .HourFormat("H") .Build(); var actualUrl = client.RealTimeSequencing(request); Assert.AreEqual(expectedUrl, actualUrl); }
/// <summary> /// The entry point of the program, where the program control starts and /// ends. /// </summary> /// <param name="args"> /// The command-line arguments. /// </param> public static void Main(string[] args) { Console.Write("Enter access token: "); var accessToken = Console.ReadLine(); Console.WriteLine(); var client = new CronofyAccountClient(accessToken); Console.WriteLine("Fetching calendars..."); var calendars = client.GetCalendars(); Console.WriteLine(); foreach (var calendar in calendars) { Console.WriteLine("{0} - {1} - {2} ({3})", calendar.CalendarId, calendar.Name, calendar.Profile.Name, calendar.Profile.ProviderName); } Console.WriteLine(); Console.WriteLine("Fetching events..."); var events = client.GetEvents(); Console.WriteLine(); foreach (var evt in events) { Console.WriteLine("{0} - {1}", evt.Start, evt.Summary); } Console.WriteLine(); const string EventId = "CronofyExample"; Console.WriteLine("Creating event with ID {0}", EventId); Console.WriteLine(); Console.Write("Enter calendar ID: "); var calendarId = Console.ReadLine(); Console.WriteLine(); var eventBuilder = new UpsertEventRequestBuilder() .EventId(EventId) .Summary("Cronofy Example") .Description("Example from the Cronofy .NET SDK") .Start(2015, 10, 20, 17, 00) .End(2015, 10, 20, 17, 30); client.UpsertEvent(calendarId, eventBuilder); Console.WriteLine("Event upserted"); Console.WriteLine(); Console.WriteLine("Press enter to delete..."); Console.ReadLine(); client.DeleteEvent(calendarId, EventId); Console.WriteLine("Event deleted"); Console.WriteLine(); Console.WriteLine("Press enter to continue..."); Console.ReadLine(); }
public void CanUpsertEventWithSeparateTimeZoneIds() { const string eventId = "qTtZdczOccgaPncGJaCiLg"; const string summary = "Board meeting"; const string description = "Discuss plans for the next quarter"; const string startTimeString = "2014-08-05 15:30:00Z"; const string endTimeString = "2014-08-05 17:00:00Z"; const string startTimeZoneId = "Europe/London"; const string endTimeZoneId = "America/Chicago"; Http.Stub( HttpPost .Url("https://api.cronofy.com/v1/calendars/" + calendarId + "/events") .RequestHeader("Authorization", "Bearer " + AccessToken) .RequestHeader("Content-Type", "application/json; charset=utf-8") .RequestBodyFormat( "{{\"event_id\":\"{0}\"," + "\"summary\":\"{1}\"," + "\"description\":\"{2}\"," + "\"start\":{{\"time\":\"{3}\",\"tzid\":\"{4}\"}}," + "\"end\":{{\"time\":\"{5}\",\"tzid\":\"{6}\"}}" + "}}", eventId, summary, description, startTimeString, startTimeZoneId, endTimeString, endTimeZoneId) .ResponseCode(202) ); var builder = new UpsertEventRequestBuilder() .EventId(eventId) .Summary(summary) .Description(description) .Start(new DateTime(2014, 8, 5, 15, 30, 0, DateTimeKind.Utc)) .StartTimeZoneId(startTimeZoneId) .End(new DateTime(2014, 8, 5, 17, 0, 0, DateTimeKind.Utc)) .EndTimeZoneId(endTimeZoneId); Client.UpsertEvent(calendarId, builder); }
public void CanUpsertEvent() { this.Http.Stub( HttpPost .Url("https://api.cronofy.com/v1/batch") .RequestHeader("Authorization", "Bearer " + AccessToken) .JsonRequest(@" { ""batch"": [ { ""method"": ""POST"", ""relative_url"": ""/v1/calendars/cal_n23kjnwrw2_jsdfjksn234/events"", ""data"": { ""event_id"": ""qTtZdczOccgaPncGJaCiLg"", ""summary"": ""Board meeting"", ""description"": ""Discuss plans for the next quarter."", ""start"": { ""time"": ""2014-08-05 15:30:00Z"", ""tzid"": ""Etc/UTC"" }, ""end"": { ""time"": ""2014-08-05 17:00:00Z"", ""tzid"": ""Etc/UTC"" }, ""location"": { ""description"": ""Board room"" } } } ] } ") .ResponseCode(207) .ResponseBody(@" { ""batch"": [ { ""status"": 202 } ] } ") ); var batchBuilder = new BatchRequestBuilder(); var upsertRequest = new UpsertEventRequestBuilder() .EventId("qTtZdczOccgaPncGJaCiLg") .Summary("Board meeting") .Description("Discuss plans for the next quarter.") .Start(new DateTime(2014, 8, 5, 15, 30, 0, DateTimeKind.Utc)) .End(new DateTime(2014, 8, 5, 17, 0, 0, DateTimeKind.Utc)) .Location("Board room") .Build(); batchBuilder.UpsertEvent("cal_n23kjnwrw2_jsdfjksn234", upsertRequest); var response = this.Client.BatchRequest(batchBuilder); var expected = new BatchResponse.EntryResponse { Status = 202, Request = new BatchRequest.EntryBuilder() .Method("POST") .RelativeUrl("/v1/calendars/cal_n23kjnwrw2_jsdfjksn234/events") .Data(upsertRequest) .Build(), }; Assert.AreEqual(expected, response.Batch[0]); }