public async Task <IEnumerable <Activity> > GetActivities(IEnumerable <string> ids = null, IEnumerable <ForeignIDTime> foreignIDTimes = null)
        {
            if (ids == null && foreignIDTimes == null)
            {
                throw new ArgumentException("one of the parameters ids or foreignIdTimes must be provided and not null", "ids, foreignIDTimes");
            }
            if (ids != null && foreignIDTimes != null)
            {
                throw new ArgumentException("at most one of the parameters ids or foreignIdTimes must be provided", "ids, foreignIDTimes");
            }

            var request = _client.BuildJWTAppRequest("activities/", HttpMethod.GET);

            if (ids != null)
            {
                request.AddQueryParameter("ids", string.Join(",", ids));
            }

            if (foreignIDTimes != null)
            {
                request.AddQueryParameter("foreign_ids", string.Join(",", foreignIDTimes.Select(f => f.ForeignID)));
                request.AddQueryParameter("timestamps", string.Join(",", foreignIDTimes.Select(f =>
                                                                                               f.Time.ToString("s", System.Globalization.CultureInfo.InvariantCulture))));
            }

            var response = await _client.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                return(Activity.GetResults(response.Content));
            }

            throw StreamException.FromResponse(response);
        }
Exemple #2
0
        /// <summary>
        /// Add a list of activities
        /// </summary>
        /// <param name="activities"></param>
        /// <returns></returns>
        public async Task <IEnumerable <Activity> > AddActivities(IEnumerable <Activity> activities)
        {
            if (activities.SafeCount() == 0)
            {
                throw new ArgumentNullException("activities", "Must have activities to add");
            }

            var request = _client.BuildFeedRequest(this, "/", HttpMethod.POST);

            request.SetJsonBody(Activity.ToActivitiesJson(activities, this._client));

            var response = await _client.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.Created)
            {
                return(Activity.GetResults(response.Content));
            }

            throw StreamException.FromResponse(response);
        }
Exemple #3
0
        public async Task <IEnumerable <Activity> > GetActivities(int offset = 0, int limit = 20, FeedFilter filter = null, ActivityMarker marker = null)
        {
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", "Offset must be greater than or equal to zero");
            }
            if (limit < 0)
            {
                throw new ArgumentOutOfRangeException("limit", "Limit must be greater than or equal to zero");
            }

            var request = _client.BuildFeedRequest(this, "/", HttpMethod.GET);

            request.AddQueryParameter("offset", offset.ToString());
            request.AddQueryParameter("limit", limit.ToString());

            // filter if needed
            if (filter != null)
            {
                filter.Apply(request);
            }

            // marker if needed
            if (marker != null)
            {
                marker.Apply(request);
            }

            var response = await _client.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                return(Activity.GetResults(response.Content));
            }

            throw StreamException.FromResponse(response);
        }