コード例 #1
0
ファイル: Security.cs プロジェクト: JPaulDuncan/Scribd.Net
        /// <summary>
        /// This method allows you to disable a user's access to a secure document, 
        /// or to re-enable it after a previous call. It is not necessary to grant 
        /// initial access to a document - that is done through the embed code.
        /// </summary>
        /// <param name="allowed">Disables or enables access to the given document identifier.</param>
        /// <param name="documentId">The document identifier.</param>
        /// <returns></returns>
        public static bool SetAccess(bool allowed, int documentId)
        {
            bool _result = false;
            // Set up our request
            using (Request _request = new Request())
            {
                _request.MethodName = "security.setAccess";
                _request.Parameters.Add("user_identifier", Service.User.UserName);
                _request.Parameters.Add("allowed", allowed ? "1" : "0");
                if (documentId > 0) { _request.Parameters.Add("doc_id", documentId.ToString()); }

                // Grab our response
                using (Response _response = Service.Instance.PostRequest(_request))
                {
                    // Parse the response
                    if (_response != null && _response.HasChildNodes && _response.ErrorList.Count < 1)
                    {
                        _result = true;
                    }
                }
            }

            return _result;
        }
コード例 #2
0
ファイル: Search.cs プロジェクト: JPaulDuncan/Scribd.Net
        /// <summary>
        /// This method searches for the specified query within the scribd documents
        /// </summary>
        /// <param name="query">Criteria used in search</param>
        /// <param name="scope">Whether to search all of scribd OR just within one 
        /// user/'s documents. If scope is set to "user" and session_key is not provided, 
        /// the documents uploaded by the API user will be searched. If scope is set 
        /// to "user" and session_key is given, the documents uploaded by the session 
        /// user will be searched. If scope is "all", only public documents will be 
        /// searched. Set to "user" by default.</param>
        /// <param name="maxResults">Number of results to return: Default 10, max 1000</param>
        /// <param name="startIndex">Number to start at: Default 1. Cannot exceed 1000</param>
        /// <returns>The <see cref="T:Search.Result"/></returns>
        internal static Result InnerFind(string query, SearchScope scope, int maxResults, int startIndex)
        {
            if (Search.ThumbnailSize == null) { Search.ThumbnailSize = new System.Drawing.Size(71, 100); }

            // Validate params
            if (maxResults > 1000) { maxResults = 1000; }
            if (startIndex < 1 || startIndex > 1000) { startIndex = 1; }

            List<Document> _documents = new List<Document>();
            int _totalAvailable = 0, _firstResultIndex = 0;

            // Generate request
            using (Request _request = new Request(Service.Instance.InternalUser))
            {
                _request.MethodName = "docs.search";
                _request.Parameters.Add("query", query);
                _request.Parameters.Add("num_results", maxResults.ToString());
                _request.Parameters.Add("num_start", startIndex.ToString());
                _request.Parameters.Add("scope", Enum.GetName(typeof(SearchScope),scope).ToLower());

                // Get Results
                using (Response _response = Service.Instance.PostRequest(_request))
                {
                    // Parse response
                    if (_response != null && _response.HasChildNodes && _response.ErrorList.Count < 1)
                    {
                        _totalAvailable = int.Parse(_response.SelectSingleNode(@"/rsp/result_set").Attributes["totalResultsAvailable"].Value);
                        _firstResultIndex = int.Parse(_response.SelectSingleNode(@"/rsp/result_set").Attributes["firstResultPosition"].Value);

                        XmlNodeList _list = _response.GetElementsByTagName("result");
                        if (_list.Count > 0)
                        {
                            foreach (XmlNode _node in _list)
                            {
                                Document _item = new Document(0, Search.ThumbnailSize);
                                _item.DocumentId = int.Parse(_node.SelectSingleNode("doc_id").InnerText);
                                _item.Title = _node.SelectSingleNode("title").InnerText.Trim();
                                _item.Description = _node.SelectSingleNode("description").InnerText.Trim();
                                _item.ThumbnailUrl = new Uri(_node.SelectSingleNode("thumbnail_url").InnerText);

                                if (_node.SelectSingleNode("access_key") != null)
                                {
                                    _item.AccessKey = _node.SelectSingleNode("access_key").InnerText;
                                }

                                // Tags
                                string _tags = _node.SelectSingleNode("tags").InnerText;
                                foreach (string _tag in _tags.Split(','))
                                {
                                    _item.TagList.Add(_tag.Trim());
                                }

                                _documents.Add(_item);
                            }
                        }
                    }
                }
            }

            // Set the criteria used to the result
            Criteria _criteria = new Criteria();
            _criteria.Query = query;
            _criteria.Scope = scope;
            _criteria.MaxResults = maxResults;
            _criteria.StartIndex = startIndex;

            return new Result(_criteria, _documents, _totalAvailable, _firstResultIndex);
        }
コード例 #3
0
ファイル: Collection.cs プロジェクト: JPaulDuncan/Scribd.Net
        /// <summary>
        /// This method retrieves a list of scribd 'Collections' associated with the user.
        /// </summary>
        /// <param name="user">if null then the current user is assumed</param>
        /// <param name="scope"></param>
        /// <returns></returns>
        public static ICollection<Collection> GetCollections(User user, Scope scope)
        {
            ICollection<Collection> _result = new List<Collection>();

            // Build the request
            using (Request _request = new Request(user, true))
            {
                _request.MethodName = "docs.getCollections";

                if (scope == Scope.Public)
                {
                    _request.Parameters.Add("scope", "public");
                }
                else if (scope == Scope.Private)
                {
                    _request.Parameters.Add("scope", "private");
                }

                // Get the response
                using (Response _response = Service.Instance.PostRequest(_request))
                {
                    // Parse the response
                    if (_response != null && _response.HasChildNodes && _response.ErrorList.Count < 1)
                    {
                        XmlNodeList _list = _response.GetElementsByTagName("result");
                        if (_list.Count > 0)
                        {
                            foreach (XmlNode _node in _list)
                            {
                                // this call to Parse will recurse into any subcategories
                                Collection col = Collection.Parse(_node, null);
                                _result.Add(col);
                            }
                        }
                    }
                }
            }

            return _result;
        }
コード例 #4
0
ファイル: User.cs プロジェクト: JPaulDuncan/Scribd.Net
        /// <summary>
        /// This method returns a URL that, when visited, will automatically sign in the 
        /// current user and then redirect to the URL you provide.
        /// </summary>
        /// <param name="nextUrl">The URL or path portion of a Scribd URL to redirect to.</param>
        /// <returns>The auto-signin URL.</returns>
        public static string GetAutoSigninUrl(string nextUrl)
        {
            string _result = nextUrl;
            // Set up our request
            using (Request _request = new Request())
            {
                _request.MethodName = "user.getAutoSigninUrl";
                _request.Parameters.Add("next_url", nextUrl);

                // Grab our response
                using (Response _response = Service.Instance.PostRequest(_request))
                {

                    // Parse the response
                    if (_response != null && _response.HasChildNodes && _response.ErrorList.Count < 1)
                    {
                        XmlNode _node = _response.SelectSingleNode("rsp");

                        // Data
                        _result = _node.SelectSingleNode("url").InnerText;
                    }
                }
            }

            return _result;
        }
コード例 #5
0
ファイル: User.cs プロジェクト: JPaulDuncan/Scribd.Net
        /// <summary>
        /// Signs a user up for Scribd.  Doing so will log the 
        /// current user profile out and replace it with this one.
        /// </summary>
        /// <param name="userName">Username to associate with your Scribd account</param>
        /// <param name="password">Password to associate with your Scribd account</param>
        /// <param name="email">Your email address</param>
        /// <param name="name">Your real name</param>
        /// <returns>True on success</returns>
        public static bool Signup(string userName, string password, string email, string name)
        {
            UserEventArgs _args = new UserEventArgs();
            if (BeforeSignUp != null)
            {
                _args.Success = false;
                _args.User.UserName = userName;
                _args.User.Name = name;
            }

            if (!_args.Cancel)
            {
                using (Request _request = new Request())
                {
                    _request.MethodName = "user.signup";
                    _request.Parameters.Add("username", userName);
                    _request.Parameters.Add("password", password);
                    _request.Parameters.Add("email", email);
                    _request.Parameters.Add("name", name);

                    User cachedUser = Service.Instance.InternalUser;
                    Service.Instance.InternalUser = null;

                    using (Response _response = Service.Instance.PostRequest(_request))
                    {
                        Service.Instance.InternalUser = cachedUser;

                        // Parse response
                        User _result = new User();
                        if (_response != null && _response.HasChildNodes && _response.ErrorList.Count < 1)
                        {
                            XmlNodeList _list = _response.GetElementsByTagName("rsp");
                            if (_list.Count > 0)
                            {
                                foreach (XmlNode _node in _list)
                                {
                                    _result.Name = _node.SelectSingleNode("name").InnerText.Trim();
                                    _result.SessionKey = _node.SelectSingleNode("session_key").InnerText.Trim();
                                    _result.UserId = int.Parse(_node.SelectSingleNode("user_id").InnerText.Trim());
                                    _result.UserName = _node.SelectSingleNode("username").InnerText.Trim();
                                    _result.m_isLoggedIn = true;

                                    // Notify subscribers of sign-up success.
                                    _args.Success = true;
                                    _args.User = _result;
                                    if (User.AfterSignUp != null)
                                    {
                                        User.AfterSignUp(null, _args);
                                    }

                                    return true;
                                }
                            }
                        }
                    }
                }
            }

            _args.Success = false;
            if (User.AfterSignUp != null)
            {
                User.AfterSignUp(null, _args);
            }

            return false;
        }
コード例 #6
0
ファイル: User.cs プロジェクト: JPaulDuncan/Scribd.Net
        /// <summary>
        /// Logs a user into the service.
        /// </summary>
        /// <param name="userName">Username associated with your Scribd account</param>
        /// <param name="password">Password associated with your Scribd account</param>
        /// <param name="verifyOnly">Just verifying credentials, don't change state of 'logged in' user</param>
        /// <param name="newUser">(out) Can be used by called to get the newly created User</param>
        /// <returns>True on success</returns>
        private static bool _Login(string userName, string password, bool verifyOnly, out User newUser)
        {
            UserEventArgs _args = new UserEventArgs();
            if (BeforeLogin != null)
            {
                _args.Success = false;
                _args.User.UserName = userName;
            }

            newUser = null;

            if (!_args.Cancel)
            {
                using (Request _request = new Request())
                {
                    _request.MethodName = "user.login";
                    _request.Parameters.Add("username", userName);
                    _request.Parameters.Add("password", password);

                    using (Response _response = Service.Instance.PostRequest(_request))
                    {
                        // Parse response
                        User _result = new User();
                        if (_response != null && _response.HasChildNodes && _response.ErrorList.Count < 1)
                        {
                            XmlNodeList _list = _response.GetElementsByTagName("rsp");
                            if (_list.Count > 0)
                            {
                                foreach (XmlNode _node in _list)
                                {
                                    _result.Name = _node.SelectSingleNode("name").InnerText.Trim();
                                    _result.SessionKey = _node.SelectSingleNode("session_key").InnerText.Trim();
                                    _result.UserId = int.Parse(_node.SelectSingleNode("user_id").InnerText.Trim());
                                    _result.UserName = _node.SelectSingleNode("username").InnerText.Trim();
                                    _result.m_isLoggedIn = true;

                                    newUser = _result;

                                    _args.Success = true;
                                    _args.User = _result;

                                    if (!verifyOnly)
                                    {
                                        Service.Instance.InternalUser = _result;
                                        Service.Instance.InternalUser.OnLoggedIn(_args);
                                    }

                                    return true;
                                }
                            }
                        }
                    }
                }
            }

            if (!verifyOnly)
            {
                // ??? It seems wrong to leave any previous 'logged in' user in tact. Code setting 'logged_in' flag to false.
                // but that flag doesn't do anything. Seems like clearing the Service.InternalUser is the right thing to do.
            Service.Instance.InternalUser.m_isLoggedIn = false;
            }

            _args.Success = false;

            // Notify subscribers of failure.
            Service.Instance.InternalUser.OnLoginFailed(_args);

            return false;
        }
コード例 #7
0
ファイル: Security.cs プロジェクト: JPaulDuncan/Scribd.Net
        /// <summary>
        /// This method can be used for tracking and verification purposes. It gets the list 
        /// of the user_identifiers currently authorized to view the given document.
        /// </summary>
        /// <param name="documentId">The document identifier.</param>
        /// <returns></returns>
        public static List<string> GetDocumentAccessList(int documentId)
        {
            List<string> _result = new List<string>();

            // Generate request
            using (Request _request = new Request(Service.Instance.InternalUser))
            {
                _request.MethodName = "security.getDocumentAccessList";
                _request.Parameters.Add("doc_id", documentId.ToString());

                // Get Results
                using (Response _response = Service.Instance.PostRequest(_request))
                {
                    // Parse response
                    if (_response != null && _response.HasChildNodes && _response.ErrorList.Count < 1)
                    {
                        XmlNodeList _list = _response.GetElementsByTagName("result");
                        if (_list.Count > 0)
                        {
                            foreach (XmlNode _node in _list)
                            {
                                string _item = _node.SelectSingleNode("user_identifier").InnerText;
                                _result.Add(_item);
                            }
                        }
                    }
                }
            }

            return _result;
        }
コード例 #8
0
ファイル: Security.cs プロジェクト: JPaulDuncan/Scribd.Net
        /// <summary>
        /// This method can be used for tracking and verification purposes. 
        /// It gets the list of the secure documents that the current user 
        /// is allowed to access.
        /// </summary>
        /// <returns></returns>
        public static List<UserAccessItem> GetUserAccessList()
        {
            List<UserAccessItem> _result = new List<UserAccessItem>();

            // Generate request
            using (Request _request = new Request(Service.Instance.InternalUser))
            {
                _request.MethodName = "security.getUserAccessList";
                _request.Parameters.Add("user_identifier", Service.User.UserName);
                
                // Get Results
                using (Response _response = Service.Instance.PostRequest(_request))
                {
                    // Parse response
                    if (_response != null && _response.HasChildNodes && _response.ErrorList.Count < 1)
                    {
                        XmlNodeList _list = _response.GetElementsByTagName("result");
                        
                        if (_list.Count > 0)
                        {
                            foreach (XmlNode _node in _list)
                            {
                                UserAccessItem _item = new UserAccessItem();
                                _item.DocumentId = int.Parse(_node.SelectSingleNode("doc_id").InnerText);
                                _item.SecretPassword = _node.SelectSingleNode("secret_password").InnerText;
                                _item.AccessKey = _node.SelectSingleNode("access_key").InnerText;
                                _item.Title = _node.SelectSingleNode("title").InnerText.Trim();
                                _item.Description = _node.SelectSingleNode("description").InnerText.Trim();
                                
                                switch (_node.SelectSingleNode("conversion_status").InnerText.Trim().ToLower())
                                {
                                    case "displayable": _item.ConversionStatus = ConversionStatusTypes.Displayable; break;
                                    case "done": _item.ConversionStatus = ConversionStatusTypes.Done; break;
                                    case "error": _item.ConversionStatus = ConversionStatusTypes.Error; break;
                                    case "processing": _item.ConversionStatus = ConversionStatusTypes.Processing; break;
                                    case "published": _item.ConversionStatus = ConversionStatusTypes.Published; break;
                                    default: _item.ConversionStatus = ConversionStatusTypes.None_Specified; break;
                                }

                                _item.PageCount = int.Parse(_node.SelectSingleNode("page_count").InnerText);

                                _result.Add(_item);
                            }
                        }
                    }
                }
            }

            return _result;
        }