Exemplo n.º 1
0
        public bool Login(string email, string password)
        {
            Http http = new Http("get");
            http.Url = new Uri("https://api.dropbox.com/0/token");

            http.Parameters.Add(new HttpParameter { Name = "oauth_consumer_key", Value = _apiKey });

            http.Parameters.Add(new HttpParameter { Name = "email", Value = email });
            http.Parameters.Add(new HttpParameter { Name = "password", Value = password });

            //add oauth
            OAuthAuthenticator oAuth = new OAuthAuthenticator(http.Url.ToString(), _apiKey, _appsecret, "", "");
            oAuth.Authenticate(http);

            try
            {
                http.Get();

                if (http.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    //Wrong Username/Password
                    throw new DropException("Incorrect Username/Password.");
                }

                BytesRecieved += http.Response.Content.Length;

                JsonDeserializer deserializer = new JsonDeserializer();

                UserLogin = deserializer.Deserialize<UserLogin>(http.Response.Content);

                if (!string.IsNullOrEmpty(UserLogin.Error))
                {
                    //Some sort of dropbox error
                    throw new DropException(UserLogin.Error);
                }

                LoggedIn = true;

                return LoggedIn;
            }
            catch (DropException dx)
            {
                throw dx;
            }
            catch (Exception ex)
            {
                return false;
            }

        }
Exemplo n.º 2
0
        public AccountInfo GetAccountInfo()
        {
            if (_accountInfo != null)
            {
                var lastDiff = DateTime.Now - _lastAccountInfo;
                //May need Tweeking
                if (lastDiff.TotalSeconds < 100) return _accountInfo;
            }

            Http http = new Http("get");
            http.Url = new Uri("https://api.dropbox.com/0/account/info");

            OAuthAuthenticator oAuth = new OAuthAuthenticator(http.Url.ToString(), _apiKey, _appsecret, UserLogin.Token, UserLogin.Secret);

            oAuth.Authenticate(http);

            try
            {
                http.Get();

                BytesRecieved += http.Response.Content.Length;

                JsonDeserializer deserializer = new JsonDeserializer();

                _accountInfo = deserializer.Deserialize<AccountInfo>(http.Response.Content);

                return _accountInfo;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
Exemplo n.º 3
0
        public MetaData CreateFolder(MetaData parent, string folderName)
        {
            Http http = new Http("get");
            http.Url = new Uri("https://api.dropbox.com/0/fileops/create_folder");

            OAuthAuthenticator oAuth = new OAuthAuthenticator(http.Url.ToString(), _apiKey, _appsecret, UserLogin.Token, UserLogin.Secret);

            http.Parameters.Add(new HttpParameter { Name = "path", Value = string.Format("{0}/{1}", parent.Path, folderName) });
            http.Parameters.Add(new HttpParameter { Name = "root", Value = "dropbox" });

            oAuth.Authenticate(http);

            try
            {
                http.Get();

                BytesRecieved += http.Response.Content.Length;

                JsonDeserializer deserializer = new JsonDeserializer();

                var returnMeta = deserializer.Deserialize<MetaData>(http.Response.Content);

                if (string.IsNullOrEmpty(returnMeta.error))
                {
                    if (returnMeta.Contents == null) returnMeta.Contents = new List<MetaData>();
                    return returnMeta;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }
Exemplo n.º 4
0
        public bool MoveFile(MetaData fromFile, MetaData toDir)
        {
            Http http = new Http("get");
            http.Url = new Uri("https://api.dropbox.com/0/fileops/move");

            OAuthAuthenticator oAuth = new OAuthAuthenticator(http.Url.ToString(), _apiKey, _appsecret, UserLogin.Token, UserLogin.Secret);

            http.Parameters.Add(new HttpParameter { Name = "root", Value = "dropbox" });
            http.Parameters.Add(new HttpParameter { Name = "from_path", Value = fromFile.Path });
            http.Parameters.Add(new HttpParameter { Name = "to_path", Value = string.Format("{0}/{1}", toDir.Path, fromFile.Name) });

            oAuth.Authenticate(http);

            try
            {
                http.Get();

                BytesRecieved += http.Response.Content.Length;

                return http.Response.StatusCode == HttpStatusCode.OK;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
Exemplo n.º 5
0
        public bool Delete(MetaData remoteFile)
        {
            Http http = new Http("get");
            http.Url = new Uri("https://api.dropbox.com/0/fileops/delete");

            OAuthAuthenticator oAuth = new OAuthAuthenticator(http.Url.ToString(), _apiKey, _appsecret, UserLogin.Token, UserLogin.Secret);

            http.Parameters.Add(new HttpParameter { Name = "path", Value = remoteFile.Path });
            http.Parameters.Add(new HttpParameter { Name = "root", Value = "dropbox" });

            oAuth.Authenticate(http);

            try
            {
                http.Get();

                BytesRecieved += http.Response.Content.Length;

                return http.Response.StatusCode == HttpStatusCode.OK;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
Exemplo n.º 6
0
        public MetaData GetItems(MetaData remoteDir)
        {
            Http http = new Http("get");
            http.Url = new Uri("https://api.dropbox.com/0/metadata/dropbox" + remoteDir.Path);

            OAuthAuthenticator oAuth = new OAuthAuthenticator(http.Url.ToString(), _apiKey, _appsecret, UserLogin.Token, UserLogin.Secret);

            oAuth.Authenticate(http);

            try
            {
                http.Get();

                BytesRecieved += http.Response.Content.Length;

                JsonDeserializer deserializer = new JsonDeserializer();

                var returnMeta = deserializer.Deserialize<MetaData>(http.Response.Content);

                if (string.IsNullOrEmpty(returnMeta.error))
                {
                    if (returnMeta.Contents == null) returnMeta.Contents = new List<MetaData>();
                    return returnMeta;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }