/// <summary> /// Will do a call to the SM JSON endpoint and will return the response /// </summary> /// <param name="method">The method</param> /// <param name="args">The arguments</param> /// <param name="sessionState">The session state for the call</param> public async Task <SMR> ExecuteMethod <SMR>(string method, SmugMugBase sessionState, params object[] args) where SMR : SmugMugResponse { //most calls go to the normal api string baseAddr = baseAddrSecure1_3_0; //if we don't have a method or the parameters are not in pairs of 2, bail if (string.IsNullOrEmpty(method)) { throw new ArgumentException("The method cannot be null or empty", "method"); } if (args.Length > 0 && args.Length % 2 != 0) { throw new ArgumentException("The number of arguments must be even", "args"); } // Generate the request string (with the oauth_signature) string msg = oAuthUtility.GetMessageParameters(Site.APIKey, Site.ApplicationSecret, method, sessionState != null ? sessionState.AccessToken : null, args); //we need to send that request as a stream of bytes. var message = System.Text.UTF8Encoding.UTF8.GetBytes(msg); var myWebRequest = HttpWebRequest.Create(baseAddr); ((HttpWebRequest)myWebRequest).UserAgent = "SmugMugModel_v1.0"; //do we have a proxy? if (Site.Proxy != null && !Site.Proxy.IsBypassed(new Uri(baseAddr))) { myWebRequest.Proxy = Site.Proxy; } myWebRequest.ContentType = "application/x-www-form-urlencoded"; myWebRequest.Method = "POST"; myWebRequest.ContentLength = message.Length; //we send the request using (Stream sw = await myWebRequest.GetRequestStreamAsync()) { sw.Write(message, 0, message.Length); } string result = string.Empty; using (var response = await myWebRequest.GetResponseAsync()) { using (StreamReader sr = new StreamReader(response.GetResponseStream())) { result = sr.ReadToEnd(); } } var temp = JsonConvert.DeserializeObject <SMR>(System.Uri.UnescapeDataString(result)); return(temp); }
/// <summary> /// Get the access Token from SmugMug /// </summary> public async Task <Token> GetAccessTokenAsync(Token requestToken) { CommunicationHelper ch = new CommunicationHelper(); SmugMugBase session = new SmugMugBase(); session.AccessToken = requestToken; var auth = await ch.ExecuteMethod <GetTokenResponse>("smugmug.auth.getAccessToken", session, "oauth_token_secret", requestToken.Secret); return(auth.Auth.Token); }
public SmugMugObject() { basic = new SmugMugBase(); }
/// <summary> /// This is the constructor for the ImageUpload object. It is private so you have to use the CreateUploader method /// </summary> /// <param name="SessionID">The session ID</param> /// <param name="AlbumID">The album ID</param> internal ImageUpload(SmugMugBase basic, Album Album) { this.authentication = basic; this.Album = Album; }
public SmugMugObject() { basic = new SmugMugBase(); }