Beispiel #1
0
        internal async Task <StreamResponse <T> > GetEnriched <T>(GetOptions options = null) where T : EnrichedActivity
        {
            // build request
            options = options ?? GetOptions.Default;
            var request = _client.BuildEnrichedFeedRequest(this, "/", HttpMethod.GET);

            options.Apply(request);

            // make request
            var response = await _client.MakeRequest(request);

            if (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                throw StreamException.FromResponse(response);
            }

            // handle response
            var     result = new StreamResponse <T>();
            JObject obj    = JObject.Parse(response.Content);

            foreach (var prop in obj.Properties())
            {
                switch (prop.Name)
                {
                case "results":
                case "activities":
                {
                    // get the results
                    var array = prop.Value as JArray;
                    result.Results = array.Select(a => EnrichedActivity.FromJson((JObject)a) as T).ToList();
                    break;
                }

                case "unseen":
                {
                    result.Unseen = prop.Value.Value <long>();
                    break;
                }

                case "unread":
                {
                    result.Unread = prop.Value.Value <long>();
                    break;
                }

                case "duration":
                {
                    result.Duration = prop.Value.Value <String>();
                    break;
                }

                default:
                    break;
                }
            }

            return(result);
        }
Beispiel #2
0
            internal static EnrichedActivity GetActivity(string json)
            {
                JObject obj = JObject.Parse(json);

                foreach (var prop in obj.Properties())
                {
                    if (prop.Name == "activity")
                    {
                        return(EnrichedActivity.FromJson((JObject)prop.Value));
                    }
                }

                return(null);
            }