Esempio n. 1
0
        public bool InvalidateCredentials(ITwitterCredentials credentials)
        {
            var url = "https://api.twitter.com/oauth2/invalidate_token";

            var json    = _twitterRequestHandler.ExecuteQuery(url, HttpMethod.POST, new InvalidateTokenHttpHandler(), credentials);
            var jobject = _jObjectStaticWrapper.GetJobjectFromJson(json);

            JToken unused;

            if (jobject.TryGetValue("access_token", out unused))
            {
                return(true);
            }

            try
            {
                var errorsObject = jobject["errors"];
                var errors       = _jObjectStaticWrapper.ToObject <ITwitterExceptionInfo[]>(errorsObject);

                _exceptionHandler.TryLogExceptionInfos(errors, url);
            }
            catch (Exception)
            {
                // Something is definitely wrong!
            }

            return(false);
        }
Esempio n. 2
0
        public void WebhookMessageReceived(IWebhookMessage message)
        {
            var json            = message.Json;
            var jsonObjectEvent = _jObjectWrapper.GetJobjectFromJson(json);

            var jsonEventChildren = jsonObjectEvent.Children().ToArray();
            var keys = jsonEventChildren.Where(x => x.Path.EndsWith("event") || x.Path.EndsWith("events"));
            var key  = keys.SingleOrDefault();

            if (key == null)
            {
                return;
            }

            this.Raise(JsonObjectReceived, new JsonObjectEventArgs(json));

            var eventName = key.Path;

            if (_events.ContainsKey(eventName))
            {
                _events[eventName].Invoke(eventName, jsonObjectEvent);
            }
            else
            {
                this.Raise(UnmanagedEventReceived, new UnmanagedMessageReceivedEventArgs(json));
            }
        }
        public IEnumerable <ITwitterExceptionInfo> GetTwitterExceptionInfosFromStream(Stream stream)
        {
            if (stream == null)
            {
                return(null);
            }

            string twitterExceptionInfo = null;

            try
            {
                using (var reader = new StreamReader(stream))
                {
                    twitterExceptionInfo = reader.ReadToEnd();
                    var jObject = _jObjectStaticWrapper.GetJobjectFromJson(twitterExceptionInfo);
                    return(_jObjectStaticWrapper.ToObject <IEnumerable <ITwitterExceptionInfo> >(jObject["errors"]));
                }
            }
            catch (Exception)
            {
                var twitterInfo = _twitterExceptionInfoUnityFactory.Create();
                twitterInfo.Message = twitterExceptionInfo;
                return(new[] { twitterInfo });
            }
        }
Esempio n. 4
0
        private bool TryGetEvent(string jsonEvent)
        {
            var    jsonObjectEvent = _jObjectWrapper.GetJobjectFromJson(jsonEvent);
            JToken jsonEventToken;

            if (jsonObjectEvent.TryGetValue("event", out jsonEventToken))
            {
                string eventName = jsonEventToken.Value <string>();

                if (_events.ContainsKey(eventName))
                {
                    _events[eventName].Invoke(jsonObjectEvent);
                }

                return(true);
            }

            return(false);
        }
 public ITwitterExceptionInfo[] GetTwitterExceptionInfos(string content)
 {
     try
     {
         var jObject = _jObjectStaticWrapper.GetJobjectFromJson(content);
         return(_jObjectStaticWrapper.ToObject <ITwitterExceptionInfo[]>(jObject["errors"]));
     }
     catch (Exception)
     {
         var twitterInfo = _twitterExceptionInfoUnityFactory.Create();
         twitterInfo.Message = content;
         return(new[] { twitterInfo });
     }
 }
Esempio n. 6
0
        public void WebhookMessageReceived(IWebhookMessage message)
        {
            var jsonObjectEvent = _jObjectStaticWrapper.GetJobjectFromJson(message.Json);
            var userId          = jsonObjectEvent["for_user_id"].ToString();

            _accountActivityStream.ForEach(activityStream =>
            {
                var isTargetingActivityStream = activityStream.AccountUserId.ToString() == userId;
                if (isTargetingActivityStream)
                {
                    activityStream.WebhookMessageReceived(message);
                }
            });
        }
Esempio n. 7
0
        public void WebhookMessageReceived(IWebhookMessage message)
        {
            var jsonObjectEvent = _jObjectStaticWrapper.GetJobjectFromJson(message.Json);

            var keys   = jsonObjectEvent.Children().SingleOrDefault(x => x.Path == "for_user_id");
            var userId = jsonObjectEvent["for_user_id"].ToString();

            _userAccountActivityStream.ForEach(activityStream =>
            {
                var isTargetingActivityStream = activityStream.UserId.ToString() == userId;
                if (isTargetingActivityStream)
                {
                    activityStream.WebhookMessageReceived(message);
                }
            });
        }
Esempio n. 8
0
        public void WebhookMessageReceived(IWebhookMessage message)
        {
            if (message == null)
            {
                return;
            }

            try
            {
                var json            = message.Json;
                var jsonObjectEvent = _jObjectWrapper.GetJobjectFromJson(json);

                var jsonEventChildren = jsonObjectEvent.Children().ToArray();
                var keys = jsonEventChildren.Where(x => x.Path.EndsWith("event") || x.Path.EndsWith("events"));
                var key  = keys.SingleOrDefault();

                if (key == null)
                {
                    return;
                }

                this.Raise(EventReceived, new AccountActivityEvent
                {
                    Json          = json,
                    AccountUserId = AccountUserId
                });

                var eventName = key.Path;
                if (_events.ContainsKey(eventName))
                {
                    _events[eventName].Invoke(eventName, jsonObjectEvent);
                }
                else
                {
                    this.Raise(UnsupportedEventReceived, new UnsupportedMessageReceivedEvent(json));
                }
            }
            catch (Exception e)
            {
                this.Raise(UnexpectedExceptionThrown, new UnexpectedExceptionThrownEvent(e));
            }
        }
Esempio n. 9
0
        // Events
        protected void TryInvokeGlobalStreamMessages(string json)
        {
            if (string.IsNullOrEmpty(json))
            {
                return;
            }

            var jsonObject    = _jObjectWrapper.GetJobjectFromJson(json);
            var jsonRootToken = jsonObject.Children().First();
            var messageType   = _jObjectWrapper.GetNodeRootName(jsonRootToken);

            if (_streamEventsActions.ContainsKey(messageType))
            {
                var messageInfo = jsonObject[messageType];
                _streamEventsActions[messageType].Invoke(messageInfo);
            }
            else
            {
                var unmanagedMessageEventArgs = new UnmanagedMessageReceivedEventArgs(json);
                this.Raise(UnmanagedEventReceived, unmanagedMessageEventArgs);
            }
        }
Esempio n. 10
0
        public async Task <bool> IsRequestManagedByTweetinviAsync(IWebhooksRequest request)
        {
            var isRequestComingFromTwitter = IsRequestComingFromTwitter(request);

            if (!isRequestComingFromTwitter)
            {
                return(false);
            }

            var body = await request.GetJsonFromBodyAsync().ConfigureAwait(false);

            if (body != null)
            {
                var jsonObjectEvent          = _jObjectStaticWrapper.GetJobjectFromJson(body);
                var isAccountActivityRequest = jsonObjectEvent?.ContainsKey("for_user_id");

                if (isAccountActivityRequest == true)
                {
                    return(true);
                }
            }

            return(IsCrcChallenge(request));
        }
Esempio n. 11
0
        public List <ITweetDTO> GetTweetsFromJsonResponse(string json)
        {
            var jObject = _jObjectWrapper.GetJobjectFromJson(json);

            return(GetTweetsFromJsonObject(jObject));
        }
Esempio n. 12
0
        // Execute<JObject>
        public JObject ExecuteGETQuery(string query)
        {
            string jsonResponse = ExecuteQuery(query, HttpMethod.GET);

            return(_jObjectStaticWrapper.GetJobjectFromJson(jsonResponse));
        }