예제 #1
0
        /// <summary>
        /// Instantiate the document.
        /// </summary>
        /// <param name="client">The client instance to make requests from.</param>
        /// <param name="data">
        /// A key-value pair to instantiate the object with. Use the following values:
        ///   - string 'id' The document ID.
        ///   - string|DateTime 'createdAt' The date the document was created.
        ///   - string 'name' The document title.
        ///   - string 'status' The document status, which can be 'queued', 'processing', 'done', or 'error'.
        /// </param>
        public Document(BoxViewClient client, IDictionary<string, object> data)
        {
            Client = client;
            Id = (string)data["id"];

            SetValues(data);
        }
예제 #2
0
 /// <summary>
 /// Send a new request to the API and return a string.
 /// </summary>
 /// <param name="client">The client instance to make requests from.</param>
 /// <param name="path">The path to make a request to.</param>
 /// <param name="getParams">A key-value pair of GET params to be added to the URL.</param>
 /// <param name="postParams">A key-value pair of POST params to be sent in the body.</param>
 /// <param name="requestOptions">
 /// A key-value pair of request options that may modify the way the request is made.
 /// </param>
 /// <returns>The response is pass-thru from Request.</returns>
 /// <exception>BoxViewException</exception>
 protected static HttpContent RequestHttpContent(
     BoxViewClient client,
     string path,
     IDictionary<string, string> getParams = null,
     IDictionary<string, string> postParams = null,
     IDictionary<string, object> requestOptions = null)
 {
     requestOptions["rawResponse"] = true;
     return client.RequestHandler.RequestHttpContent(
         path: path,
         getParams: getParams,
         postParams: postParams,
         requestOptions: requestOptions);
 }
예제 #3
0
        public static void Main()
        {
            BoxView = new BoxViewClient(API_KEY);

            Example1();
            Example2();
            Example3();
            Example4();
            Example5();
            Example6();
            Example7();
            Example8();
            Example9();
            Example10();
            Example11();
            Example12();
            Example13();
            Example14();
            Example15();
            Example16();
            Example17();
        }
예제 #4
0
        /// <summary>
        /// Generic upload function used by the two other upload functions, which are more specific than this one, and
        /// know how to handle upload by URL and upload from filesystem.
        /// </summary>
        /// <param name="client">The client instance to make requests from.</param>
        /// <param name="options">
        /// A key-value pair of options relating to the file upload. Pass-thru from the other upload functions.
        /// </param>
        /// <param name="postParams">A key-value pair of POST params to be sent in the body.</param>
        /// <param name="requestOptions">
        /// A key-value pair of request options that may modify the way the request is made.
        /// </param>
        /// <returns>A new document instance.</returns>
        /// <exception cref="BoxViewException"></exception>
        static Document Upload(
            BoxViewClient client,
            IDictionary<string, object> options,
            IDictionary<string, string> postParams = null,
            IDictionary<string, object> requestOptions = null)
        {
            if (postParams == null)
                postParams = new Dictionary<string, string>();

            postParams["name"] = (string)options["name"];

            if (options["thumbnails"] != null)
            {
                var thumbnails = options["thumbnails"];

                if (thumbnails is string[])
                    thumbnails = ((string[])thumbnails).ToList();

                if (thumbnails is List<string>)
                    thumbnails = ((List<string>)thumbnails).ToArray();

                if (thumbnails is string[])
                    thumbnails = String.Join(",", (string[])thumbnails);

                postParams["thumbnails"] = (string)thumbnails;
            }

            if (options["nonSvg"] != null)
                postParams["non_svg"] = (bool)options["nonSvg"] ? "1" : "0";

            var metadata = RequestJson(
                               client: client,
                               path: PATH,
                               postParams: postParams,
                               requestOptions: requestOptions);
            return new Document(client, metadata);
        }
예제 #5
0
 /// <summary>
 /// Upload a file by URL and return a new document instance.
 /// </summary>
 /// <param name="client">The client instance to make requests from.</param>
 /// <param name="url">The URL of the file to upload.</param>
 /// <param name="name">Override the filename of the file being uploaded.</param>
 /// <param name="thumbnails">
 /// An array of dimensions in pixels, with each dimension formatted as [width]x[height], this can also be a
 /// comma-separated string.
 /// </param>
 /// <param name="nonSvg">
 /// Create a second version of the file that doesn't use SVG, for users with browsers that don't support SVG?
 /// </param>
 /// <returns>A new document instance.</returns>
 /// <exception cref="BoxViewException"></exception>
 public static Document Upload(
     BoxViewClient client,
     string url,
     string name = null,
     object thumbnails = null,
     bool? nonSvg = null)
 {
     return Upload(
         client: client,
         options: new Dictionary<string, object>
         {
             { "name", name },
             { "thumbnails", thumbnails },
             { "nonSvg", nonSvg }
         },
         postParams: new Dictionary<string, string>
         {
             { "url", url }
         });
 }
예제 #6
0
 /// <summary>
 /// Upload a local file and return a new document instance.
 /// </summary>
 /// <param name="client">The client instance to make requests from.</param>
 /// <param name="file">The file resource to upload.</param>
 /// <param name="name">Override the filename of the file being uploaded.</param>
 /// <param name="thumbnails">
 /// An array of dimensions in pixels, with each dimension formatted as [width]x[height], this can also be a
 /// comma-separated string.
 /// </param>
 /// <param name="nonSvg">
 /// Create a second version of the file that doesn't use SVG, for users with browsers that don't support SVG?
 /// </param>
 /// <returns>A new document instance.</returns>
 /// <exception cref="BoxViewException"></exception>
 public static Document Upload(
     BoxViewClient client,
     FileStream file,
     string name = null,
     object thumbnails = null,
     bool? nonSvg = null)
 {
     return Upload(
         client: client,
         options: new Dictionary<string, object>
         {
             { "name", name },
             { "thumbnails", thumbnails },
             { "nonSvg", nonSvg }
         },
         requestOptions: new Dictionary<string, object>
         {
             { "file", file },
             { "host", FILE_UPLOAD_HOST }
         });
 }
예제 #7
0
        /// <summary>
        /// Create a new document instance by ID, and load it with values requested from the API.
        /// </summary>
        /// <param name="client">The client instance to make requests from.</param>
        /// <param name="id">The document ID.</param>
        /// <returns>A document instance using data from the API.</returns>
        /// <exception cref="BoxViewException"></exception>
        public static Document Get(BoxViewClient client, string id)
        {
            string[] fields = { "id", "created_at", "name", "status" };

            var getParams = new Dictionary<string, string>
            {
                { "fields", String.Join(",", fields) }
            };

            var metadata = RequestJson(
                               client: client,
                               path: PATH + "/" + id,
                               getParams: getParams);
            return new Document(client, metadata);
        }
예제 #8
0
        /// <summary>
        /// Get a list of all documents that meet the provided criteria.
        /// </summary>
        /// <param name="client">The client instance to make requests from.</param>
        /// <param name="limit">The number of documents to return.</param>
        /// <param name="createdBefore">Upper date limit to filter by.</param>
        /// <param name="createdAfter">Lower date limit to filter by.</param>
        /// <returns>An array containing document instances matching the request.</returns>
        /// <exception cref="BoxViewException"></exception>
        public static List<Document> Find(
            BoxViewClient client,
            int? limit = null,
            object createdBefore = null,
            object createdAfter = null)
        {
            var getParams = new Dictionary<string, string>();

            if (limit != null && limit > 0)
                getParams["limit"] = limit.ToString();

            if (createdBefore != null)
                getParams["created_before"] = (createdBefore is DateTime)
                                              ? Date((DateTime)createdBefore)
                                              : Date(createdBefore.ToString());

            if (createdAfter != null)
                getParams["created_after"] = (createdAfter is DateTime)
                                           ? Date((DateTime)createdAfter)
                                           : Date(createdAfter.ToString());

            var response = RequestJson(
                               client: client,
                               path: PATH,
                               getParams: getParams);

            if (response.Count == 0
                || !response.ContainsKey("document_collection")
                || !((IDictionary<string, object>)response["document_collection"]).
                ContainsKey("entries"))
            {
                Error(INVALID_RESPONSE_ERROR, "response is not in a valid format.");
            }

            var collection = (IDictionary<string, object>)response["document_collection"];
            var entries = (ArrayList)collection["entries"];

            var documents = new List<Document>();

            foreach (var entry in entries)
            {
                documents.Add(new Document(client, (IDictionary<string, object>)entry));
            }

            return documents;
        }
예제 #9
0
 /// <summary>
 /// Send a new request to the API and return a key-value pair.
 /// </summary>
 /// <param name="client">The client instance to make requests from.</param>
 /// <param name="path">The path to make a request to.</param>
 /// <param name="getParams">A key-value pair of GET params to be added to the URL.</param>
 /// <param name="postParams">A key-value pair of POST params to be sent in the body.</param>
 /// <param name="requestOptions">
 /// A key-value pair of request options that may modify the way the request is  made.
 /// </param>
 /// <returns>The response is pass-thru from Request.</returns>
 /// <exception cref="BoxViewException"></exception>
 protected static IDictionary<string, object> RequestJson(
     BoxViewClient client,
     string path,
     IDictionary<string, string> getParams = null,
     IDictionary<string, string> postParams = null,
     IDictionary<string, object> requestOptions = null)
 {
     return client.RequestHandler.RequestJson(
         path: path,
         getParams: getParams,
         postParams: postParams,
         requestOptions: requestOptions);
 }
예제 #10
0
        /// <summary>
        /// Create a session for a specific document by ID that may expire.
        /// </summary>
        /// <param name="client">The client instance to make requests from.</param>
        /// <param name="id">The ID of the file to create a session for.</param>
        /// <param name="duration">The number of minutes for the session to last.</param>
        /// <param name="expiresAt">When the session should expire.</param>
        /// <param name="isDownloadable">Should the user be allowed to download the original file</param>
        /// <param name="isTextSelectable">Should the user be allowed to select text?</param>
        /// <returns>A new session instance.</returns>
        /// <exception cref="BoxViewException"></exception>
        public static Session Create(
            BoxViewClient client,
            string id,
            int? duration = null,
            object expiresAt = null,
            bool? isDownloadable = null,
            bool? isTextSelectable = null)
        {
            var postParams = new Dictionary<string, string>();
            postParams["document_id"] = id;

            if (duration != null && duration > 0)
                postParams["duration"] = duration.ToString();

            if (expiresAt != null)
                postParams["expires_at"] = (expiresAt is DateTime)
                                           ? Date((DateTime)expiresAt)
                                           : Date(expiresAt.ToString());

            if (isDownloadable != null)
                postParams["is_downloadable"] = isDownloadable.Equals(true) ? "1" : "0";

            if (isTextSelectable != null)
                postParams["is_text_selectable"] = isTextSelectable.Equals(true) ? "1" : "0";

            var metadata = RequestJson(
                               client: client,
                               path: PATH,
                               postParams: postParams);
            return new Session(client, metadata);
        }
예제 #11
0
        public static void Main()
        {
            BoxView = new BoxViewClient(API_KEY);

            Example1();
            Example2();
            Example3();
            Example4();
            Example5();
            Example6();
            Example7();
            Example8();
            Example9();
            Example10();
            Example11();
            Example12();
            Example13();
            Example14();
            Example15();
            Example16();
            Example17();
        }