public async Task FollowMany(IEnumerable <Follow> follows, int activityCopyLimit = StreamClient.ActivityCopyLimitDefault) { if (activityCopyLimit < 0) { throw new ArgumentOutOfRangeException("activityCopyLimit", "Activity copy limit must be greater than or equal to 0"); } if (activityCopyLimit > StreamClient.ActivityCopyLimitMax) { throw new ArgumentOutOfRangeException("activityCopyLimit", string.Format("Activity copy limit must be less than or equal to {0}", StreamClient.ActivityCopyLimitMax)); } var request = _client.BuildAppRequest("follow_many/", HttpMethod.POST); request.AddQueryParameter("activity_copy_limit", activityCopyLimit.ToString()); request.SetJsonBody(JsonConvert.SerializeObject(from f in follows select new { source = f.Source, target = f.Target })); _client.SignRequest(request); var response = await _client.MakeRequest(request); if (response.StatusCode != System.Net.HttpStatusCode.Created) { throw StreamException.FromResponse(response); } }
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); }
public async Task <IEnumerable <Follower> > Following(int offset = 0, int limit = 25, String[] filterBy = 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, "/following/", Method.GET); request.AddQueryParameter("offset", offset.ToString()); request.AddQueryParameter("limit", limit.ToString()); if (filterBy.SafeCount() > 0) { request.AddQueryParameter("filter", String.Join(",", filterBy)); } var response = await _client.MakeRequest(request); if (response.StatusCode != System.Net.HttpStatusCode.OK) { throw StreamException.FromResponse(response); } return(JsonConvert.DeserializeObject <FollowersResponse>(response.Content).results); }
public async Task <IEnumerable <Activity> > GetActivities(int offset = 0, int limit = 20, FeedFilter filter = null, ActivityMarker marker = null) { var request = _client.BuildRequest(this, "/", Method.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(GetResults(response.Content)); } throw StreamException.FromResponse(response); }
public async Task FollowMany(IEnumerable <Follow> follows, int activityCopyLimit = CopyLimitDefault) { var request = _client.BuildAppRequest("follow_many/", RestSharp.Method.POST); if (activityCopyLimit != CopyLimitDefault) { request.AddQueryParameter("activity_copy_limit", activityCopyLimit.ToString()); } request.AddJsonBody(from f in follows select new { source = f.Source, target = f.Target }); _client.SignRequest(request); var response = await _client.MakeRequest(request); if (response.StatusCode != System.Net.HttpStatusCode.Created) { throw StreamException.FromResponse(response); } }
public async Task FollowFeed(StreamFeed feedToFollow) { if (feedToFollow == null) { throw new ArgumentNullException("feedToFollow", "Must have a feed to follow"); } if (feedToFollow.FeedTokenId == this.FeedTokenId) { throw new ArgumentException("Cannot follow myself"); } var request = _client.BuildRequest(this, "/follows/", Method.POST); request.AddJsonBody(new { target = feedToFollow.FeedId, target_token = feedToFollow.Token }); var response = await _client.MakeRequest(request); if (response.StatusCode != System.Net.HttpStatusCode.Created) { throw StreamException.FromResponse(response); } }
public async Task FollowFeed(StreamFeed feedToFollow, int activityCopyLimit = StreamClient.ActivityCopyLimitDefault) { if (feedToFollow == null) { throw new ArgumentNullException("feedToFollow", "Must have a feed to follow"); } if (feedToFollow.FeedTokenId == this.FeedTokenId) { throw new ArgumentException("Cannot follow myself"); } if (activityCopyLimit < 1) { throw new ArgumentOutOfRangeException("activityCopyLimit", "Activity copy limit must be greater than 0"); } if (activityCopyLimit > StreamClient.ActivityCopyLimitMax) { throw new ArgumentOutOfRangeException("activityCopyLimit", string.Format("Activity copy limit must be less than or equal to {0}", StreamClient.ActivityCopyLimitMax)); } var request = _client.BuildFeedRequest(this, "/following/", HttpMethod.POST); request.SetJsonBody(JsonConvert.SerializeObject(new { target = feedToFollow.FeedId, activity_copy_limit = activityCopyLimit, target_token = feedToFollow.Token })); var response = await _client.MakeRequest(request); if (response.StatusCode != System.Net.HttpStatusCode.Created) { throw StreamException.FromResponse(response); } }
public async Task FollowFeed(IStreamFeed feedToFollow, int activityCopyLimit = StreamClient.ActivityCopyLimitDefault) { ValidateFeedFollow(feedToFollow); if (activityCopyLimit < 0) { throw new ArgumentOutOfRangeException("activityCopyLimit", "Activity copy limit must be greater than or equal to 0"); } if (activityCopyLimit > StreamClient.ActivityCopyLimitMax) { throw new ArgumentOutOfRangeException("activityCopyLimit", string.Format("Activity copy limit must be less than or equal to {0}", StreamClient.ActivityCopyLimitMax)); } var request = _client.BuildFeedRequest(this, "/following/", HttpMethod.POST); request.SetJsonBody(JsonConvert.SerializeObject(new { target = feedToFollow.FeedId, activity_copy_limit = activityCopyLimit, })); var response = await _client.MakeRequest(request); if (response.StatusCode != System.Net.HttpStatusCode.Created) { throw StreamException.FromResponse(response); } }
internal async Task <StreamResponse <T> > GetWithOptions <T>(GetOptions options = null) where T : Activity { // build request options = options ?? GetOptions.Default; var request = _client.BuildRequest(this, "/", Method.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 => Activity.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); }
public async Task UpdateActivities(IEnumerable<Activity> activities) { var request = _client.BuildJWTAppRequest("activities/", HttpMethod.POST); request.SetJsonBody(Activity.ToActivitiesJson(activities, this._client)); var response = await this._client.MakeRequest(request); if (response.StatusCode != System.Net.HttpStatusCode.Created) throw StreamException.FromResponse(response); }
/// <summary> /// Delete the feed /// </summary> public async Task Delete() { var request = _client.BuildRequest(this, "/", Method.DELETE); var response = await _client.MakeRequest(request); if (response.StatusCode != System.Net.HttpStatusCode.OK) { throw StreamException.FromResponse(response); } }
public async Task <IEnumerable <Reaction> > Filter(ReactionFiltering filtering, ReactionPagination pagination) { var response = await FilterHelper(filtering, pagination); if (response.StatusCode == System.Net.HttpStatusCode.OK) { return(JsonConvert.DeserializeObject <ReactionsFilterResponse>(response.Content).Reactions); } throw StreamException.FromResponse(response); }
public async Task Delete(string userID) { var request = this._client.BuildJWTAppRequest($"user/{userID}/", HttpMethod.DELETE); var response = await this._client.MakeRequest(request); if (response.StatusCode != System.Net.HttpStatusCode.OK) { throw StreamException.FromResponse(response); } }
public async Task Delete(string collectionName, string ID) { var request = this._client.BuildAppRequest($"collections/{collectionName}/{ID}/", HttpMethod.DELETE); var response = await this._client.MakeRequest(request); if (response.StatusCode != System.Net.HttpStatusCode.OK) { throw StreamException.FromResponse(response); } }
public async Task <CollectionObject> Get(string collectionName, string ID) { var request = this._client.BuildAppRequest($"collections/{collectionName}/{ID}/", HttpMethod.GET); var response = await this._client.MakeRequest(request); if (response.StatusCode != System.Net.HttpStatusCode.OK) { throw StreamException.FromResponse(response); } return(CollectionObject.FromJSON(JObject.Parse(response.Content))); }
public async Task AddToMany(Activity activity, IEnumerable<string> feedIds) { var request = _client.BuildAppRequest("feed/add_to_many/", HttpMethod.POST); request.SetJsonBody( "{" + string.Format("\"activity\": {0}, \"feeds\": {1}", activity.ToJson(this._client), JsonConvert.SerializeObject(feedIds)) + "}" ); _client.SignRequest(request); var response = await _client.MakeRequest(request); if (response.StatusCode != System.Net.HttpStatusCode.Created) throw StreamException.FromResponse(response); }
public async Task <Reaction> Get(string reactionID) { var request = this._client.BuildJWTAppRequest($"reaction/{reactionID}/", HttpMethod.GET); var response = await this._client.MakeRequest(request); if (response.StatusCode == System.Net.HttpStatusCode.OK) { return(JsonConvert.DeserializeObject <Reaction>(response.Content)); } throw StreamException.FromResponse(response); }
public async Task DeleteMany(string collectionName, IEnumerable <string> ids) { var request = this._client.BuildAppRequest("collections/", HttpMethod.DELETE); request.AddQueryParameter("collection_name", collectionName); request.AddQueryParameter("ids", string.Join(",", ids)); var response = await this._client.MakeRequest(request); if (response.StatusCode != System.Net.HttpStatusCode.OK) { throw StreamException.FromResponse(response); } }
public async Task ActivitiesPartialUpdate(IEnumerable<ActivityPartialUpdateRequestObject> updates) { var request = this._client.BuildJWTAppRequest("activity/", HttpMethod.POST); var requestData = new Dictionary<string, object>(){ {"changes", updates.Select(x => x.ToJObject())} }; request.SetJsonBody(JsonConvert.SerializeObject(requestData)); var response = await this._client.MakeRequest(request); if (response.StatusCode != System.Net.HttpStatusCode.Created) throw StreamException.FromResponse(response); }
public async Task <IDictionary <string, object> > Post(string endpoint, IDictionary <string, object> data) { var request = this._client.BuildPersonalizationRequest(endpoint + "/", HttpMethod.POST); request.SetJsonBody(JsonConvert.SerializeObject(data)); var response = await this._client.MakeRequest(request); if ((int)response.StatusCode < 300) { return(JsonConvert.DeserializeObject <Dictionary <string, object> >(response.Content)); } throw StreamException.FromResponse(response); }
public async Task UnfollowFeed(IStreamFeed feedToUnfollow, bool keepHistory = false) { ValidateFeedFollow(feedToUnfollow); var request = _client.BuildFeedRequest(this, "/following/" + feedToUnfollow.FeedId + "/", HttpMethod.DELETE); request.AddQueryParameter("keep_history", keepHistory.ToString()); var response = await _client.MakeRequest(request); if (response.StatusCode != System.Net.HttpStatusCode.OK) { throw StreamException.FromResponse(response); } }
/// <summary> /// Remove an activity /// </summary> /// <param name="activityId"></param> /// <param name="foreignId"></param> /// <returns></returns> public async Task RemoveActivity(String activityId, bool foreignId = false) { var request = _client.BuildRequest(this, "/" + activityId + "/", Method.DELETE); if (foreignId) { request.AddQueryParameter("foreign_id", "1"); } var response = await _client.MakeRequest(request); if (response.StatusCode != System.Net.HttpStatusCode.OK) { throw StreamException.FromResponse(response); } }
private async Task <Reaction> Add(Reaction r) { var request = this._client.BuildJWTAppRequest("reaction/", HttpMethod.POST); request.SetJsonBody(JsonConvert.SerializeObject(r)); var response = await this._client.MakeRequest(request); if (response.StatusCode == System.Net.HttpStatusCode.Created) { return(JsonConvert.DeserializeObject <Reaction>(response.Content)); } throw StreamException.FromResponse(response); }
public async Task <CollectionObject> Update(string collectionName, string ID, GenericData data) { var dataJson = new JObject(new JProperty("data", data.ToJObject())); var request = this._client.BuildAppRequest($"collections/{collectionName}/{ID}/", HttpMethod.PUT); request.SetJsonBody(dataJson.ToString()); var response = await this._client.MakeRequest(request); if (response.StatusCode != System.Net.HttpStatusCode.Created) { throw StreamException.FromResponse(response); } return(CollectionObject.FromJSON(JObject.Parse(response.Content))); }
public async Task Delete(string endpoint, IDictionary <string, object> data) { var request = this._client.BuildPersonalizationRequest(endpoint + "/", HttpMethod.DELETE); foreach (KeyValuePair <string, object> entry in data) { request.AddQueryParameter(entry.Key, Convert.ToString(entry.Value)); } var response = await this._client.MakeRequest(request); if ((int)response.StatusCode >= 300) { throw StreamException.FromResponse(response); } }
public async Task <IEnumerable <CollectionObject> > SelectMany(string collectionName, IEnumerable <string> ids) { var foreignIds = ids.Select(x => string.Format("{0}:{1}", collectionName, x)); var request = this._client.BuildAppRequest("collections/", HttpMethod.GET); request.AddQueryParameter("foreign_ids", string.Join(",", foreignIds)); var response = await this._client.MakeRequest(request); if (response.StatusCode == System.Net.HttpStatusCode.OK) { return(Collections.GetResults(response.Content)); } throw StreamException.FromResponse(response); }
public async Task UpsertMany(string collectionName, IEnumerable <CollectionObject> data) { var dataJson = new JObject( new JProperty("data", new JObject( new JProperty(collectionName, data.Select(x => x.ToJObject()))))); var request = this._client.BuildAppRequest("collections/", HttpMethod.POST); request.SetJsonBody(dataJson.ToString()); var response = await this._client.MakeRequest(request); if (response.StatusCode != System.Net.HttpStatusCode.Created) { throw StreamException.FromResponse(response); } }
public async Task <ReactionsWithActivity> FilterWithActivityData(ReactionFiltering filtering, ReactionPagination pagination) { var response = await FilterHelper(filtering.WithActivityData(), pagination); if (response.StatusCode == System.Net.HttpStatusCode.OK) { var reactions = JsonConvert.DeserializeObject <ReactionsFilterResponse>(response.Content).Reactions; var activity = ReactionsFilterResponse.GetActivity(response.Content); return(new ReactionsWithActivity { Reactions = reactions, Activity = activity }); } throw StreamException.FromResponse(response); }
public async Task <IDictionary <string, object> > Get(string endpoint, IDictionary <string, object> data) { var request = this._client.BuildPersonalizationRequest(endpoint + "/", HttpMethod.GET); foreach (KeyValuePair <string, object> entry in data) { request.AddQueryParameter(entry.Key, Convert.ToString(entry.Value)); } var response = await this._client.MakeRequest(request); if ((int)response.StatusCode < 300) { return(JsonConvert.DeserializeObject <Dictionary <string, object> >(response.Content)); } throw StreamException.FromResponse(response); }
public async Task UnfollowFeed(StreamFeed feedToUnfollow) { if (feedToUnfollow == null) { throw new ArgumentNullException("feedToUnfollow", "Must have a feed to unfollow"); } if (feedToUnfollow.FeedTokenId == this.FeedTokenId) { throw new ArgumentException("Cannot unfollow myself"); } var request = _client.BuildRequest(this, "/follows/" + feedToUnfollow.FeedId + "/", Method.DELETE); var response = await _client.MakeRequest(request); if (response.StatusCode != System.Net.HttpStatusCode.OK) { throw StreamException.FromResponse(response); } }