예제 #1
0
파일: Copy.cs 프로젝트: ywscr/ShareX
        public string CreatePublicURL(string path, CopyURLType urlType = CopyURLType.Default)
        {
            path = path.Trim('/');

            string url = URLHelpers.CombineURL(URLLinks, URLHelpers.URLEncode(path, true));

            string query = OAuthManager.GenerateQuery(url, null, HttpMethod.POST, AuthInfo);

            CopyLinkRequest publicLink = new CopyLinkRequest();

            publicLink.@public = true;
            publicLink.name    = "ShareX";
            publicLink.paths   = new string[] { path };

            string content = JsonConvert.SerializeObject(publicLink);

            string response = SendRequest(HttpMethod.POST, query, content, headers: APIHeaders);

            if (!string.IsNullOrEmpty(response))
            {
                CopyLinksInfo link = JsonConvert.DeserializeObject <CopyLinksInfo>(response);

                return(GetLinkURL(link, path, urlType));
            }

            return("");
        }
예제 #2
0
파일: Copy.cs 프로젝트: ywscr/ShareX
        // https://developers.copy.com/documentation#api-calls/filesystem - Create File or Directory
        // POST https://api.copy.com/rest/files/PATH/TO/FILE?overwrite=true
        public UploadResult UploadFile(Stream stream, string path, string fileName)
        {
            if (!OAuthInfo.CheckOAuth(AuthInfo))
            {
                Errors.Add("Copy login is required.");
                return(null);
            }

            string url = URLHelpers.CombineURL(URLFiles, URLHelpers.URLEncode(path, true));

            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("overwrite", "true");

            string query = OAuthManager.GenerateQuery(url, args, HttpMethod.POST, AuthInfo);

            // There's a 1GB and 5 hour(max time for a single upload) limit to all uploads through the API.
            UploadResult result = SendRequestFile(query, stream, fileName, "file", headers: APIHeaders);

            if (result.IsSuccess)
            {
                CopyUploadInfo content = JsonConvert.DeserializeObject <CopyUploadInfo>(result.Response);

                if (content != null && content.objects != null && content.objects.Length > 0)
                {
                    AllowReportProgress = false;
                    result.URL          = CreatePublicURL(content.objects[0].path, URLType);
                }
            }

            return(result);
        }
예제 #3
0
        public bool CreateAlbum(string albumID, string albumName)
        {
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("id", albumID);     // Album identifier.
            args.Add("name", albumName); // Name of result. Must be between 2 and 50 characters. Valid characters are letters, numbers, underscore ( _ ), hyphen (-), and space.

            string url   = "http://api.photobucket.com/album/!";
            string query = OAuthManager.GenerateQuery(url, args, HttpMethod.POST, AuthInfo);

            query = FixURL(query);

            string response = SendRequest(HttpMethod.POST, query, args);

            if (!string.IsNullOrEmpty(response))
            {
                XDocument xd = XDocument.Parse(response);
                XElement  xe;

                if ((xe = xd.GetNode("response")) != null)
                {
                    string status = xe.GetElementValue("status");

                    return(!string.IsNullOrEmpty(status) && status == "OK");
                }
            }

            return(false);
        }
예제 #4
0
        public UploadResult TweetMessageWithMedia(string message, Stream stream, string fileName)
        {
            if (message.Length > MessageMediaLimit)
            {
                message = message.Remove(MessageMediaLimit);
            }

            string url   = string.Format("https://api.twitter.com/{0}/statuses/update_with_media.json", APIVersion);
            string query = OAuthManager.GenerateQuery(url, null, HttpMethod.POST, AuthInfo);

            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("status", message);

            UploadResult result = UploadData(stream, query, fileName, "media[]", args);

            if (!string.IsNullOrEmpty(result.Response))
            {
                TwitterStatusResponse status = JsonConvert.DeserializeObject <TwitterStatusResponse>(result.Response);

                if (status != null && status.user != null)
                {
                    result.URL = status.GetTweetURL();
                }
            }

            return(result);
        }
        public DropboxUserLogin Login(string email, string password)
        {
            if (!string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(password))
            {
                Dictionary <string, string> args = new Dictionary <string, string>();
                args.Add("email", email);
                args.Add("password", password);

                string url = OAuthManager.GenerateQuery(URLToken, args, HttpMethod.Get, AuthInfo);

                string response = SendGetRequest(url);

                if (!string.IsNullOrEmpty(response))
                {
                    DropboxUserLogin login = JsonConvert.DeserializeObject <DropboxUserLogin>(response);

                    if (login != null)
                    {
                        AuthInfo.UserToken  = login.Token;
                        AuthInfo.UserSecret = login.Secret;
                        return(login);
                    }
                }
            }

            return(null);
        }
        public override string ShortenURL(string url)
        {
            if (!string.IsNullOrEmpty(url))
            {
                string query;

                switch (UploadMethod)
                {
                default:
                case AccountType.Anonymous:
                    query = string.Format("{0}?key={1}", APIURL, AnonymousKey);
                    break;

                case AccountType.User:
                    query = OAuthManager.GenerateQuery(APIURL, null, HttpMethod.Post, AuthInfo);
                    break;
                }

                string json = string.Format("{{\"longUrl\":\"{0}\"}}", url);

                string response = SendPostRequestJSON(query, json);

                if (!string.IsNullOrEmpty(response))
                {
                    GoogleURLShortenerResponse result = JsonConvert.DeserializeObject <GoogleURLShortenerResponse>(response);
                    if (result != null)
                    {
                        return(result.id);
                    }
                }
            }

            return(null);
        }
예제 #7
0
        private string GetConfiguration()
        {
            string url      = string.Format("https://api.twitter.com/{0}/help/configuration.json", APIVersion);
            string query    = OAuthManager.GenerateQuery(url, null, HttpMethod.GET, AuthInfo);
            string response = SendRequest(HttpMethod.GET, query);

            return(response);
        }
예제 #8
0
        // https://www.dropbox.com/developers/core/api#files-GET
        public bool DownloadFile(string path, Stream downloadStream)
        {
            if (!string.IsNullOrEmpty(path) && OAuthInfo.CheckOAuth(AuthInfo))
            {
                string url   = Helpers.CombineURL(URLFiles, Helpers.URLPathEncode(path));
                string query = OAuthManager.GenerateQuery(url, null, HttpMethod.Get, AuthInfo);
                return(SendGetRequest(downloadStream, query));
            }

            return(false);
        }
예제 #9
0
파일: Copy.cs 프로젝트: ywscr/ShareX
        // https://developers.copy.com/documentation#api-calls/filesystem - Download Raw File Conents
        // GET https://api.copy.com/rest/files/PATH/TO/FILE
        public bool DownloadFile(string path, Stream downloadStream)
        {
            if (!string.IsNullOrEmpty(path) && OAuthInfo.CheckOAuth(AuthInfo))
            {
                string url   = URLHelpers.CombineURL(URLFiles, URLHelpers.URLEncode(path, true));
                string query = OAuthManager.GenerateQuery(url, null, HttpMethod.GET, AuthInfo);
                return(SendRequestDownload(HttpMethod.GET, query, downloadStream));
            }

            return(false);
        }
        public TweetStatus TweetMessage(string message)
        {
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("status", message);

            string query = OAuthManager.GenerateQuery(URLTweet, args, HttpMethod.Post, AuthInfo);

            string response = SendPostRequest(query);

            return(ParseTweetResponse(response));
        }
예제 #11
0
        private UploadResult UserUpload(Stream stream, string fileName)
        {
            if (AuthInfo == null || string.IsNullOrEmpty(AuthInfo.UserToken) || string.IsNullOrEmpty(AuthInfo.UserSecret))
            {
                Errors.Add("Login is required.");
                return(null);
            }

            string query = OAuthManager.GenerateQuery(URLUserUpload, null, HttpMethod.Post, AuthInfo);

            UploadResult result = UploadData(stream, query, fileName, "image");

            return(ParseResponse(result));
        }
예제 #12
0
        protected string GetAuthorizationURL(string requestTokenURL, string authorizeURL, OAuthInfo authInfo,
                                             Dictionary <string, string> customParameters = null, HttpMethod httpMethod = HttpMethod.GET)
        {
            string url = OAuthManager.GenerateQuery(requestTokenURL, customParameters, httpMethod, authInfo);

            string response = SendRequest(httpMethod, url);

            if (!string.IsNullOrEmpty(response))
            {
                return(OAuthManager.GetAuthorizationURL(response, authInfo, authorizeURL));
            }

            return(null);
        }
예제 #13
0
        public FlickrPhotosGetSizesResponse PhotosGetSizes(string photoid)
        {
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("nojsoncallback", "1");
            args.Add("format", "json");
            args.Add("method", "flickr.photos.getSizes");
            args.Add("photo_id", photoid);

            string query = OAuthManager.GenerateQuery("https://api.flickr.com/services/rest", args, HttpMethod.POST, AuthInfo);

            string response = SendRequest(HttpMethod.GET, query);

            return(JsonConvert.DeserializeObject <FlickrPhotosGetSizesResponse>(response));
        }
예제 #14
0
        public TweetStatus TweetMessage(string message)
        {
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("status", message);

            string query = OAuthManager.GenerateQuery(URLTweet, args, HttpMethod.POST, AuthInfo);

            string response = SendRequest(HttpMethod.POST, query);

            if (!string.IsNullOrEmpty(response))
            {
                return(JsonConvert.DeserializeObject <TweetStatus>(response));
            }

            return(null);
        }
        /// <summary>
        /// Creates and returns a shareable link to files or folders.
        /// Note: Links created by the /shares API call expire after thirty days.
        /// </summary>
        /// <returns>
        /// A shareable link to the file or folder. The link can be used publicly and directs to a preview page of the file.
        /// Also returns the link's expiration date in Dropbox's usual date format.
        /// </returns>
        public DropboxShares CreateShareableLink(string path, string fileName = "")
        {
            if (OAuthInfo.CheckOAuth(AuthInfo))
            {
                string url = OAuthManager.GenerateQuery(ZAppHelper.CombineURL(URLShares, path, fileName), null, HttpMethod.Get, AuthInfo);

                string response = SendGetRequest(url);

                if (!string.IsNullOrEmpty(response))
                {
                    DropboxShares shares = JsonConvert.DeserializeObject <DropboxShares>(response);
                    return(shares);
                }
            }

            return(null);
        }
예제 #16
0
        public string GetAuthorizationURL()
        {
            Dictionary <string, string> args = new Dictionary <string, string>();

            args[OAuthManager.ParameterCallback] = "oob"; // Request activation code to validate authentication

            string url = OAuthManager.GenerateQuery(_jiraRequestToken.ToString(), args, HttpMethod.Post, AuthInfo);

            string response = SendRequest(HttpMethod.Post, url);

            if (!string.IsNullOrEmpty(response))
            {
                return(OAuthManager.GetAuthorizationURL(response, AuthInfo, _jiraAuthorize.ToString()));
            }

            return(null);
        }
        /// <summary>Retrieves file and folder metadata.</summary>
        /// <param name="path">The path to the file or folder.</param>
        /// <returns>
        /// The metadata for the file or folder at the given <path>.
        /// If <path> represents a folder and the list parameter is true, the metadata will also include a listing of metadata for the folder's contents.
        /// </returns>
        public DropboxDirectoryInfo GetFilesList(string path)
        {
            DropboxDirectoryInfo directoryInfo = null;

            if (OAuthInfo.CheckOAuth(AuthInfo))
            {
                string url = OAuthManager.GenerateQuery(ZAppHelper.CombineURL(URLMetaData, path), null, HttpMethod.Get, AuthInfo);

                string response = SendGetRequest(url);

                if (!string.IsNullOrEmpty(response))
                {
                    directoryInfo = JsonConvert.DeserializeObject <DropboxDirectoryInfo>(response);
                }
            }

            return(directoryInfo);
        }
예제 #18
0
        protected NameValueCollection GetAccessTokenEx(string accessTokenURL, OAuthInfo authInfo, HttpMethod httpMethod = HttpMethod.GET)
        {
            if (string.IsNullOrEmpty(authInfo.AuthToken) || string.IsNullOrEmpty(authInfo.AuthSecret))
            {
                throw new Exception("Auth infos missing. Open Authorization URL first.");
            }

            string url = OAuthManager.GenerateQuery(accessTokenURL, null, httpMethod, authInfo);

            string response = SendRequest(httpMethod, url);

            if (!string.IsNullOrEmpty(response))
            {
                return(OAuthManager.ParseAccessTokenResponse(response, authInfo));
            }

            return(null);
        }
예제 #19
0
        // https://www.dropbox.com/developers/core/api#files-POST
        public UploadResult UploadFile(Stream stream, string path, string fileName, bool createShareableURL = false, bool shortURL = true)
        {
            if (!OAuthInfo.CheckOAuth(AuthInfo))
            {
                Errors.Add("Login is required.");
                return(null);
            }

            string url = Helpers.CombineURL(URLFiles, Helpers.URLPathEncode(path));

            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("file", fileName);

            string query = OAuthManager.GenerateQuery(url, args, HttpMethod.Post, AuthInfo);

            // There's a 150MB limit to all uploads through the API.
            UploadResult result = UploadData(stream, query, fileName);

            if (result.IsSuccess)
            {
                DropboxContentInfo content = JsonConvert.DeserializeObject <DropboxContentInfo>(result.Response);

                if (content != null)
                {
                    if (createShareableURL)
                    {
                        DropboxShares shares = CreateShareableLink(content.Path, shortURL);

                        if (shares != null)
                        {
                            result.URL = shares.URL;
                        }
                    }
                    else
                    {
                        result.URL = GetPublicURL(content.Path);
                    }
                }
            }

            return(result);
        }
예제 #20
0
파일: Copy.cs 프로젝트: ywscr/ShareX
        // https://developers.copy.com/documentation#api-calls/filesystem - Read Root Directory
        // GET https://api.copy.com/rest/meta/copy
        public CopyContentInfo GetMetadata(string path)
        {
            CopyContentInfo contentInfo = null;

            if (OAuthInfo.CheckOAuth(AuthInfo))
            {
                string url = URLHelpers.CombineURL(URLMetaData, URLHelpers.URLEncode(path, true));

                string query = OAuthManager.GenerateQuery(url, null, HttpMethod.GET, AuthInfo);

                string response = SendRequest(HttpMethod.GET, query);

                if (!string.IsNullOrEmpty(response))
                {
                    contentInfo = JsonConvert.DeserializeObject <CopyContentInfo>(response);
                }
            }

            return(contentInfo);
        }
        public override UploadResult Upload(Stream stream, string fileName)
        {
            if (AuthInfo == null || string.IsNullOrEmpty(AuthInfo.UserToken) || string.IsNullOrEmpty(AuthInfo.UserSecret))
            {
                Errors.Add("Login is required.");
                return(null);
            }

            string url = ZAppHelper.CombineURL(URLFiles, UploadPath);

            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("file", fileName);

            string query = OAuthManager.GenerateQuery(url, args, HttpMethod.Post, AuthInfo);

            // There's a 150MB limit to all uploads through the API.
            string response = UploadData(stream, query, fileName);

            UploadResult result = new UploadResult(response);

            if (!string.IsNullOrEmpty(response))
            {
                if (AutoCreateShareableLink)
                {
                    DropboxShares shares = CreateShareableLink(UploadPath, fileName);

                    if (shares != null)
                    {
                        result.URL = shares.URL;
                    }
                }
                else
                {
                    result.URL = GetDropboxURL(AccountInfo.Uid, UploadPath, fileName);
                }
            }

            return(result);
        }
예제 #22
0
        // https://www.dropbox.com/developers/core/api#fileops-delete
        public DropboxContentInfo Delete(string path)
        {
            DropboxContentInfo contentInfo = null;

            if (!string.IsNullOrEmpty(path) && OAuthInfo.CheckOAuth(AuthInfo))
            {
                Dictionary <string, string> args = new Dictionary <string, string>();
                args.Add("root", Root);
                args.Add("path", path);

                string query = OAuthManager.GenerateQuery(URLDelete, args, HttpMethod.POST, AuthInfo);

                string response = SendRequest(HttpMethod.POST, query);

                if (!string.IsNullOrEmpty(response))
                {
                    contentInfo = JsonConvert.DeserializeObject <DropboxContentInfo>(response);
                }
            }

            return(contentInfo);
        }
예제 #23
0
        public override UploadResult Upload(Stream stream, string fileName)
        {
            using (new SSLBypassHelper())
            {
                using (JiraUpload up = new JiraUpload(_jiraIssuePrefix, GetSummary))
                {
                    if (up.ShowDialog() == DialogResult.Cancel)
                    {
                        return(new UploadResult
                        {
                            IsSuccess = true,
                            IsURLExpected = false
                        });
                    }

                    Uri    uri   = Combine(_jiraBaseAddress, string.Format(PathIssueAttachments, up.IssueId));
                    string query = OAuthManager.GenerateQuery(uri.ToString(), null, HttpMethod.POST, AuthInfo);

                    NameValueCollection headers = new NameValueCollection();
                    headers.Set("X-Atlassian-Token", "nocheck");

                    UploadResult res = UploadData(stream, query, fileName, headers: headers);
                    if (res.Response.Contains("errorMessages"))
                    {
                        res.Errors.Add(res.Response);
                    }
                    else
                    {
                        res.IsURLExpected = true;
                        var anonType   = new[] { new { thumbnail = "" } };
                        var anonObject = JsonConvert.DeserializeAnonymousType(res.Response, anonType);
                        res.ThumbnailURL = anonObject[0].thumbnail;
                        res.URL          = Combine(_jiraBaseAddress, string.Format(PathBrowseIssue, up.IssueId)).ToString();
                    }

                    return(res);
                }
            }
        }
        /// <summary>Retrieves information about the user's account.</summary>
        /// <returns>User account information.</returns>
        public DropboxAccountInfo GetAccountInfo()
        {
            if (OAuthInfo.CheckOAuth(AuthInfo))
            {
                string url = OAuthManager.GenerateQuery(URLAccountInfo, null, HttpMethod.Get, AuthInfo);

                string response = SendGetRequest(url);

                if (!string.IsNullOrEmpty(response))
                {
                    DropboxAccountInfo account = JsonConvert.DeserializeObject <DropboxAccountInfo>(response);

                    if (account != null)
                    {
                        AccountInfo = account;
                        return(account);
                    }
                }
            }

            return(null);
        }
        public UploadResult UploadMedia(Stream stream, string fileName, string albumID)
        {
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("id", albumID);   // Album identifier.
            args.Add("type", "image"); // Media type. Options are image, video, or base64.

            /*
             * // Optional
             * args.Add("title", ""); // Searchable title to set on the media. Maximum 250 characters.
             * args.Add("description", ""); // Searchable description to set on the media. Maximum 2048 characters.
             * args.Add("scramble", "false"); // Indicates if the filename should be scrambled. Options are true or false.
             * args.Add("degrees", ""); // Degrees of rotation in 90 degree increments.
             * args.Add("size", ""); // Size to resize an image to. (Images can only be made smaller.)
             */

            string url   = "http://api.photobucket.com/album/!/upload";
            string query = OAuthManager.GenerateQuery(url, args, HttpMethod.Post, AuthInfo);

            query = FixURL(query);

            string response = UploadData(stream, query, fileName, "uploadfile");

            UploadResult ur = new UploadResult(response);

            if (!string.IsNullOrEmpty(response))
            {
                XDocument xd = XDocument.Parse(response);
                XElement  xe;

                if ((xe = xd.GetNode("response/content")) != null)
                {
                    ur.URL          = xe.GetElementValue("url");
                    ur.ThumbnailURL = xe.GetElementValue("thumb");
                }
            }

            return(ur);
        }
예제 #26
0
        // https://www.dropbox.com/developers/core/api#shares
        public string CreateShareableLink(string path, DropboxURLType urlType)
        {
            if (!string.IsNullOrEmpty(path) && OAuthInfo.CheckOAuth(AuthInfo))
            {
                string url = Helpers.CombineURL(URLShares, Helpers.URLPathEncode(path));

                Dictionary <string, string> args = new Dictionary <string, string>();
                args.Add("short_url", urlType == DropboxURLType.Shortened ? "true" : "false");

                string query = OAuthManager.GenerateQuery(url, args, HttpMethod.POST, AuthInfo);

                string response = SendRequest(HttpMethod.POST, query);

                if (!string.IsNullOrEmpty(response))
                {
                    DropboxShares shares = JsonConvert.DeserializeObject <DropboxShares>(response);

                    if (urlType == DropboxURLType.Direct)
                    {
                        Match match = Regex.Match(shares.URL, @"https?://(?:www\.)?dropbox.com/s/(?<path>\w+/.+)");
                        if (match.Success)
                        {
                            string urlPath = match.Groups["path"].Value;
                            if (!string.IsNullOrEmpty(urlPath))
                            {
                                return(Helpers.CombineURL(URLShareDirect, urlPath));
                            }
                        }
                    }
                    else
                    {
                        return(shares.URL);
                    }
                }
            }

            return(null);
        }
예제 #27
0
        // https://www.dropbox.com/developers/core/api#metadata
        public DropboxContentInfo GetMetadata(string path, bool list)
        {
            DropboxContentInfo contentInfo = null;

            if (OAuthInfo.CheckOAuth(AuthInfo))
            {
                string url = Helpers.CombineURL(URLMetaData, Helpers.URLPathEncode(path));

                Dictionary <string, string> args = new Dictionary <string, string>();
                args.Add("list", list ? "true" : "false");

                string query = OAuthManager.GenerateQuery(url, args, HttpMethod.GET, AuthInfo);

                string response = SendRequest(HttpMethod.GET, query);

                if (!string.IsNullOrEmpty(response))
                {
                    contentInfo = JsonConvert.DeserializeObject <DropboxContentInfo>(response);
                }
            }

            return(contentInfo);
        }
예제 #28
0
        public TwitterStatusResponse TweetMessage(string message)
        {
            if (message.Length > MessageLimit)
            {
                message = message.Remove(MessageLimit);
            }

            string url   = string.Format("https://api.twitter.com/{0}/statuses/update.json", APIVersion);
            string query = OAuthManager.GenerateQuery(url, null, HttpMethod.POST, AuthInfo);

            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("status", message);

            string response = SendRequest(HttpMethod.POST, query, args);

            if (!string.IsNullOrEmpty(response))
            {
                return(JsonConvert.DeserializeObject <TwitterStatusResponse>(response));
            }

            return(null);
        }
예제 #29
0
        private string GetSummary(string issueId)
        {
            Dictionary <string, string> args = new Dictionary <string, string>();

            args["jql"]        = string.Format("issueKey='{0}'", issueId);
            args["maxResults"] = "10";
            args["fields"]     = "summary";
            string query = OAuthManager.GenerateQuery(_jiraPathSearch.ToString(), args, HttpMethod.Get, AuthInfo);

            string response = SendGetRequest(query);

            if (!string.IsNullOrEmpty(response))
            {
                var anonType = new { issues = new[] { new { key = "", fields = new { summary = "" } } } };
                var res      = JsonConvert.DeserializeAnonymousType(response, anonType);
                return(res.issues[0].fields.summary);
            }

            // This query can returns error so we have to remove last error from errors list
            Errors.RemoveAt(Errors.Count - 1);

            return(null);
        }
예제 #30
0
파일: Copy.cs 프로젝트: ywscr/ShareX
        // https://developers.copy.com/documentation#api-calls/profile
        public CopyAccountInfo GetAccountInfo()
        {
            CopyAccountInfo account = null;

            if (OAuthInfo.CheckOAuth(AuthInfo))
            {
                string query = OAuthManager.GenerateQuery(URLAccountInfo, null, HttpMethod.GET, AuthInfo);

                string response = SendRequest(HttpMethod.GET, query, null, APIHeaders);

                if (!string.IsNullOrEmpty(response))
                {
                    account = JsonConvert.DeserializeObject <CopyAccountInfo>(response);

                    if (account != null)
                    {
                        AccountInfo = account;
                    }
                }
            }

            return(account);
        }