public IRequest SetProfile(string member_id = null, string external_id = null, string new_email = null,
            string new_external_id = null)
        {
            if (member_id != null && external_id != null)
                throw new ArgumentException("Must specify either a member_id or external_id.");
            if (new_email != null && new_external_id != null)
                throw new ArgumentException("Must specify either a new_email or new_external_id.");

            var request = new Request
                {
                    Method = HttpMethod.Post,
                    BaseAddress = Consts.ApiBaseUrl,
                    Resource = Consts.Version + "/team/members/set_profile"
                };

            var content = new JObject();

            if (member_id != null)
                content["member_id"] = member_id;
            else if (external_id != null)
                content["external_id"] = external_id;
            if (new_email != null)
                content["new_email"] = new_email;
            else if (new_external_id != null)
                content["new_external_id"] = new_external_id;

            request.Content = new JsonContent(content);
            request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            return request;
        }
        public IRequest AccountInfo(string locale = null, string asTeamMember = null)
        {
            var request = new Request
                {
                    Method = HttpMethod.Get,
                    BaseAddress = Consts.ApiBaseUrl,
                    Resource = Consts.Version + "/account/info"
                };
            request.AddHeader(Consts.AsTeamMemberHeader, asTeamMember);
            request.AddParameter("locale", locale);

            return request;
        }
        public IRequest ListAsync()
        {
            var request = new Request
                {
                    Method = HttpMethod.Post,
                    BaseAddress = Consts.ApiBaseUrl,
                    Resource = Consts.Version + "/team/groups/list"
                };
            request.Content = new JsonContent(new { });
            request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            return request;
        }
        public IRequest GetInfoAsync(IEnumerable<string> group_ids)
        {
            var request = new Request
                {
                    Method = HttpMethod.Post,
                    BaseAddress = Consts.ApiBaseUrl,
                    Resource = Consts.Version + "/team/groups/get_info"
                };
            request.Content = new JsonContent(new { group_ids });
            request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            return request;
        }
        public IRequest Files(string root, string path, string rev = null, string asTeamMember = null)
        {
            var request = new Request
                {
                    BaseAddress = Consts.ApiContentBaseUrl,
                    Resource = Consts.Version + "/files/" + root + path.EncodePathParts(),
                    Method = HttpMethod.Head
                };
            request.AddHeader(Consts.AsTeamMemberHeader, asTeamMember);

            if (!string.IsNullOrEmpty(rev))
                request.AddParameter("rev", rev);

            return request;
        }
        public IRequest Delete(string root, string path, string locale = null, string asTeamMember = null)
        {
            var request = new Request
                {
                    Method = HttpMethod.Post,
                    BaseAddress = Consts.ApiBaseUrl,
                    Resource = Consts.Version + "/fileops/delete"
                };
            request.AddHeader(Consts.AsTeamMemberHeader, asTeamMember);

            request.AddParameter("root", root);
            request.AddParameter("path", path);
            request.AddParameter("locale", locale);

            return request;
        }
Ejemplo n.º 7
0
        public IRequest AccessToken(string clientId, string clientSecret, string callbackUrl, string authorizationCode)
        {
            var request = new Request
                {
                    Method = HttpMethod.Post,
                    BaseAddress = Consts.ApiBaseUrl,
                    Resource = Consts.Version + "/oauth2/token"
                };

            request.AddParameter("code", authorizationCode);
            request.AddParameter("grant_type", "authorization_code");
            request.AddParameter("client_id", clientId);
            request.AddParameter("client_secret", clientSecret);
            request.AddParameter("redirect_uri", callbackUrl);

            return request;
        }
        public IRequest ChunkedUpload(byte[] content, int count, string uploadId = null, long? offset = null, string asTeamMember = null)
        {
            var request = new Request
                {
                    BaseAddress = Consts.ApiContentBaseUrl,
                    Resource = Consts.Version + "/chunked_upload/",
                    Method = HttpMethod.Put
                };
            request.AddHeader(Consts.AsTeamMemberHeader, asTeamMember);

            request.AddParameter("upload_id", uploadId);
            if (offset != null)
                request.AddParameter("offset", offset.ToString());

            HttpContent httpContent = new ByteArrayContent(content, 0, count);
            request.Content = httpContent;

            return request;
        }
        public IRequest GetEvents(int limit = 1000, string cursor = null, string member_id = null, string user_id = null, string user_email = null, string category = null,
            DateTime? start_ts = null, DateTime? end_ts = null)
        {
            if (member_id != null && (user_id != null || user_email != null))
                throw new ArgumentException("Exactly one of member_id, user_id, and user_email must be set.", "member_id");
            if (user_id != null && (member_id != null || user_email != null))
                throw new ArgumentException("Exactly one of member_id, user_id, and user_email must be set.", "user_id");
            if (user_email != null && (user_id != null || member_id != null))
                throw new ArgumentException("Exactly one of member_id, user_id, and user_email must be set.", "user_email");

            var request = new Request
                {
                    Method = HttpMethod.Post,
                    BaseAddress = Consts.ApiBaseUrl,
                    Resource = Consts.Version + "/team/members/set_profile"
                };

            var content = new JObject();

            if (limit != 1000)
                content["limit"] = limit;
            if (cursor != null)
                content["cursor"] = cursor;
            if (category != null)
                content["category"] = category;
            if (start_ts != null)
                content["start_ts"] = ToUnixTime(start_ts.Value.ToUniversalTime());
            if (end_ts != null)
                content["end_ts"] = ToUnixTime(end_ts.Value.ToUniversalTime());

            content["user"] = new JObject();
            if (member_id != null)
                content["user"]["member_id"] = member_id;
            else if (user_id != null)
                content["user"]["user_id"] = user_id;
            else if (user_email != null)
                content["user"]["email"] = user_email;

            request.Content = new JsonContent(content);
            request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            return request;
        }
        public IRequest CommitChunkedUpload(string root, string path, string uploadId, string locale = null, bool overwrite = true,
            string parent_rev = null, bool autorename = true, string asTeamMember = null)
        {
            var request = new Request
                {
                    BaseAddress = Consts.ApiContentBaseUrl,
                    Resource = Consts.Version + "/commit_chunked_upload/" + root + path.EncodePathParts(),
                    Method = HttpMethod.Post
                };
            request.AddHeader(Consts.AsTeamMemberHeader, asTeamMember);

            request.AddParameter("upload_id", uploadId);
            request.AddParameter("locale", locale);
            request.AddParameter("overwrite", overwrite.ToString());
            request.AddParameter("parent_rev", parent_rev);
            if (!autorename)
                request.AddParameter("autorename", false.ToString());

            return request;
        }
Ejemplo n.º 11
0
        public IRequest Authorize(string response_type, string client_id, string redirect_uri, string state = null, bool force_reapprove = false, bool disable_signup = false)
        {
            var request = new Request
            {
                Method = HttpMethod.Get,
                BaseAddress = Consts.ApiBaseUrl,
                Resource = Consts.Version + "/oauth2/authorize"
            };

            request.AddParameter("response_type", response_type);
            request.AddParameter("client_id", client_id);
            request.AddParameter("redirect_uri", redirect_uri);
            request.AddParameter("state", state);
            if (force_reapprove)
                request.AddParameter("force_reapprove", true.ToString());
            if (disable_signup)
                request.AddParameter("disable_signup", true.ToString());

            return request;
        }
        public IRequest GetMembership(DateTime? start_date, DateTime? end_date)
        {
            var request = new Request
                {
                    Method = HttpMethod.Post,
                    BaseAddress = Consts.ApiBaseUrl,
                    Resource = Consts.Version + "/team/reports/get_membership"
                };

            var content = new JObject();

            if (start_date != null)
                content["start_date"] = start_date.Value.ToUniversalTime().ToString("yyyy-MM-dd");
            if (end_date != null)
                content["end_date"] = end_date.Value.ToUniversalTime().ToString("yyyy-MM-dd");
            request.Content = new JsonContent(content);
            request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            return request;
        }
        public IRequest Copy(string root, string from_path, string to_path, string from_copy_ref = null, string locale = null, string asTeamMember = null)
        {
            if (from_path != null && from_copy_ref != null)
                throw new ArgumentException("Must specify either a from_path or from_copy_ref.");

            var request = new Request
                {
                    Method = HttpMethod.Post,
                    BaseAddress = Consts.ApiBaseUrl,
                    Resource = Consts.Version + "/fileops/copy"
                };
            request.AddHeader(Consts.AsTeamMemberHeader, asTeamMember);

            request.AddParameter("root", root);
            request.AddParameter("from_path", from_path);
            request.AddParameter("to_path", to_path);
            request.AddParameter("from_copy_ref", from_copy_ref);
            request.AddParameter("locale", locale);

            return request;
        }
        public IRequest FilesRange(string root, string path, long @from, long to, string etag, string rev = null, string asTeamMember = null)
        {
            var request = new Request
                {
                    BaseAddress = Consts.ApiContentBaseUrl,
                    Resource = Consts.Version + "/files/" + root + path.EncodePathParts(),
                    Method = HttpMethod.Get
                };
            request.AddHeader(Consts.AsTeamMemberHeader, asTeamMember);

            if (to < 0)
                to = 0;

            request.AddHeader("Range", string.Format("bytes={0}-{1}", from, to));
            request.AddHeader("ETag", etag);

            if (!string.IsNullOrEmpty(rev))
                request.AddParameter("rev", rev);

            return request;
        }
        public IRequest GetMembers(int limit = 1000, string cursor = null)
        {
            var request = new Request
                {
                    Method = HttpMethod.Post,
                    BaseAddress = Consts.ApiBaseUrl,
                    Resource = Consts.Version + "/team/members/list"
                };

            var content = new JObject();

            if (limit != 1000)
                content["limit"] = limit;
            if (cursor != null)
                content["cursor"] = cursor;

            request.Content = new JsonContent(content);
            request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");


            return request;
        }
        public IRequest FilesPut(string root, Stream content, string path, string locale = null, bool overwrite = true, string parent_rev = null, bool autorename = true, string asTeamMember = null)
        {
            var request = new Request
                {
                    BaseAddress = Consts.ApiContentBaseUrl,
                    Resource = Consts.Version + "/files_put/" + root + path.EncodePathParts(),
                    Method = HttpMethod.Put
                };
            request.AddHeader(Consts.AsTeamMemberHeader, asTeamMember);

            request.AddHeader("locale", locale);
            request.AddParameter("parent_rev", parent_rev);
            if (!overwrite)
                request.AddParameter("overwrite", false.ToString());
            if (!autorename)
                request.AddParameter("autorename", false.ToString());

            var httpContent = new StreamContent(content);
            request.Content = httpContent;


            return request;
        }
        public IRequest Add(string member_email, string member_given_name, string member_surname,
            string member_external_id = null, bool? send_welcome_email = null)
        {
            var request = new Request
                {
                    Method = HttpMethod.Post,
                    BaseAddress = Consts.ApiBaseUrl,
                    Resource = Consts.Version + "/team/members/add"
                };

            var content = new
                {
                    member_email,
                    member_given_name,
                    member_surname,
                    member_external_id,
                    send_welcome_email
                };
            request.Content = new JsonContent(content);
            request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            return request;
        }
        public IRequest SaveUrlJob(string jobId, string asTeamMember = null)
        {
            var request = new Request
                {
                    BaseAddress = Consts.ApiBaseUrl,
                    Resource = Consts.Version + "/save_url_job/" + jobId,
                    Method = HttpMethod.Get
                };
            request.AddHeader(Consts.AsTeamMemberHeader, asTeamMember);

            return request;
        }
        public IRequest LongPollDelta(string cursor = null, int timeout = 30, string asTeamMember = null)
        {
            var request = new Request
                {
                    BaseAddress = Consts.ApiNotifyBaseUrl,
                    Resource = Consts.Version + "/longpoll_delta",
                    Method = HttpMethod.Get
                };
            request.AddHeader(Consts.AsTeamMemberHeader, asTeamMember);

            request.AddParameter("cursor", cursor);
            if (timeout != 30)
                request.AddParameter("timeout", timeout.ToString());

            return request;
        }
        public IRequest Previews(string root, string path, string rev = null, string asTeamMember = null)
        {
            var request = new Request
                {
                    BaseAddress = Consts.ApiContentBaseUrl,
                    Resource = Consts.Version + "/previews/" + root + path.EncodePathParts(),
                    Method = HttpMethod.Get
                };
            request.AddHeader(Consts.AsTeamMemberHeader, asTeamMember);

            request.AddParameter("rev", rev);

            return request;
        }
        public IRequest Metadata(string root, string path, int file_limit = 10000, string hash = null, bool list = true,
            bool include_deleted = false, string rev = null, string locale = null, bool include_media_info = false,
            bool include_membership = false, string asTeamMember = null)
        {
            var request = new Request
                {
                    Method = HttpMethod.Get,
                    BaseAddress = Consts.ApiBaseUrl,
                    Resource = Consts.Version + "/metadata/" + root + path.EncodePathParts()
                };
            request.AddHeader(Consts.AsTeamMemberHeader, asTeamMember);

            request.AddParameter("hash", hash);
            request.AddParameter("rev", rev);
            request.AddParameter("locale", locale);

            if (file_limit != 10000)
                request.AddParameter("file_limit", file_limit.ToString());
            if (list != true)
                request.AddParameter("list", false.ToString());
            if (include_deleted)
                request.AddParameter("include_deleted", true.ToString());
            if (include_media_info)
                request.AddParameter("include_media_info", true.ToString());
            if (include_membership)
                request.AddParameter("include_membership", true.ToString());

            return request;
        }
        public IRequest CopyRef(string root, string path, string asTeamMember = null)
        {
            var request = new Request
                {
                    BaseAddress = Consts.ApiBaseUrl,
                    Resource = Consts.Version + "/copy_ref/" + root + path.EncodePathParts(),
                    Method = HttpMethod.Get
                };
            request.AddHeader(Consts.AsTeamMemberHeader, asTeamMember);

            return request;
        }
        public IRequest Delta(string cursor = null, string locale = null, string path_prefix = null, bool include_media_info = false,
            string asTeamMember = null)
        {
            var request = new Request
                {
                    BaseAddress = Consts.ApiBaseUrl,
                    Resource = Consts.Version + "/delta",
                    Method = HttpMethod.Post
                };
            request.AddHeader(Consts.AsTeamMemberHeader, asTeamMember);

            request.AddParameter("cursor", cursor);
            request.AddHeader("locale", locale);
            request.AddParameter("path_prefix", path_prefix);
            if (include_media_info)
                request.AddParameter("include_media_info", true.ToString());

            return request;
        }
        public IRequest Revisions(string root, string path, int rev_limit = 10, string locale = null, string asTeamMember = null)
        {
            var request = new Request
                {
                    BaseAddress = Consts.ApiBaseUrl,
                    Resource = Consts.Version + "/revisions/" + root + path.EncodePathParts(),
                    Method = HttpMethod.Get
                };
            request.AddHeader(Consts.AsTeamMemberHeader, asTeamMember);

            request.AddParameter("locale", locale);
            if (rev_limit != 10)
                request.AddParameter("rev_limit", rev_limit.ToString());

            return request;
        }
        public IRequest Restore(string root, string path, string rev = null, string locale = null, string asTeamMember = null)
        {
            var request = new Request
                {
                    BaseAddress = Consts.ApiBaseUrl,
                    Resource = Consts.Version + "/restore/" + root + path.EncodePathParts(),
                    Method = HttpMethod.Post
                };
            request.AddHeader(Consts.AsTeamMemberHeader, asTeamMember);

            request.AddParameter("rev", rev);
            request.AddParameter("locale", locale);

            return request;
        }
        public IRequest Thumbnails(string root, string path, string format = "jpeg", string size = "s", string asTeamMember = null)
        {
            var request = new Request
                {
                    BaseAddress = Consts.ApiContentBaseUrl,
                    Resource = Consts.Version + "/thumbnails/" + root + path.EncodePathParts(),
                    Method = HttpMethod.Get
                };
            request.AddHeader(Consts.AsTeamMemberHeader, asTeamMember);

            request.AddParameter("format", format);
            request.AddParameter("size", size);

            return request;
        }
        public IRequest Shares(string root, string path, string locale = null, bool short_url = true, string asTeamMember = null)
        {
            var request = new Request
                {
                    BaseAddress = Consts.ApiBaseUrl,
                    Resource = Consts.Version + "/shares/" + root + path.EncodePathParts(),
                    Method = HttpMethod.Post
                };
            request.AddHeader(Consts.AsTeamMemberHeader, asTeamMember);

            request.AddParameter("locale", locale);
            if (!short_url)
                request.AddParameter("short_url", false.ToString());

            return request;
        }
        public IRequest SharedFolders(string id = null, string asTeamMember = null)
        {
            var request = new Request
                {
                    BaseAddress = Consts.ApiBaseUrl,
                    Resource = Consts.Version + "/shared_folders/" + id,
                    Method = HttpMethod.Get
                };
            request.AddHeader(Consts.AsTeamMemberHeader, asTeamMember);

            return request;
        }
        public IRequest Search(string root, string path, string query, int file_limit = 1000, bool include_deleted = false,
            string locale = null, bool include_membership = false, string asTeamMember = null)
        {
            var request = new Request
                {
                    BaseAddress = Consts.ApiBaseUrl,
                    Resource = Consts.Version + "/search/" + root + path.EncodePathParts(),
                    Method = HttpMethod.Get
                };
            request.AddHeader(Consts.AsTeamMemberHeader, asTeamMember);

            request.AddParameter("query", query);
            request.AddParameter("locale", locale);
            if (include_deleted)
                request.AddParameter("include_deleted", true.ToString());
            if (include_membership)
                request.AddParameter("include_membership", true.ToString());
            if (file_limit != 1000)
                request.AddParameter("file_limit", file_limit.ToString());

            return request;
        }
        public IRequest SaveUrl(string root, string path, string url, string asTeamMember = null)
        {
            var request = new Request
                {
                    BaseAddress = Consts.ApiBaseUrl,
                    Resource = Consts.Version + "/save_url/" + root + path.EncodePathParts(),
                    Method = HttpMethod.Post
                };
            request.AddParameter("url", url);
            request.AddHeader(Consts.AsTeamMemberHeader, asTeamMember);

            return request;
        }