/// <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);
        }
예제 #2
0
        /// <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);
        }
예제 #4
0
            /// <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;
            }
예제 #5
0
            /// <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);
            }
예제 #6
0
        /// <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);
        }
예제 #7
0
        /// <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);
        }
예제 #8
0
        /// <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));
            }
        }
예제 #9
0
        /// <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;
        }
예제 #10
0
        /// <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));
        }
예제 #11
0
        /// <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);
        }
예제 #12
0
        /// <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);
        }
예제 #13
0
        /// <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);
        }
예제 #14
0
        /// <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());
        }
예제 #15
0
        /// <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 <Responses.SmartInviteMultiRecipientResponse>(request);

            return(response.ToSmartInvite());
        }
예제 #16
0
        /// <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");
            }
        }
예제 #17
0
        /// <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");
            }
        }
예제 #18
0
        /// <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 <Responses.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);
        }
예제 #20
0
        /// <inheritdoc/>
        public SmartInvite GetSmartInvite(string smartInviteId, string emailAddress)
        {
            Preconditions.NotEmpty("smartInviteId", smartInviteId);
            Preconditions.NotEmpty("emailAddress", emailAddress);

            var request = new HttpRequest
            {
                Method      = "GET",
                Url         = this.urlProvider.SmartInviteUrl,
                QueryString =
                    new HttpRequest.QueryStringCollection
                {
                    { "smart_invite_id", smartInviteId },
                    { "recipient_email", emailAddress }
                }
            };

            request.AddOAuthAuthorization(this.clientSecret);

            var response = this.HttpClient.GetJsonResponse <SmartInviteResponse>(request);

            return(response.ToSmartInvite());
        }
예제 #21
0
        /// <inheritdoc/>
        public OAuthToken GetTokenFromRefreshToken(string refreshToken)
        {
            Preconditions.NotEmpty("refreshToken", refreshToken);

            var request = new HttpRequest();

            request.Method = "POST";
            request.Url    = this.urlProvider.TokenUrl;

            var requestBody = new OAuthTokenRefreshRequest
            {
                ClientId     = this.clientId,
                ClientSecret = this.clientSecret,
                GrantType    = RefreshTokenGrantType,
                RefreshToken = refreshToken,
            };

            request.SetJsonBody(requestBody);

            var token = this.HttpClient.GetJsonResponse <Responses.OAuthTokenResponse>(request);

            return(token.ToToken());
        }
예제 #22
0
        /// <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(this.UrlProvider.ManagedEventUrlFormat, calendarId);
            request.AddOAuthAuthorization(this.AccessToken);

            var requestBody = new DeleteExternalEventRequest {
                EventUid = eventUid
            };

            request.SetJsonBody(requestBody);

            var response = this.HttpClient.GetResponse(request);

            if (response.Code != 202)
            {
                throw new CronofyException("Request failed");
            }
        }
예제 #23
0
        /// <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);
        }
예제 #24
0
        /// <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, this.urlProvider, redirectUri));
        }