public async Task <TwoResponses <T, V> > MakeRequest <T, V>(CancellationToken?cancellationToken = null)
            where T : IFoursquareType
            where V : IFoursquareType
        {
            try
            {
                switch (Method)
                {
                case HttpMethod.GET:
                    string resp = await MakeGetRequest(cancellationToken);

                    var twoParsedResponse = JsonConvert.DeserializeObject <TwoResponses <T, V> >(resp, new FoursquareTwoResponseConverter <T, V>());
                    ProcessMultiNotifications(twoParsedResponse);
                    return(twoParsedResponse);

                default:
                    throw new Exception("Unsupported HttpMethod type");
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Network exception: " + e.Message);
                var response = new TwoResponses <T, V>
                {
                    Exception = e
                };
                return(response);
            }
        }
        private static void ProcessMultiNotifications <T, V>(TwoResponses <T, V> response)
            where T : IFoursquareType
            where V : IFoursquareType
        {
            if (response?.notifications == null)
            {
                return;
            }

            foreach (var notif in response.notifications)
            {
                switch (notif.type)
                {
                case "pendingFriendRequests":
                    break;

                case "notificationTray":
                    break;

                case "plans":
                    break;

                default:
                    break;
                }
            }
        }
Exemple #3
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            TwoResponses <T, V> output = (TwoResponses <T, V>)Activator.CreateInstance(objectType);

            JObject jObject = JObject.Load(reader);

            if (jObject["meta"] != null)
            {
                output.meta = jObject["meta"].ToObject <Meta>();
            }

            if (jObject["notifications"] != null)
            {
                output.notifications = jObject["notifications"].ToObject <List <Notifications> >();
            }

            JToken response = jObject["response"];

            if (response?["responses"] != null)
            {
                var responses = response["responses"].Children().ToList();
                if (responses.Count > 0)
                {
                    output.SubResponse1 = ParseResponse <T>(responses.ElementAt(0));
                }
                if (responses.Count > 1)
                {
                    output.SubResponse2 = ParseResponse <V>(responses.ElementAt(1));
                }
            }

            return(output);
        }