Example #1
0
        //Create a Drive
        public async Task <OHDrive> Create(string name, long size, OHDriveOptions driveOptions = null)
        {
            string json      = "";
            var    driveDict = new Dictionary <string, string>();

            //name and size are required
            if (string.IsNullOrEmpty(name) || size == 0)
            {
                throw new Exception("Name and Size are required for drive creation");
            }

            driveDict["name"] = name;
            driveDict["size"] = size.ToString();
            if (driveOptions != null)
            {
                driveDict = SetDriveOptions(driveDict, driveOptions, false);
            }

            json = JsonConvert.SerializeObject(driveDict);
            var content = new StringContent(json, UnicodeEncoding.UTF8, "application/json");

            using (HttpClient client = OHUtilities.CreateClient(userID, secretKey))
            {
                var url      = urlBase + "create";
                var response = await client.PostAsync(url, content);

                json = await response.Content.ReadAsStringAsync();
            }

            return(DeserializeDrive(json));
        }
Example #2
0
        //Return a List of Drives
        public async Task <List <OHDrive> > GetAll()
        {
            string         json   = "";
            List <OHDrive> drives = new List <OHDrive>();

            using (HttpClient client = OHUtilities.CreateClient(userID, secretKey))
            {
                var url      = urlBase + "list";
                var response = await client.GetAsync(url);

                json = await response.Content.ReadAsStringAsync();
            }

            dynamic driveList = JsonConvert.DeserializeObject(json);

            foreach (var drive in driveList)
            {
                string driveId  = drive.uuid;
                var    response = await Get(driveId);

                drives.Add(response);
            }

            return(drives);
        }
Example #3
0
        //Return a Drive
        public async Task <OHDrive> Get(string driveID)
        {
            string json = "";

            using (HttpClient client = OHUtilities.CreateClient(userID, secretKey))
            {
                var url      = string.Format("{0}{1}/info/full", urlBase, driveID);
                var response = await client.GetAsync(url);

                json = await response.Content.ReadAsStringAsync();
            }

            return(DeserializeDrive(json));
        }
Example #4
0
        //Delete a Drive
        public async Task <bool> Destroy(string driveID)
        {
            HttpResponseMessage response;

            using (HttpClient client = OHUtilities.CreateClient(userID, secretKey))
            {
                var url = string.Format("{0}{1}/destroy", urlBase, driveID);
                response = await client.PostAsync(url, null);
            }

            if (response.StatusCode == HttpStatusCode.NoContent)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }