/// <summary>
 /// Instantiates a new AuthRepository
 /// </summary>
 /// <param name="boxConfig">The Box configuration that should be used</param>
 /// <param name="boxService">The Box service that will be used to make the requests</param>
 /// <param name="converter">How requests/responses will be serialized/deserialized respectively</param>
 /// <param name="session">The current authenticated session</param>
 public AuthRepository(IBoxConfig boxConfig, IBoxService boxService, IBoxConverter converter, OAuthSession session)
 {
     _config = boxConfig;
     _service = boxService;
     _converter = converter;
     Session = session;
 }
Beispiel #2
0
 public BoxServiceTest()
 {
     // Initial Setup
     _converter = new BoxJsonConverter();
     _handler   = new Mock <IRequestHandler>();
     _service   = new BoxService(_handler.Object);
 }
 /// <summary>
 /// Instantiates the base class for the Box resource managers
 /// </summary>
 /// <param name="config"></param>
 /// <param name="service"></param>
 /// <param name="converter"></param>
 /// <param name="auth"></param>
 public BoxResourceManager(IBoxConfig config, IBoxService service, IBoxConverter converter, IAuthRepository auth)
 {
     _config    = config;
     _service   = service;
     _converter = converter;
     _auth      = auth;
 }
Beispiel #4
0
 /// <summary>
 /// Instantiates a new AuthRepository
 /// </summary>
 /// <param name="boxConfig">The Box configuration that should be used</param>
 /// <param name="boxService">The Box service that will be used to make the requests</param>
 /// <param name="converter">How requests/responses will be serialized/deserialized respectively</param>
 /// <param name="session">The current authenticated session</param>
 public AuthRepository(IBoxConfig boxConfig, IBoxService boxService, IBoxConverter converter, OAuthSession session)
 {
     _config    = boxConfig;
     _service   = boxService;
     _converter = converter;
     Session    = session;
 }
        public BoxResourceManagerTestIntegration()
        {
            _auth = new OAuthSession("HrMywfaXCtAStbY9FTvoCbMZCBPeBgud", "Qx34izsfUuvbcm90x88gPs6ZiRXexxN3jbQGqNoY2r9to6mppRBoCD4iqlSVrm0F", 3600, "bearer");

            _handler = new HttpRequestHandler();
            _parser  = new BoxJsonConverter();
            _config  = new BoxConfig(ClientId, ClientSecret, RedirectUri);
            _client  = new BoxClient(_config, _auth);
        }
Beispiel #6
0
 /// <summary>
 /// Instantiates the base class for the Box resource managers
 /// </summary>
 /// <param name="config"></param>
 /// <param name="service"></param>
 /// <param name="converter"></param>
 /// <param name="auth"></param>
 public BoxResourceManager(IBoxConfig config, IBoxService service, IBoxConverter converter, IAuthRepository auth, string asUser, bool?suppressNotifications)
 {
     _config                = config;
     _service               = service;
     _converter             = converter;
     _auth                  = auth;
     _asUser                = asUser;
     _suppressNotifications = suppressNotifications;
 }
Beispiel #7
0
        /// <summary>
        /// Initializes a new BoxClient with the provided config, converter, service and auth objects.
        /// </summary>
        /// <param name="boxConfig">The config object to use</param>
        /// <param name="boxConverter">The box converter object to use</param>
        /// <param name="boxService">The box service to use</param>
        /// <param name="auth">The auth repository object to use</param>
        public BoxClient(IBoxConfig boxConfig, IBoxConverter boxConverter, IBoxService boxService, IAuthRepository auth)
        {
            Config     = boxConfig;
            Auth       = auth;
            _converter = boxConverter;
            _service   = boxService;

            InitManagers();
        }
Beispiel #8
0
        public BoxResourceManagerTestIntegration()
        {
            _auth = new OAuthSession("YOUR_ACCESS_TOKEN", "YOUR_REFRESH_TOKEN", 3600, "bearer");

            _handler = new HttpRequestHandler();
            _parser  = new BoxJsonConverter();
            _config  = new BoxConfig(ClientId, ClientSecret, RedirectUri);
            _client  = new BoxClient(_config, _auth);
        }
        public BoxResourceManagerTestIntegration()
        {
            _auth = new OAuthSession("YOUR_ACCESS_TOKEN", "YOUR_REFRESH_TOKEN", 3600, "bearer");

            _handler = new HttpRequestHandler();
            _parser = new BoxJsonConverter();
            _config = new BoxConfig(ClientId, ClientSecret, RedirectUri);
            _client = new BoxClient(_config, _auth);
        }
        public BoxResourceManagerTestIntegration()
        {
            _auth = new OAuthSession("HrMywfaXCtAStbY9FTvoCbMZCBPeBgud", "Qx34izsfUuvbcm90x88gPs6ZiRXexxN3jbQGqNoY2r9to6mppRBoCD4iqlSVrm0F", 3600, "bearer");

            _handler = new HttpRequestHandler();
            _parser = new BoxJsonConverter();
            _config = new BoxConfig(ClientId, ClientSecret, RedirectUri);
            _client = new BoxClient(_config, _auth);
        }
        public BoxResourceManagerTest()
        {
            // Initial Setup
            _converter = new BoxJsonConverter();
            _handler = new Mock<IRequestHandler>();
            _service = new BoxService(_handler.Object);
            _config = new Mock<IBoxConfig>();

            _authRepository = new AuthRepository(_config.Object, _service, _converter, new OAuthSession("fakeAccessToken", "fakeRefreshToken", 3600, "bearer"));
        }
        public BoxResourceManagerTest()
        {
            // Initial Setup
            _converter = new BoxJsonConverter();
            _handler   = new Mock <IRequestHandler>();
            _service   = new BoxService(_handler.Object);
            _config    = new Mock <IBoxConfig>();

            _authRepository = new AuthRepository(_config.Object, _service, _converter, new OAuthSession("fakeAccessToken", "fakeRefreshToken", 3600, "bearer"));
        }
Beispiel #13
0
        /// <summary>
        /// Instantiates a BoxClient with the provided config object and auth session
        /// </summary>
        /// <param name="boxConfig">The config object to be used</param>
        /// <param name="authSession">A fully authenticated auth session</param>
        public BoxClient(IBoxConfig boxConfig, OAuthSession authSession)
        {
            Config = boxConfig;

            _handler   = new HttpRequestHandler();
            _converter = new BoxJsonConverter();
            _service   = new BoxService(_handler);
            Auth       = new AuthRepository(Config, _service, _converter, authSession);

            InitManagers();
        }
Beispiel #14
0
        /// <summary>
        /// Initializes a new BoxClient with the provided config, converter, service and auth objects.
        /// </summary>
        /// <param name="boxConfig">The config object to use</param>
        /// <param name="boxConverter">The box converter object to use</param>
        /// <param name="boxService">The box service to use</param>
        /// <param name="auth">The auth repository object to use</param>
        public BoxClient(IBoxConfig boxConfig, IBoxConverter boxConverter, IRequestHandler requestHandler, IBoxService boxService, IAuthRepository auth)
        {
            Config = boxConfig;

            _handler   = requestHandler;
            _converter = boxConverter;
            _service   = boxService;
            Auth       = auth;

            InitManagers();
        }
        /// <summary>
        /// Instantiates a BoxClient that uses JWT authentication
        /// </summary>
        /// <param name="boxConfig">The config object to be used</param>
        /// <param name="authRepository">An IAuthRepository that knows how to retrieve new tokens using JWT</param>
        public BoxClient(IBoxConfig boxConfig, IAuthRepository authRepository)
        {
            Config = boxConfig;

            _handler   = new HttpRequestHandler();
            _converter = new BoxJsonConverter();
            _service   = new BoxService(_handler);
            Auth       = authRepository;

            InitManagers();
        }
        public BoxResourceManagerTestIntegration()
        {
            _auth = new OAuthSession("YOUR_ACCESS_TOKEN", "YOUR_REFRESH_TOKEN", 3600, "bearer");

            _handler = new HttpRequestHandler();
            _parser = new BoxJsonConverter();
            _config = new BoxConfig(ClientId, ClientSecret, RedirectUri);
            _client = new BoxClient(_config, _auth);

            _boxDeveloperEditionConfig = new BoxConfig(EnterpriseId, "enterprise", ClientId, ClientSecret, PrivateKey, PrivateKeyPassword);
            _boxDeveloperEditionClient = new BoxClient(_boxDeveloperEditionConfig);
        }
        public BoxResourceManagerTestIntegration()
        {
            _auth = new OAuthSession("YOUR_ACCESS_TOKEN", "YOUR_REFRESH_TOKEN", 3600, "bearer");

            _handler = new HttpRequestHandler();
            _parser  = new BoxJsonConverter();
            _config  = new BoxConfig(ClientId, ClientSecret, RedirectUri);
            _client  = new BoxClient(_config, _auth);

            _boxDeveloperEditionConfig = new BoxConfig(EnterpriseId, "enterprise", ClientId, ClientSecret, PrivateKey, PrivateKeyPassword);
            _boxDeveloperEditionClient = new BoxClient(_boxDeveloperEditionConfig);
        }
Beispiel #18
0
        /// <summary>
        /// Instantiates a BoxClient with the provided config object and auth session
        /// </summary>
        /// <param name="boxConfig">The config object to be used</param>
        /// <param name="authSession">A fully authenticated auth session</param>
        public BoxClient(IBoxConfig boxConfig, OAuthSession authSession)
        {
            _config = boxConfig;
            
            IRequestHandler handler = new HttpRequestHandler();
            _converter = new BoxJsonConverter();

            _service = new BoxService(handler);

            Auth = new AuthRepository(_config, _service, _converter, authSession);

            InitManagers();
        }
        /// <summary>
        /// Instantiates a BoxClient with the provided config object
        /// </summary>
        /// <param name="boxConfig">The config object to be used</param>
        /// <param name="asUser">The user ID to set as the 'As-User' header parameter; used to make calls in the context of a user using an admin token</param>
        public BoxClient(IBoxConfig boxConfig, string asUser = null)
        {
            Config = boxConfig;

            _asUser = asUser;

            _handler   = new HttpRequestHandler();
            _converter = new BoxJsonConverter();
            _service   = new BoxService(_handler);
            Auth       = new AuthRepository(Config, _service, _converter, null);

            InitManagers();
        }
        /// <summary>
        /// Instantiates a BoxClient that uses JWT authentication
        /// </summary>
        /// <param name="boxConfig">The config object to be used</param>
        /// <param name="authRepository">An IAuthRepository that knows how to retrieve new tokens using JWT</param>
        /// <param name="asUser">The user ID to set as the 'As-User' header parameter; used to make calls in the context of a user using an admin token</param>
        /// <param name="suppressNotifications">Whether or not to suppress both email and webhook notifications. Typically used for administrative API calls. Your application must have “Manage an Enterprise” scope, and the user making the API calls is a co-admin with the correct "Edit settings for your company" permission.</param>
        public BoxClient(IBoxConfig boxConfig, IAuthRepository authRepository, string asUser = null, bool?suppressNotifications = null)
        {
            Config = boxConfig;

            _asUser = asUser;
            _suppressNotifications = suppressNotifications;

            _handler   = new HttpRequestHandler();
            _converter = new BoxJsonConverter();
            _service   = new BoxService(_handler);
            Auth       = authRepository;

            InitManagers();
        }
Beispiel #21
0
        /// <summary>
        /// Instantiates a BoxClient with the provided config object and auth session
        /// </summary>
        /// <param name="boxConfig">The config object to be used</param>
        /// <param name="authSession">A fully authenticated auth session</param>
        /// <param name="asUser">The user ID to set as the 'As-User' header parameter; used to make calls in the context of a user using an admin token</param>
        /// <param name="suppressNotifications">Whether or not to suppress both email and webhook notifications. Typically used for administrative API calls. Your application must have “Manage an Enterprise” scope, and the user making the API calls is a co-admin with the correct "Edit settings for your company" permission.</param>
        public BoxClient(IBoxConfig boxConfig, OAuthSession authSession, string asUser = null, bool?suppressNotifications = null)
        {
            Config = boxConfig;

            _asUser = asUser;
            _suppressNotifications = suppressNotifications;

            _handler   = new HttpRequestHandler(boxConfig.WebProxy);
            _converter = new BoxJsonConverter();
            _service   = new BoxService(_handler);
            Auth       = new AuthRepository(Config, _service, _converter, authSession);

            InitManagers();
        }
        /// <summary>
        /// Initializes a new BoxClient with the provided config, converter, service and auth objects.
        /// </summary>
        /// <param name="boxConfig">The config object to use</param>
        /// <param name="boxConverter">The box converter object to use</param>
        /// <param name="requestHandler">The box request handler to use</param>
        /// <param name="boxService">The box service to use</param>
        /// <param name="auth">The auth repository object to use</param>
        /// <param name="asUser">The user ID to set as the 'As-User' header parameter; used to make calls in the context of a user using an admin token</param>
        /// <param name="suppressNotifications">Whether or not to suppress both email and webhook notifications. Typically used for administrative API calls. Your application must have “Manage an Enterprise” scope, and the user making the API calls is a co-admin with the correct "Edit settings for your company" permission.</param>
        public BoxClient(IBoxConfig boxConfig, IBoxConverter boxConverter, IRequestHandler requestHandler, IBoxService boxService, IAuthRepository auth, string asUser = null, bool?suppressNotifications = null)
        {
            Config = boxConfig;

            _asUser = asUser;
            _suppressNotifications = suppressNotifications;

            _handler   = requestHandler;
            _converter = boxConverter;
            _service   = boxService;
            Auth       = auth;

            InitManagers();
        }
        public BoxResourceManagerTest()
        {
            // Initial Setup
            _converter = new BoxJsonConverter();
            _handler   = new Mock <IRequestHandler>();
            _service   = new BoxService(_handler.Object);
            _config    = new Mock <IBoxConfig>();
            _config.SetupGet(x => x.CollaborationsEndpointUri).Returns(new Uri(Constants.CollaborationsEndpointString));
            _config.SetupGet(x => x.FoldersEndpointUri).Returns(_FoldersUri);
            _config.SetupGet(x => x.FilesEndpointUri).Returns(_FilesUri);
            _config.SetupGet(x => x.UserEndpointUri).Returns(_usersUri);

            _authRepository = new AuthRepository(_config.Object, _service, _converter, new OAuthSession("fakeAccessToken", "fakeRefreshToken", 3600, "bearer"));
        }
        protected BoxResourceManagerTest()
        {
            // Initial Setup
            Converter = new BoxJsonConverter();
            Handler   = new Mock <IRequestHandler>();
            Service   = new BoxService(Handler.Object);
            Config    = new Mock <IBoxConfig>();
            Config.SetupGet(x => x.CollaborationsEndpointUri).Returns(new Uri(Constants.CollaborationsEndpointString));
            Config.SetupGet(x => x.FoldersEndpointUri).Returns(FoldersUri);
            Config.SetupGet(x => x.FilesEndpointUri).Returns(FilesUri);
            Config.SetupGet(x => x.FilesUploadEndpointUri).Returns(FilesUploadUri);
            Config.SetupGet(x => x.UserEndpointUri).Returns(UserUri);
            Config.SetupGet(x => x.InviteEndpointUri).Returns(InviteUri);

            AuthRepository = new AuthRepository(Config.Object, Service, Converter, new OAuthSession("fakeAccessToken", "fakeRefreshToken", 3600, "bearer"));
        }
Beispiel #25
0
        public BoxResourceManagerTestIntegration()
        {
            _handler = new HttpRequestHandler();
            _parser  = new BoxJsonConverter();

            if (userToken == null)
            {
                // Legacy way of getting the token
                _auth = new OAuthSession("YOUR_ACCESS_TOKEN", "YOUR_REFRESH_TOKEN", 3600, "bearer");

                _config = new BoxConfig(ClientId, ClientSecret, RedirectUri);
                _client = new BoxClient(_config, _auth);
            }
            else
            {
                _config = BoxConfig.CreateFromJsonString(jsonConfig);

                _client = userClient;
                _auth   = new OAuthSession(userToken, "", 3600, "bearer");
            }
        }
 public BoxFilesManager(IBoxConfig config, IBoxService service, IBoxConverter converter, IAuthRepository auth)
     : base(config, service, converter, auth) { }
Beispiel #27
0
        /// <summary>
        /// Parses the BoxResponse with the provided converter
        /// </summary>
        /// <typeparam name="T">The return type of the Box response</typeparam>
        /// <param name="response">The response to parse</param>
        /// <param name="converter">The converter to use for the conversion</param>
        /// <returns></returns>
        internal static IBoxResponse <T> ParseResults <T>(this IBoxResponse <T> response, IBoxConverter converter)
            where T : class
        {
            switch (response.Status)
            {
            case ResponseStatus.Success:
                if (!string.IsNullOrWhiteSpace(response.ContentString))
                {
                    response.ResponseObject = converter.Parse <T>(response.ContentString);
                }
                break;

            case ResponseStatus.Error:
                if (!string.IsNullOrWhiteSpace(response.ContentString))
                {
                    try
                    {
                        response.Error = converter.Parse <BoxError>(response.ContentString);
                    }
                    catch (Exception)
                    {
                        Debug.WriteLine(string.Format("Unable to parse error message: {0}", response.ContentString));
                    }

                    // Throw formatted error if available
                    if (response.Error != null && !string.IsNullOrWhiteSpace(response.Error.Name))
                    {
                        throw new BoxException(string.Format("{0}: {1}", response.Error.Name, response.Error.Description))
                              {
                                  StatusCode = response.StatusCode
                              }
                    }
                    ;
                    // Throw error with full response if error object not available
                    throw new BoxException(response.ContentString)
                          {
                              StatusCode = response.StatusCode
                          };
                }
                throw new BoxException()
                      {
                          StatusCode = response.StatusCode
                      };
            }
            return(response);
        }
 public BoxFileManagerCommand(IBoxConfig config, IBoxService service, IBoxConverter converter, IAuthRepository auth, string asUser = null, bool?suppressNotifications = default(bool?))
     : base(config, service, converter, auth, asUser, suppressNotifications)
 {
 }
Beispiel #29
0
 /// <summary>
 /// Create a new BoxMetadataCascadePolicy object.
 /// </summary>
 /// <param name="config"></param>
 /// <param name="service"></param>
 /// <param name="converter"></param>
 /// <param name="auth"></param>
 /// <param name="asUser"></param>
 /// <param name="suppressNotifications"></param>
 public BoxMetadataCascadePolicyManager(IBoxConfig config, IBoxService service, IBoxConverter converter, IAuthRepository auth, string asUser = null, bool?suppressNotifications = null)
     : base(config, service, converter, auth, asUser, suppressNotifications)
 {
 }
Beispiel #30
0
 /// <summary>
 /// Instantiates a new AuthRepository
 /// </summary>
 /// <param name="boxConfig">The Box configuration that should be used</param>
 /// <param name="boxService">The Box service that will be used to make the requests</param>
 /// <param name="converter">How requests/responses will be serialized/deserialized respectively</param>
 public AuthRepository(IBoxConfig boxConfig, IBoxService boxService, IBoxConverter converter) : this(boxConfig, boxService, converter, null)
 {
 }
 public BoxCollaborationsManager(IBoxConfig config, IBoxService service, IBoxConverter converter, IAuthRepository auth)
     : base(config, service, converter, auth)
 {
 }
        /// <summary>
        /// Parses the BoxResponse with the provided converter
        /// </summary>
        /// <typeparam name="T">The return type of the Box response</typeparam>
        /// <param name="response">The response to parse</param>
        /// <param name="converter">The converter to use for the conversion</param>
        /// <returns></returns>
        internal static IBoxResponse <T> ParseResults <T>(this IBoxResponse <T> response, IBoxConverter converter)
            where T : class
        {
            switch (response.Status)
            {
            case ResponseStatus.Success:
                if (!string.IsNullOrWhiteSpace(response.ContentString))
                {
                    response.ResponseObject = converter.Parse <T>(response.ContentString);
                }
                break;

            case ResponseStatus.Error:
                if (!string.IsNullOrWhiteSpace(response.ContentString))
                {
                    response.Error = converter.Parse <BoxError>(response.ContentString);
                    if (response.Error != null && !string.IsNullOrWhiteSpace(response.Error.Name))
                    {
                        throw new BoxException(string.Format("{0}: {1}", response.Error.Name, response.Error.Description));
                    }
                    throw new BoxException(response.ContentString);
                }
                break;
            }
            return(response);
        }
 public BoxMetadataManager(IBoxConfig config, IBoxService service, IBoxConverter converter, IAuthRepository auth)
     : base(config, service, new BoxMetadataJsonConverter(), auth)
 {
 }
        /// <summary>
        /// Parses the BoxResponse with the provided converter
        /// </summary>
        /// <typeparam name="T">The return type of the Box response</typeparam>
        /// <param name="response">The response to parse</param>
        /// <param name="converter">The converter to use for the conversion</param>
        /// <returns></returns>
        internal static IBoxResponse <T> ParseResults <T>(this IBoxResponse <T> response, IBoxConverter converter)
            where T : class
        {
            switch (response.Status)
            {
            case ResponseStatus.Success:
                if (!string.IsNullOrWhiteSpace(response.ContentString))
                {
                    response.ResponseObject = converter.Parse <T>(response.ContentString);
                }
                break;

            case ResponseStatus.RateLimitReached:
                if (!string.IsNullOrWhiteSpace(response.ContentString))
                {
                    int retryAfter = int.Parse(response.Headers
                                               .Where(x => x.Key == "Retry-After")
                                               .SelectMany(x => x.Value)
                                               .FirstOrDefault() ?? "20");

                    response.Error = converter.Parse <BoxError>(response.ContentString);
                    if (response.Error != null && !string.IsNullOrWhiteSpace(response.Error.Name))
                    {
                        throw new BoxRateLimitingException(string.Format("{0}: {1}", response.Error.Name, response.Error.Description), retryAfter);
                    }
                    throw new BoxRateLimitingException(response.ContentString, retryAfter);
                }
                break;

            case ResponseStatus.Unauthorized:
            {
                response.Error = converter.Parse <BoxError>(response.ContentString);
                if (response.Error != null && !string.IsNullOrWhiteSpace(response.Error.Name))
                {
                    throw new AccessTokenExpiredException(string.Format("{0}: {1}", response.Error.Name, response.Error.Description));
                }
                throw new AccessTokenExpiredException(response.ContentString);
            }

            case ResponseStatus.Error:
                if (!string.IsNullOrWhiteSpace(response.ContentString))
                {
                    try
                    {
                        response.Error = converter.Parse <BoxError>(response.ContentString);
                    }
                    catch (Exception)
                    {
                        Debug.WriteLine(string.Format("Unable to parse error message: {0}", response.ContentString));
                    }

                    // Throw formatted error if available
                    if (response.Error != null && !string.IsNullOrWhiteSpace(response.Error.Name))
                    {
                        throw new BoxException(string.Format("{0}: {1}", response.Error.Name, response.Error.Description))
                              {
                                  StatusCode = response.StatusCode
                              }
                    }
                    ;
                    // Throw error with full response if error object not available
                    throw new BoxException(response.ContentString)
                          {
                              StatusCode = response.StatusCode
                          };
                }
                throw new BoxException()
                      {
                          StatusCode = response.StatusCode
                      };
            }
            return(response);
        }
 /// <summary>
 /// Instantiates a new AuthRepository
 /// </summary>
 /// <param name="boxConfig">The Box configuration that should be used</param>
 /// <param name="boxService">The Box service that will be used to make the requests</param>
 /// <param name="converter">How requests/responses will be serialized/deserialized respectively</param>
 public AuthRepository(IBoxConfig boxConfig, IBoxService boxService, IBoxConverter converter) : this(boxConfig, boxService, converter, null) { }
 /// <summary>
 /// Initializes a new instance of the <see cref="BoxSharedItemsManager"/> class.
 /// </summary>
 /// <param name="config">The config object to use</param>
 /// <param name="service">The Box service object</param>
 /// <param name="converter">The box converter object to use</param>
 /// <param name="auth">The auth repository object to use</param>
 /// <param name="asUser">The user ID to set as the 'As-User' header parameter; used to make calls in the context of a user using an admin token</param>
 /// <param name="suppressNotifications">Whether or not to suppress both email and webhook notifications. Typically used for administrative API calls. Your application must have “Manage an Enterprise” scope, and the user making the API calls is a co-admin with the correct "Edit settings for your company" permission.</param>
 public BoxSharedItemsManager(IBoxConfig config, IBoxService service, IBoxConverter converter, IAuthRepository auth, string asUser = null, bool?suppressNotifications = null)
     : base(config, service, converter, auth, asUser, suppressNotifications)
 {
 }
 public BoxMetadataManager(IBoxConfig config, IBoxService service, IBoxConverter converter, IAuthRepository auth)
     : base(config, service, new BoxMetadataJsonConverter(), auth) { }
        /// <summary>
        /// Parses the BoxResponse with the provided converter
        /// </summary>
        /// <typeparam name="T">The return type of the Box response</typeparam>
        /// <param name="response">The response to parse</param>
        /// <param name="converter">The converter to use for the conversion</param>
        /// <returns></returns>
        public static IBoxResponse <T> ParseResults <T>(this IBoxResponse <T> response, IBoxConverter converter)
            where T : class
        {
            BoxException exToThrow = null;

            switch (response.Status)
            {
            case ResponseStatus.Success:
                if (!string.IsNullOrWhiteSpace(response.ContentString))
                {
                    response.ResponseObject = converter.Parse <T>(response.ContentString);
                }
                break;

            case ResponseStatus.Forbidden:
                var errorMsg = response.Headers.WwwAuthenticate.FirstOrDefault();
                if (errorMsg != null)
                {
                    var err = new BoxError()
                    {
                        Code = response.StatusCode.ToString(), Description = "Forbidden", Message = errorMsg.ToString()
                    };
                    throw new BoxException(err.Message, err);
                }
                else if (!string.IsNullOrWhiteSpace(response.ContentString))
                {
                    response.Error = converter.Parse <BoxError>(response.ContentString);
                    throw new BoxException(response.ContentString, response.Error)
                          {
                              StatusCode = response.StatusCode
                          };
                }
                else
                {
                    throw new BoxException("Forbidden");
                }

            default:
                if (!string.IsNullOrWhiteSpace(response.ContentString))
                {
                    try
                    {
                        switch (response.StatusCode)
                        {
                        case System.Net.HttpStatusCode.Conflict:
                            if (response is IBoxResponse <BoxPreflightCheck> )
                            {
                                BoxPreflightCheckConflictError <BoxFile> err = converter.Parse <BoxPreflightCheckConflictError <BoxFile> >(response.ContentString);
                                exToThrow = new BoxPreflightCheckConflictException <BoxFile>(response.ContentString, err);
                            }
                            else
                            {
                                BoxConflictError <T> error = converter.Parse <BoxConflictError <T> >(response.ContentString);
                                exToThrow = new BoxConflictException <T>(response.ContentString, error);
                            }

                            break;

                        default:
                            response.Error = converter.Parse <BoxError>(response.ContentString);
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(string.Format("Unable to parse error message: {0}", response.ContentString));
                    }

                    throw exToThrow == null ?
                          new BoxException(response.ContentString, response.Error)
                          {
                              StatusCode = response.StatusCode
                          } :
                          exToThrow;
                }
                throw new BoxException(response.ContentString)
                      {
                          StatusCode = response.StatusCode
                      };
            }
            return(response);
        }
Beispiel #39
0
 public BoxRetentionPoliciesManager(IBoxConfig config, IBoxService service, IBoxConverter converter, IAuthRepository auth, string asUser = null)
     : base(config, service, converter, auth, asUser)
 {
 }
 public BoxCollectionsManager(IBoxConfig config, IBoxService service, IBoxConverter converter, IAuthRepository auth, string asUser = null, bool? suppressNotifications = null)
     : base(config, service, converter, auth, asUser, suppressNotifications) { }
 public BoxCommentsManager(IBoxConfig config, IBoxService service, IBoxConverter converter, IAuthRepository auth, string asUser = null)
     : base(config, service, converter, auth, asUser) { }