예제 #1
0
        public static string GetUsername(ConsumerBase twitter, string accessToken)
        {
            XDocument      xml = VerifyCredentials(twitter, accessToken);
            XPathNavigator nav = xml.CreateNavigator();

            return(nav.SelectSingleNode("/user/screen_name").Value);
        }
예제 #2
0
        public static XDocument GetDocList(ConsumerBase consumer, string accessToken, string nextEndpoint)
        {
            if (consumer == null)
            {
                throw new ArgumentNullException("consumer");
            }
            var endpoint = GetDocsEntriesEndpoint;

            if (!string.IsNullOrEmpty(nextEndpoint))
            {
                endpoint = new MessageReceivingEndpoint(nextEndpoint, HttpDeliveryMethods.GetRequest);
            }

            var extraData = new Dictionary <string, string>() /*{ {"GData-Version","3.0"} }*/;
            //var request = consumer.PrepareAuthorizedRequest(endpoint, accessToken, extraData);
            //var response = consumer.Channel.WebRequestHandler.GetResponse(request);
            //string body = response.GetResponseReader().ReadToEnd();
            //XDocument result = XDocument.Parse(body);
            //return result;

            var request = consumer.PrepareAuthorizedRequest(endpoint, accessToken, extraData);

            // Enable gzip compression.  Google only compresses the response for recognized user agent headers. - Mike Lim
            request.AutomaticDecompression = DecompressionMethods.GZip;
            request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.151 Safari/534.16";

            var       response = consumer.Channel.WebRequestHandler.GetResponse(request);
            string    body     = response.GetResponseReader().ReadToEnd();
            XDocument result   = XDocument.Parse(body);

            return(result);
        }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OAuthAuthorization"/> class.
        /// </summary>
        /// <param name="consumer">The consumer.</param>
        protected OAuthAuthorization(ConsumerBase consumer)
        {
            if (consumer == null)
            {
                throw new ArgumentNullException("consumer");
            }

            this.Consumer = consumer;
        }
예제 #4
0
        public static string Tweet(ConsumerBase twitter, string accessToken, string status)
        {
            Dictionary <string, string> extraData = new Dictionary <string, string>();

            extraData.Add("status", status);
            HttpWebRequest      request  = twitter.PrepareAuthorizedRequest(TweetEndpoint, accessToken, extraData);
            IncomingWebResponse response = twitter.Channel.WebRequestHandler.GetResponse(request);

            return(response.GetResponseReader().ReadToEnd());
        }
예제 #5
0
            public ConsumerArrayLHS()
            {
                ConsumerBase elemConsumer = GetConsumer(typeof(LHS_ElemT));

                LHS_Type          = typeof(LHS_ElemT[]);
                expected_RHS_Type = typeof(IEnumerable <>).MakeGenericType(new[] { elemConsumer.expected_RHS_Type });
                var closed_mkFunc = (this).GetType() /*class type should be closed*/.GetMethod("MkFunc").MakeGenericMethod(new[] { elemConsumer.expected_RHS_Type });

                F = closed_mkFunc.Invoke(null, new[] { elemConsumer.F }); // if the runtime type of elemConsumer.F doesnt match , it throws here
            }
예제 #6
0
        public static XDocument UpdateProfileImage(ConsumerBase twitter, string accessToken, Stream image, string contentType)
        {
            var parts = new[] {
                MultipartPostPart.CreateFormFilePart("image", "twitterPhoto", contentType, image),
            };
            HttpWebRequest      request  = twitter.PrepareAuthorizedRequest(UpdateProfileImageEndpoint, accessToken, parts);
            IncomingWebResponse response = twitter.Channel.WebRequestHandler.GetResponse(request);
            string responseString        = response.GetResponseReader().ReadToEnd();

            return(XDocument.Parse(responseString));
        }
예제 #7
0
        public static string GetUserID(ConsumerBase flickr, string accessToken)
        {
            if (accessToken != null)
            {
                XDocument      xml = VerifyCredentials(flickr, accessToken);
                XPathNavigator nav = xml.CreateNavigator();
                return(nav.SelectSingleNode("/rsp/user").GetAttribute("id", ""));
            }

            return(null);
        }
        public static string GetProfile(ConsumerBase consumer, string accessToken)
        {
            if (consumer == null)
            {
                throw new ArgumentNullException("consumer");
            }

            var    request  = consumer.PrepareAuthorizedRequest(ProfileEndpoint, accessToken, new Dictionary <string, string>());
            var    response = consumer.Channel.WebRequestHandler.GetResponse(request);
            string body     = response.GetResponseReader().ReadToEnd();

            return(body);
        }
예제 #9
0
        /// <summary>
        /// Gets the Gmail address book's contents.
        /// </summary>
        /// <param name="consumer">The Google consumer previously constructed using <see cref="CreateWebConsumer"/> or <see cref="CreateDesktopConsumer"/>.</param>
        /// <param name="accessToken">The access token previously retrieved.</param>
        /// <returns>An XML document returned by Google.</returns>
        public static XDocument GetContacts(ConsumerBase consumer, string accessToken)
        {
            if (consumer == null)
            {
                throw new ArgumentNullException("consumer");
            }

            var       response = consumer.PrepareAuthorizedRequestAndSend(GetContactsEndpoint, accessToken);
            string    body     = response.GetResponseReader().ReadToEnd();
            XDocument result   = XDocument.Parse(body);

            return(result);
        }
예제 #10
0
        public static void PostBlogEntry(ConsumerBase consumer, string accessToken, string blogUrl, string title, XElement body)
        {
            string feedUrl;
            var    getBlogHome = WebRequest.Create(blogUrl);

            using (var blogHomeResponse = getBlogHome.GetResponse()) {
                using (StreamReader sr = new StreamReader(blogHomeResponse.GetResponseStream())) {
                    string homePageHtml = sr.ReadToEnd();
                    Match  m            = Regex.Match(homePageHtml, @"http://www.blogger.com/feeds/\d+/posts/default");
                    Debug.Assert(m.Success, "Posting operation failed.");
                    feedUrl = m.Value;
                }
            }
            const string Atom  = "http://www.w3.org/2005/Atom";
            XElement     entry = new XElement(
                XName.Get("entry", Atom),
                new XElement(XName.Get("title", Atom), new XAttribute("type", "text"), title),
                new XElement(XName.Get("content", Atom), new XAttribute("type", "xhtml"), body),
                new XElement(XName.Get("category", Atom), new XAttribute("scheme", "http://www.blogger.com/atom/ns#"), new XAttribute("term", "oauthdemo")));

            MemoryStream      ms  = new MemoryStream();
            XmlWriterSettings xws = new XmlWriterSettings()
            {
                Encoding = Encoding.UTF8,
            };
            XmlWriter xw = XmlWriter.Create(ms, xws);

            entry.WriteTo(xw);
            xw.Flush();

            WebRequest request = consumer.PrepareAuthorizedRequest(new MessageReceivingEndpoint(feedUrl, HttpDeliveryMethods.PostRequest | HttpDeliveryMethods.AuthorizationHeaderRequest), accessToken);

            request.ContentType   = "application/atom+xml";
            request.Method        = "POST";
            request.ContentLength = ms.Length;
            ms.Seek(0, SeekOrigin.Begin);
            using (Stream requestStream = request.GetRequestStream()) {
                ms.CopyTo(requestStream);
            }
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
                if (response.StatusCode == HttpStatusCode.Created)
                {
                    // Success
                }
                else
                {
                    // Error!
                }
            }
        }
예제 #11
0
        public static XDocument UpdateProfileBackgroundImage(ConsumerBase twitter, string accessToken, string image, bool tile)
        {
            var parts = new[] {
                MultipartPostPart.CreateFormFilePart("image", image, "image/" + Path.GetExtension(image).Substring(1).ToLowerInvariant()),
                MultipartPostPart.CreateFormPart("tile", tile.ToString().ToLowerInvariant()),
            };
            HttpWebRequest request = twitter.PrepareAuthorizedRequest(UpdateProfileBackgroundImageEndpoint, accessToken, parts);

            request.ServicePoint.Expect100Continue = false;
            IncomingWebResponse response = twitter.Channel.WebRequestHandler.GetResponse(request);
            string responseString        = response.GetResponseReader().ReadToEnd();

            return(XDocument.Parse(responseString));
        }
예제 #12
0
        public static string Digg(ConsumerBase consumer, string accessToken, string id)
        {
            if (consumer == null)
            {
                throw new ArgumentNullException("consumer");
            }

            var extraData = new Dictionary <string, string>()
            {
                { "story_id", id }
            };
            var    request  = consumer.PrepareAuthorizedRequest(DiggEndpoint, accessToken, extraData);
            var    response = consumer.Channel.WebRequestHandler.GetResponse(request);
            string body     = response.GetResponseReader().ReadToEnd();

            return(body);
        }
        /// <summary>
        ///    Updates the authenticating user's status, also known as tweeting.
        /// </summary>
        /// <param name="twitter"></param>
        /// <param name="accessToken"></param>
        /// <param name="status">The text of your status update, typically up to 140 characters. URL encode as necessary. t.co link wrapping may effect character counts.</param>
        /// <param name="includeEntities">When set to either true, t or 1, each tweet will include a node called "entities,". This node offers a variety of metadata about the tweet in a discreet structure, including: user_mentions, urls, and hashtags. While entities are opt-in on timelines at present, they will be made a default component of output in the future. See Tweet Entities for more detail on entities.
        ///  </param>
        /// <returns></returns>
        public static JObject UpdateStatus(ConsumerBase twitter, string accessToken, String status, bool includeEntities)
        {
            var parts = new[] {
                MultipartPostPart.CreateFormPart("status", status),
                MultipartPostPart.CreateFormPart("include_entities", includeEntities.ToString()),
            };

            HttpWebRequest      request  = twitter.PrepareAuthorizedRequest(UpdateStatusEndpoint, accessToken, parts);
            IncomingWebResponse response = twitter.Channel.WebRequestHandler.GetResponse(request);

            using (var responseReader = response.GetResponseReader())
            {
                var result = responseReader.ReadToEnd();

                return(JObject.Parse(result));
            }
        }
예제 #14
0
        public Task <T> Receive()
        {
            lock (_mon)
            {
                if (_messages.Count != 0)
                {
                    var t = _messages.First.Value;
                    _messages.RemoveFirst();
                    return(Task.FromResult(t));
                }

                var cons = new ConsumerBase <T>();
                _consumers.AddLast(cons);

                return(cons.Task);
            }
        }
예제 #15
0
        /// <summary>
        /// Gets the Gmail address book's contents.
        /// </summary>
        /// <param name="consumer">The Google consumer.</param>
        /// <param name="accessToken">The access token previously retrieved.</param>
        /// <param name="maxResults">The maximum number of entries to return. If you want to receive all of the contacts, rather than only the default maximum, you can specify a very large number here.</param>
        /// <param name="startIndex">The 1-based index of the first result to be retrieved (for paging).</param>
        /// <returns>An XML document returned by Google.</returns>
        public static XDocument GetContacts(ConsumerBase consumer, string accessToken, int maxResults /* = 25*/, int startIndex /* = 1*/)
        {
            if (consumer == null)
            {
                throw new ArgumentNullException("consumer");
            }

            var extraData = new Dictionary <string, string>()
            {
                { "start-index", startIndex.ToString(CultureInfo.InvariantCulture) },
                { "max-results", maxResults.ToString(CultureInfo.InvariantCulture) },
            };
            var       request  = consumer.PrepareAuthorizedRequest(GetContactsEndpoint, accessToken, extraData);
            var       response = consumer.Channel.WebRequestHandler.GetResponse(request);
            string    body     = response.GetResponseReader().ReadToEnd();
            XDocument result   = XDocument.Parse(body);

            return(result);
        }
예제 #16
0
        public static Stream GetDoc(ConsumerBase consumer, string accessToken, string docEndpoint, out long size)
        {
            if (consumer == null)
            {
                throw new ArgumentNullException("consumer");
            }
            var endpoint  = new MessageReceivingEndpoint(docEndpoint, HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest);
            var extraData = new Dictionary <string, string>() /*{ {"GData-Version","3.0"} }*/;
            var request   = consumer.PrepareAuthorizedRequest(endpoint, accessToken, extraData);
            var response  = consumer.Channel.WebRequestHandler.GetResponse(request);

            if (!string.IsNullOrEmpty(response.Headers[HttpResponseHeader.ContentLength]))
            {
                long.TryParse(response.Headers[HttpResponseHeader.ContentLength], out size);
            }
            else
            {
                size = 0;
            }
            return(response.ResponseStream);
        }
예제 #17
0
        public static XDocument GetDocList(ConsumerBase consumer, string accessToken, string nextEndpoint)
        {
            if (consumer == null)
            {
                throw new ArgumentNullException("consumer");
            }
            var endpoint = GetDocsEntriesEndpoint;

            if (!string.IsNullOrEmpty(nextEndpoint))
            {
                endpoint = new MessageReceivingEndpoint(nextEndpoint, HttpDeliveryMethods.GetRequest);
            }

            var       extraData = new Dictionary <string, string>() /*{ {"GData-Version","3.0"} }*/;
            var       request   = consumer.PrepareAuthorizedRequest(endpoint, accessToken, extraData);
            var       response  = consumer.Channel.WebRequestHandler.GetResponse(request);
            string    body      = response.GetResponseReader().ReadToEnd();
            XDocument result    = XDocument.Parse(body);

            return(result);
        }
예제 #18
0
        /// <summary>
        /// Gets the Gmail address book's contents.
        /// </summary>
        /// <param name="consumer">The Google consumer.</param>
        /// <param name="accessToken">The access token previously retrieved.</param>
        /// <param name="maxResults">The maximum number of entries to return. If you want to receive all of the contacts, rather than only the default maximum, you can specify a very large number here.</param>
        /// <param name="startIndex">The 1-based index of the first result to be retrieved (for paging).</param>
        /// <returns>An XML document returned by Google.</returns>
        public static XDocument GetContacts(ConsumerBase consumer, string accessToken, int maxResults /* = 25*/, int startIndex /* = 1*/)
        {
            if (consumer == null)
            {
                throw new ArgumentNullException("consumer");
            }

            var extraData = new Dictionary <string, string>()
            {
                { "start-index", startIndex.ToString(CultureInfo.InvariantCulture) },
                { "max-results", maxResults.ToString(CultureInfo.InvariantCulture) },
            };
            var request = consumer.PrepareAuthorizedRequest(GetContactsEndpoint, accessToken, extraData);

            // Enable gzip compression.  Google only compresses the response for recognized user agent headers. - Mike Lim
            request.AutomaticDecompression = DecompressionMethods.GZip;
            request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.151 Safari/534.16";

            var       response = consumer.Channel.WebRequestHandler.GetResponse(request);
            string    body     = response.GetResponseReader().ReadToEnd();
            XDocument result   = XDocument.Parse(body);

            return(result);
        }
예제 #19
0
 public static XDocument GetUpdates(ConsumerBase twitter, string accessToken)
 {
     IncomingWebResponse response = twitter.PrepareAuthorizedRequestAndSend(GetFriendTimelineStatusEndpoint, accessToken);
     return XDocument.Load(XmlReader.Create(response.GetResponseReader()));
 }
 public GoogleDocumentProvider(AuthData authData)
 {
     _accessToken = authData.Token;
     _consumer    = new WebConsumer(GoogleConsumer.ServiceDescription, ImportConfiguration.GoogleTokenManager);
 }
예제 #21
0
        public static XDocument GetAuthToken(ConsumerBase flickr, string accessToken)
        {
            IncomingWebResponse response = flickr.PrepareAuthorizedRequestAndSend(ServiceDescription.AccessTokenEndpoint, accessToken);

            return(XDocument.Load(XmlReader.Create(response.GetResponseReader())));
        }
예제 #22
0
 /// <summary>
 /// Creates is XRDS object, automatically attaches
 /// to specified OpenID object.
 /// </summary>
 /// <param name="oid">Parent OpenID object</param>
 public XRDS(ConsumerBase oid)
 {
     Parent = oid;
     oid.PluginsDiscovery.Add(this);
 }
예제 #23
0
        public static Stream GetDoc(ConsumerBase consumer, string accessToken, string docEndpoint)
        {
            long size;

            return(GetDoc(consumer, accessToken, docEndpoint, out size));
        }
 /// <summary>
 /// Creates a new SimpleRegistration plugin and attaches it to a OpenID object.
 /// </summary>
 /// <param name="oid">OpenID object to attach.</param>
 public SimpleRegistration(ConsumerBase oid)
 {
     _RequiredFields = new List<string>();
     _OptionalFields = new List<string>();
     Parent = oid;
     oid.PluginsExtension.Add(this);
 }
예제 #25
0
        public static XDocument VerifyCredentials(ConsumerBase twitter, string accessToken)
        {
            IncomingWebResponse response = twitter.PrepareAuthorizedRequestAndSend(VerifyCredentialsEndpoint, accessToken);

            return(XDocument.Load(XmlReader.Create(response.GetResponseReader())));
        }
예제 #26
0
        public static XDocument GetUpdates(ConsumerBase twitter, string accessToken)
        {
            IncomingWebResponse response = twitter.PrepareAuthorizedRequestAndSend(GetFriendTimelineStatusEndpoint, accessToken);

            return(XDocument.Load(XmlReader.Create(response.GetResponseReader())));
        }
예제 #27
0
        public static XDocument UpdateProfileImage(ConsumerBase twitter, string accessToken, string pathToImage)
        {
            string contentType = "image/" + Path.GetExtension(pathToImage).Substring(1).ToLowerInvariant();

            return(UpdateProfileImage(twitter, accessToken, File.OpenRead(pathToImage), contentType));
        }
 /// <summary>
 /// Creates an instance of AuthenticationPolicy extension.
 /// </summary>
 /// <param name="openid">The parent OpenIDConsumer object.</param>
 public AuthenticationPolicy(ConsumerBase openid)
 {
     _Parent = openid;
     _Parent.PluginsExtension.Add(this);
     PreferredPolicies = new List<string>();
 }