public void GetUser(string userId, Action <IFizzUser, FizzException> callback) { IfOpened(() => { string path = string.Format(FizzConfig.API_PATH_USER, userId); _client.Get(FizzConfig.API_BASE_URL, path, (response, ex) => { if (ex != null) { FizzUtils.DoCallback <IFizzUser>(null, ex, callback); } else { try { JSONNode userResponse = JSONNode.Parse(response); FizzJsonUser user = new FizzJsonUser(userId, userResponse); FizzUtils.DoCallback <IFizzUser>(user, null, callback); } catch { FizzUtils.DoCallback <IFizzUser>(null, ERROR_INVALID_RESPONSE_FORMAT, callback); } } }); }); }
public void Next(Action <IList <IFizzUserGroup>, FizzException> callback) { string path = string.Format(FizzConfig.API_PATH_USER_GROUPS, _userId) + "?page_size=100"; if (_next != null && _next != string.Empty) { path += "&page=" + _next; } _restClient.Get(FizzConfig.API_BASE_URL, path, (response, ex) => { if (ex != null) { FizzUtils.DoCallback <IList <IFizzUserGroup> >(null, ex, callback); } else { try { FizzUtils.DoCallback <IList <IFizzUserGroup> >(ParseResponse(response), null, callback); } catch { FizzUtils.DoCallback <IList <IFizzUserGroup> >(null, FizzRestClient.ERROR_INVALID_RESPONSE_FORMAT, callback); } } }); }
public void FetchGroup(string groupId, Action <IFizzGroup, FizzException> callback) { IfOpened(() => { string path = string.Format(FizzConfig.API_PATH_GROUP, groupId); _restClient.Get(FizzConfig.API_BASE_URL, path, (response, ex) => { if (ex != null) { FizzUtils.DoCallback <IFizzGroup> (null, ex, callback); } else { FizzUtils.DoCallback <IFizzGroup>(new FizzJsonGroup(response), null, callback); } }); }); }
public void QueryLatest(string channel, int count, long beforeId, Action <IList <FizzChannelMessage>, FizzException> callback) { IfOpened(() => { if (string.IsNullOrEmpty(channel)) { FizzUtils.DoCallback <IList <FizzChannelMessage> > (null, ERROR_INVALID_CHANNEL, callback); return; } if (count < 0) { FizzUtils.DoCallback <IList <FizzChannelMessage> > (null, ERROR_INVALID_MESSAGE_QUERY_COUNT, callback); return; } if (count == 0) { FizzUtils.DoCallback <IList <FizzChannelMessage> > (new List <FizzChannelMessage> (), null, callback); return; } string path = string.Format(FizzConfig.API_PATH_MESSAGES, channel) + "?count=" + count; if (beforeId > 0) { path += "&before_id=" + beforeId; } _restClient.Get(FizzConfig.API_BASE_URL, path, (response, ex) => { if (ex != null) { FizzUtils.DoCallback <IList <FizzChannelMessage> > (null, ex, callback); } else { try { JSONArray messagesArr = JSONNode.Parse(response).AsArray; IList <FizzChannelMessage> messages = new List <FizzChannelMessage> (); foreach (JSONNode message in messagesArr.Childs) { messages.Add(new FizzJsonChannelMessage(message)); } FizzUtils.DoCallback <IList <FizzChannelMessage> > (messages, null, callback); } catch { FizzUtils.DoCallback <IList <FizzChannelMessage> > (null, ERROR_INVALID_RESPONSE_FORMAT, callback); } } }); }); }