/// <summary> /// Sets the time zone identifier for the start and end times of the /// event. /// </summary> /// <param name="timeZoneId"> /// Time zone identifier, must not be empty. /// </param> /// <returns> /// A reference to the modified builder. /// </returns> /// <exception cref="ArgumentException"> /// Thrown if <paramref name="timeZoneId"/> is empty. /// </exception> public UpsertEventRequestBuilder TimeZoneId(string timeZoneId) { Preconditions.NotEmpty("timeZoneId", timeZoneId); this.startTimeZoneId = timeZoneId; this.endTimeZoneId = timeZoneId; this.timeZoneId = timeZoneId; return(this); }
/// <summary> /// Add an event upsert to the batch. /// </summary> /// <param name="calendarId"> /// The ID of the calendar the event should be upserted to, must not be /// empty. /// </param> /// <param name="eventBuilder"> /// The builder from which to create a <see cref="UpsertEventRequest"/> /// entry, must not be null. /// </param> /// <exception cref="ArgumentException"> /// Thrown if <paramref name="calendarId"/> is empty or if /// <paramref name="eventBuilder"/> is null. /// </exception> /// <returns> /// A reference to the modified builder. /// </returns> public BatchRequestBuilder UpsertEvent(string calendarId, IBuilder <UpsertEventRequest> eventBuilder) { Preconditions.NotEmpty("calendarId", calendarId); Preconditions.NotNull("eventBuilder", eventBuilder); return(this.WithEntry( new BatchRequest.EntryBuilder() .Method("POST") .RelativeUrlFormat("/v1/calendars/{0}/events", calendarId) .Data(eventBuilder))); }
/// <summary> /// Removes the attendee from the event. /// </summary> /// <returns> /// A reference to the modified builder. /// </returns> /// <param name="email">The email of the attendee.</param> /// <param name="displayName">The display name of the attendee.</param> /// <exception cref="ArgumentException"> /// Thrown if <paramref name="email"/> is empty. /// </exception> public UpsertEventRequestBuilder RemoveAttendee(string email, string displayName = null) { Preconditions.NotEmpty("email", email); this.removedAttendees.Add(new UpsertEventRequest.RequestAttendee { Email = email, DisplayName = displayName }); return(this); }
/// <inheritdoc/> public void RevokeProfileAuthorization(string profileId) { Preconditions.NotEmpty("profileId", profileId); var request = new HttpRequest(); request.Method = "POST"; request.Url = string.Format(this.UrlProvider.RevokeProfileAuthorizationUrlFormat, profileId); request.AddOAuthAuthorization(this.AccessToken); this.HttpClient.GetValidResponse(request); }
/// <summary> /// Initializes a new instance of the <see cref="Cronofy.OAuthToken"/> /// class. /// </summary> /// <param name="accessToken"> /// The access token for the OAuth authorization, must not be empty. /// </param> /// <param name="refreshToken"> /// The refresh token for the OAuth authorization, must not be empty. /// </param> /// <param name="expiresIn"> /// The number of seconds until the <paramref name="accessToken"/> /// expires, must not be negative. /// </param> /// <param name="scope"> /// The scope of the OAuth authorization, must not be null. /// </param> public OAuthToken(string accessToken, string refreshToken, int expiresIn, string[] scope) { Preconditions.NotEmpty("accessToken", accessToken); Preconditions.NotEmpty("refreshToken", refreshToken); Preconditions.NotNegative("expiresIn", expiresIn); Preconditions.NotNull("scope", scope); this.AccessToken = accessToken; this.RefreshToken = refreshToken; this.ExpiresIn = expiresIn; this.Scope = scope; }
/// <summary> /// Initializes a new instance of the /// <see cref="Cronofy.CronofyAccountClient.PagedResultsIterator{TResponse,TResult}"/> /// class. /// </summary> /// <param name="httpClient"> /// The HTTP client to use for requests, must not be null. /// </param> /// <param name="accessToken"> /// The access token for the OAuth authorization for the account, /// must not be empty. /// </param> /// <param name="firstRequest"> /// The request for the first page of results, must not be null. /// </param> /// <exception cref="System.ArgumentException"> /// Thrown if <paramref name="httpClient"/> or /// <paramref name="firstRequest"/> are null, of if /// <paramref name="accessToken"/> is empty. /// </exception> public PagedResultsIterator(IHttpClient httpClient, string accessToken, HttpRequest firstRequest) { Preconditions.NotNull("httpClient", httpClient); Preconditions.NotEmpty("accessToken", accessToken); Preconditions.NotNull("firstRequest", firstRequest); this.httpClient = httpClient; this.accessToken = accessToken; // Eagerly fetch the first page to hit access token and validation issues. this.firstPage = this.httpClient.GetJsonResponse <TResponse>(firstRequest); }
/// <inheritdoc/> public void CloseChannel(string channelId) { Preconditions.NotEmpty("channelId", channelId); var request = new HttpRequest(); request.Method = "DELETE"; request.Url = string.Format(this.UrlProvider.ChannelUrlFormat, channelId); request.AddOAuthAuthorization(this.AccessToken); this.HttpClient.GetValidResponse(request); }
/// <inheritdoc/> public bool HmacMatches(string sha256Hmac, byte[] requestBytes) { Preconditions.NotEmpty("sha256Hmac", sha256Hmac); var keyBytes = Encoding.UTF8.GetBytes(this.clientSecret); using (var hmacsha256 = new HMACSHA256(keyBytes)) { var requestHash = hmacsha256.ComputeHash(requestBytes); return(sha256Hmac == Convert.ToBase64String(requestHash)); } }
/// <summary> /// Initializes a new instance of the /// <see cref="AuthorizationUrlBuilder"/> class. /// </summary> /// <param name="clientId"> /// The application's OAuth client_id, must not be blank. /// </param> /// <param name="urlProvider"> /// The URL provider for the current context, must not be /// <code>null</code>. /// </param> /// <param name="redirectUri"> /// The URI to redirect the user's response for the authorization /// request to, must not be empty. /// </param> /// <exception cref="System.ArgumentException"> /// Thrown if <paramref name="clientId"/> is blank, /// <paramref name="urlProvider"/> is <code>null</code>, or if /// <paramref name="redirectUri"/> is empty. /// </exception> internal AuthorizationUrlBuilder(string clientId, UrlProvider urlProvider, string redirectUri) { Preconditions.NotBlank("clientId", clientId); Preconditions.NotNull("urlProvider", urlProvider); Preconditions.NotEmpty("redirectUri", redirectUri); this.clientId = clientId; this.urlProvider = urlProvider; this.redirectUri = redirectUri; this.scope = DefaultScopes; this.enterpriseConnectScope = DefaultEnterpriseConnectScopes; }
/// <summary> /// Adds an event delete to the batch. /// </summary> /// <param name="calendarId"> /// The ID of the calendar the event should be deleted from, must not be /// empty. /// </param> /// <param name="eventId"> /// The ID of the event to delete, must not be empty. /// </param> /// <exception cref="ArgumentException"> /// Thrown if <paramref name="calendarId"/> is empty or if /// <paramref name="eventId"/> is null. /// </exception> /// <returns> /// A reference to the modified builder. /// </returns> public BatchRequestBuilder DeleteEvent(string calendarId, string eventId) { Preconditions.NotEmpty("calendarId", calendarId); Preconditions.NotEmpty("eventId", eventId); return(this.WithEntry( new BatchRequest.EntryBuilder() .Method("DELETE") .RelativeUrlFormat("/v1/calendars/{0}/events", calendarId) .Data(new DeleteEventRequest { EventId = eventId }))); }
/// <inheritdoc/> public Calendar CreateCalendar(string profileId, string name) { Preconditions.NotEmpty("profileId", profileId); Preconditions.NotEmpty("name", name); var calendarRequest = new CreateCalendarRequest { ProfileId = profileId, Name = name, }; return(this.CreateCalendar(calendarRequest)); }
/// <inheritdoc/> public void UpsertEvent(string calendarId, UpsertEventRequest eventRequest) { Preconditions.NotEmpty("calendarId", calendarId); Preconditions.NotNull("eventRequest", eventRequest); var request = new HttpRequest(); request.Method = "POST"; request.Url = string.Format(this.UrlProvider.ManagedEventUrlFormat, calendarId); request.AddOAuthAuthorization(this.AccessToken); request.SetJsonBody(eventRequest); this.HttpClient.GetValidResponse(request); }
/// <summary> /// Adds a querystring parameter to the URL. /// </summary> /// <param name="key"> /// The key of the querystring parameter, must not be null or empty. /// </param> /// <param name="value"> /// The value of the querystring parameter, must not be null. /// </param> /// <returns> /// A reference to the builder. /// </returns> /// <exception cref="ArgumentException"> /// Thrown if <paramref name="key"/> is null or empty, or if /// <paramref name="value"/> is null. /// </exception> public UrlBuilder AddParameter(string key, string value) { Preconditions.NotEmpty("key", key); Preconditions.NotNull("value", value); var encodedKey = EncodeParameter(key); var encodedValue = EncodeParameter(value); var parameter = string.Format("{0}={1}", encodedKey, encodedValue); this.parameters.Add(parameter); return(this); }
/// <inheritdoc/> public void CloseChannel(string channelId) { Preconditions.NotEmpty("channelId", channelId); var request = new HttpRequest(); request.Method = "DELETE"; request.Url = string.Format(ChannelUrlFormat, channelId); request.AddOAuthAuthorization(this.accessToken); var response = this.HttpClient.GetResponse(request); if (response.Code != 202) { // TODO More useful exceptions for validation errors throw new CronofyException("Request failed"); } }
/// <inheritdoc/> public void DeleteEvent(string calendarId, string eventId) { Preconditions.NotEmpty("calendarId", calendarId); Preconditions.NotEmpty("eventId", eventId); var request = new HttpRequest(); request.Method = "DELETE"; request.Url = string.Format(this.UrlProvider.ManagedEventUrlFormat, calendarId); request.AddOAuthAuthorization(this.AccessToken); var requestBody = new DeleteEventRequest { EventId = eventId }; request.SetJsonBody(requestBody); this.HttpClient.GetValidResponse(request); }
/// <inheritdoc/> public void UpsertEvent(string calendarId, UpsertEventRequest eventRequest) { Preconditions.NotEmpty("calendarId", calendarId); Preconditions.NotNull("eventRequest", eventRequest); var request = new HttpRequest(); request.Method = "POST"; request.Url = string.Format(ManagedEventUrlFormat, calendarId); request.AddOAuthAuthorization(this.accessToken); request.SetJsonBody(eventRequest); var response = this.HttpClient.GetResponse(request); if (response.Code != 202) { // TODO More useful exceptions for validation errors throw new CronofyException("Request failed"); } }
/// <inheritdoc/> public SmartInviteMultiRecipient GetSmartInvite(string smartInviteId) { Preconditions.NotEmpty("smartInviteId", smartInviteId); var request = new HttpRequest { Method = "GET", Url = this.urlProvider.SmartInviteUrl, QueryString = new HttpRequest.QueryStringCollection { { "smart_invite_id", smartInviteId } } }; request.AddOAuthAuthorization(this.clientSecret); var response = this.HttpClient.GetJsonResponse <SmartInviteMultiRecipientResponse>(request); return(response.ToSmartInvite()); }
/// <inheritdoc/> public SmartInvite CancelInvite(string smartInviteId, string recipientEmail) { Preconditions.NotEmpty("smartInviteId", smartInviteId); Preconditions.NotEmpty("emailAddress", recipientEmail); var request = new HttpRequest { Method = "POST", Url = this.urlProvider.SmartInviteUrl }; var smartInviteRequest = new SmartInviteCancelRequest(smartInviteId, recipientEmail); request.AddOAuthAuthorization(this.clientSecret); request.SetJsonBody(smartInviteRequest); var response = this.HttpClient.GetJsonResponse <SmartInviteResponse>(request); return(response.ToSmartInvite()); }
/// <inheritdoc/> public void DeleteAllEventsForCalendars(params string[] calendarIds) { Preconditions.NotEmpty("calendarIds", calendarIds); var request = new HttpRequest(); request.Method = "DELETE"; request.Url = this.UrlProvider.EventsUrl; request.AddOAuthAuthorization(this.AccessToken); var requestBody = new { calendar_ids = calendarIds }; request.SetJsonBody(requestBody); var response = this.HttpClient.GetResponse(request); if (response.Code != 202) { // TODO More useful exceptions for validation errors throw new CronofyException("Request failed"); } }
/// <inheritdoc/> public void ChangeParticipationStatus(string calendarId, string eventUid, ParticipationStatus status) { Preconditions.NotEmpty("calendarId", calendarId); Preconditions.NotEmpty("eventUid", eventUid); var request = new HttpRequest(); request.Method = "POST"; request.Url = string.Format(this.UrlProvider.ParticipationStatusUrlFormat, calendarId, eventUid); request.AddOAuthAuthorization(this.AccessToken); var requestBody = new { status = status.ToString().ToLower() }; request.SetJsonBody(requestBody); var response = this.HttpClient.GetResponse(request); if (response.Code != 202) { throw new CronofyException("Request failed"); } }
/// <inheritdoc /> public OAuthToken ApplicationCalendar(string applicationCalendarId) { Preconditions.NotEmpty("applicationCalendarId", applicationCalendarId); var request = new HttpRequest(); request.Method = "POST"; request.Url = this.urlProvider.ApplicationCalendarsUrl; var requestBody = new ApplicationCalendarRequest { ClientId = this.clientId, ClientSecret = this.clientSecret, ApplicationCalendarId = applicationCalendarId, }; request.SetJsonBody(requestBody); var tokenResponse = this.HttpClient.GetJsonResponse <OAuthTokenResponse>(request); return(tokenResponse.ToToken()); }
/// <inheritdoc/> public void AuthorizeUser(string email, string callbackUrl, string scope) { Preconditions.NotEmpty("email", email); Preconditions.NotEmpty("callbackUrl", callbackUrl); Preconditions.NotEmpty("scope", scope); var request = new HttpRequest(); request.Method = "POST"; request.Url = this.UrlProvider.AuthorizeWithServiceAccountUrl; request.AddOAuthAuthorization(this.AccessToken); var requestBody = new { email, callback_url = callbackUrl, scope }; request.SetJsonBody(requestBody); this.HttpClient.GetValidResponse(request); }
/// <inheritdoc/> public void DeleteExternalEvent(string calendarId, string eventUid) { Preconditions.NotEmpty("calendarId", calendarId); Preconditions.NotEmpty("eventUid", eventUid); var request = new HttpRequest(); request.Method = "DELETE"; request.Url = string.Format(ManagedEventUrlFormat, calendarId); request.AddOAuthAuthorization(this.accessToken); var requestBody = new { event_uid = eventUid }; request.SetJsonBody(requestBody); var response = this.HttpClient.GetResponse(request); if (response.Code != 202) { // TODO More useful exceptions for validation errors throw new CronofyException("Request failed"); } }
/// <inheritdoc/> public OAuthToken GetTokenFromRefreshToken(string refreshToken) { Preconditions.NotEmpty("refreshToken", refreshToken); var request = new HttpRequest(); request.Method = "POST"; request.Url = TokenUrl; var requestBody = new OAuthTokenRefreshRequest { ClientId = this.clientId, ClientSecret = this.clientSecret, GrantType = RefreshTokenGrantType, RefreshToken = refreshToken, }; request.SetJsonBody(requestBody); var token = this.HttpClient.GetJsonResponse <OAuthTokenResponse>(request); return(token.ToToken()); }
/// <inheritdoc/> public Calendar CreateCalendar(string profileId, string name) { Preconditions.NotEmpty("profileId", profileId); Preconditions.NotEmpty("name", name); var request = new HttpRequest(); request.Method = "POST"; request.Url = CalendarsUrl; request.AddOAuthAuthorization(this.accessToken); var calendarRequest = new CreateCalendarRequest { ProfileId = profileId, Name = name, }; request.SetJsonBody(calendarRequest); var response = this.HttpClient.GetJsonResponse <CreateCalendarResponse>(request); return(response.ToCalendar()); }
/// <summary> /// Creates a new <see cref="AuthorizationUrlBuilder"/> seeded with your /// client configuration. /// </summary> /// <param name="redirectUri"> /// The URI to redirect the user's response for the authorization /// request to, must not be empty. /// </param> /// <returns> /// Returns a new <see cref="AuthorizationUrlBuilder"/>. /// </returns> /// <remarks> /// The read_account, read_events, create_event, and delete_event scopes /// are requested by default. /// </remarks> /// <exception cref="System.ArgumentException"> /// Thrown if <paramref name="redirectUri"/> is null or empty. /// </exception> public AuthorizationUrlBuilder GetAuthorizationUrlBuilder(string redirectUri) { Preconditions.NotEmpty("redirectUri", redirectUri); return(new AuthorizationUrlBuilder(this.clientId, redirectUri)); }
/// <summary> /// Adds an OAuth authorization header to the request. /// </summary> /// <param name="accessToken"> /// The OAuth access token to use for authorization, must not be empty. /// </param> /// <exception cref="System.ArgumentException"> /// Thrown if <paramref name="accessToken"/> is empty. /// </exception> public void AddOAuthAuthorization(string accessToken) { Preconditions.NotEmpty("accessToken", accessToken); this.Headers.Add("Authorization", "Bearer " + accessToken); }