public bool ValidateUserToken(UserToken userToken) { string relativePath = GenerateRelativeUserUrl(userToken.Username); QueryParameterList paramaters = new QueryParameterList(); paramaters.Add(new QueryParameter(_format, "xml")); string validateUserUrl = OAuth.GenerateURL(userToken.UserApi, relativePath, _getUserMethod, userToken, paramaters); try { XmlResponseMessage getUserResponseMessage = GetXmlResponseMessageFromUrl(validateUserUrl, _getUserMethod); return(true); } catch (PhotobucketApiException apiEx) { if (apiEx.ErrorCode == ErrorCode.CouldNotGet) { return(false); } throw; } }
private Privacy UpdateAlbumPrivacySettings(string albumPath, Privacy privacySetting, string password) { string relativePath = GenerateRelativeAlbumPrivacyUrl(albumPath); QueryParameterList paramaters = new QueryParameterList(); paramaters.Add(new QueryParameter(_format, "xml")); if (privacySetting == Privacy.PUBLIC) { paramaters.Add(new QueryParameter(_privacy, "public")); } else { paramaters.Add(new QueryParameter(_privacy, "private")); paramaters.Add(new QueryParameter(_password, password)); } string updateAlbumPrivacySettingsUrl = OAuth.GenerateURL(ApiUrl, relativePath, _updateAlbumPrivacyMethod, Token, paramaters); XmlResponseMessage updateAlbumPrivacySettingsResponseMessage = GetXmlResponseMessageFromUrl(updateAlbumPrivacySettingsUrl, _updateAlbumPrivacyMethod); return(GetPrivacyFromResponseMessage(updateAlbumPrivacySettingsResponseMessage)); }
private string GenerateRelativeMediaUrl(string url) { return(_media + "/" + OAuth.UrlEncode(OAuth.UrlEncode(url))); }
private string GenerateAlbumIdentifier(string albumName) { return(_albumUrl + "/" + OAuth.UrlEncode(OAuth.UrlEncode(albumName))); }
private XmlResponseMessage GetResponseForUploadMediaItem(string uploadMediaItemUrl, MediaItem mediaItem, QueryParameterList paramaters) { string boundary = "PHOTBUCKET_MIME_" + DateTime.Now.ToString("yyyyMMddhhmmss"); HttpWebRequest request = ( HttpWebRequest )HttpWebRequest.Create(uploadMediaItemUrl); request.UserAgent = "Mozilla/4.0 PhotobucketNet API (compatible; MSIE 6.0; Windows NT 5.1)"; request.Method = "POST"; request.KeepAlive = true; request.ContentType = "multipart/form-data; boundary=" + boundary + ""; request.Expect = ""; StringBuilder sb = new StringBuilder(); foreach (QueryParameter paramater in paramaters) { if (paramater.Name == "format") { continue; } else if (paramater.Name == "oauth_signature") { paramater.Value = OAuth.UrlDecode(paramater.Value); } else if (paramater.Name == _description || paramater.Name == _title) { paramater.Value = OAuth.UrlDecode(paramater.Value); } sb.Append("--" + boundary + "\r\n"); sb.Append("Content-Disposition: form-data; name=\"" + paramater.Name + "\"\r\n"); sb.Append("\r\n"); sb.Append(paramater.Value + "\r\n"); } sb.Append("--" + boundary + "\r\n"); sb.Append("Content-Disposition: form-data; name=\"uploadfile\"; filename=\"" + mediaItem.Name + "\"\r\n"); sb.Append("Content-Type: mimetype\r\nContent-Transfer-Ecoding: binary"); sb.Append("\r\n\r\n"); UTF8Encoding encoding = new UTF8Encoding(); byte[] postContents = encoding.GetBytes(sb.ToString()); Stream stream = mediaItem.MediaStream; byte[] photoContents = new byte[stream.Length]; stream.Read(photoContents, 0, photoContents.Length); stream.Close(); byte[] postFooter = encoding.GetBytes("\r\n--" + boundary + "--\r\n"); byte[] dataBuffer = new byte[postContents.Length + photoContents.Length + postFooter.Length]; Buffer.BlockCopy(postContents, 0, dataBuffer, 0, postContents.Length); Buffer.BlockCopy(photoContents, 0, dataBuffer, postContents.Length, photoContents.Length); Buffer.BlockCopy(postFooter, 0, dataBuffer, postContents.Length + photoContents.Length, postFooter.Length); request.ContentLength = dataBuffer.Length; Stream resStream = request.GetRequestStream(); int count = 1; int uploadBit = Math.Max(dataBuffer.Length / 100, 50 * 1024); int uploadSoFar = 0; if (OnUploadMediaProgress != null) { OnUploadMediaProgress(this, new UploadMediaProgressEventArgs(0, dataBuffer.Length)); } for (int i = 0; i < dataBuffer.Length; i = i + uploadBit) { int toUpload = Math.Min(uploadBit, dataBuffer.Length - i); uploadSoFar += toUpload; resStream.Write(dataBuffer, i, toUpload); if ((OnUploadMediaProgress != null) && ((count++) % 5 == 0 || uploadSoFar == dataBuffer.Length)) { OnUploadMediaProgress(this, new UploadMediaProgressEventArgs(uploadSoFar, dataBuffer.Length)); } } resStream.Close(); try { request.Method = _uploadMediaMethod; HttpWebResponse response = ( HttpWebResponse )request.GetResponse(); Stream responseStream = response.GetResponseStream(); return(new XmlResponseMessage(responseStream)); } catch (WebException webEx) { throw PhotobucketException.CreateFromWebException(webEx); } }
public void Ping() { string pingUrl = OAuth.GenerateURL(ApiUrl, _pingUrl, _pingMethod, new PhotobucketToken()); ResponseMessage pingResponseMessage = GetResponseMessageFromUrl(pingUrl, _pingMethod); }
private string GenerateRelativeSearchUrl(string query) { return(_searchUrl + "/" + OAuth.UrlEncode(query)); }