public void TestRefWithCollection() { var collectionObj = new Stream.CollectionObject("id-col"); var refString = Stream.Collections.Ref("col", collectionObj); Assert.AreEqual("SO:col:id-col", refString); }
internal static CollectionObject FromJSON(JObject obj) { CollectionObject result = new CollectionObject(); obj.Properties().ForEach(prop => { switch (prop.Name) { case "id": result.ID = prop.Value.Value <string>(); break; case "user_id": result.UserID = prop.Value.Value <string>(); break; case "data": { var dataObj = prop.Value as JObject; dataObj.Properties().ForEach(p => { result.SetData(p.Name, p.Value); }); break; } } }); return(result); }
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 <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))); }
internal static CollectionObject FromJSON(JObject obj) { CollectionObject result = new CollectionObject(); obj.Properties().ForEach(prop => { switch (prop.Name) { case "id": result.ID = prop.Value.Value <string>(); break; default: result._data.SetData(prop.Name, prop.Value); break; } }); return(result); }
private static IEnumerable <CollectionObject> GetResults(string json) { var obj = JObject.Parse(json); var response = obj.Property("response").Value as JObject; var data = response.Property("data").Value as JArray; foreach (var result in data) { var resultObj = result as JObject; var foreignID = resultObj.Property("foreign_id").Value.Value <string>(); var objectID = foreignID.Split(':')[1]; var objectData = resultObj.Property("data").Value as JObject; var collectionObject = CollectionObject.FromBatchJSON(objectData); collectionObject.ID = objectID; yield return(collectionObject); } }
public async Task <CollectionObject> Add(string collectionName, GenericData data, string ID = null, string userID = null) { var collectionObject = new CollectionObject() { ID = ID, UserID = userID, _data = data, }; var request = this._client.BuildAppRequest($"collections/{collectionName}/", HttpMethod.POST); request.SetJsonBody(collectionObject.ToJson()); 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 static string Ref(string collectionName, CollectionObject obj) { return(Ref(collectionName, obj.ID)); }
public async Task Upsert(string collectionName, CollectionObject data) { await this.UpsertMany(collectionName, new CollectionObject[] { data }); }