public void PostThread(int forumId, string title, string content, SuccessfulCallback scb, ErrorCallback ecb) { if (!LoggedIn) { ecb("Not logged in!", null); return; } RequestData("author/thread/?contents=" + content + "&forumid=" + forumId + "&title=" + title + "&_t=" + _sessionToken + "&_u=" + User.UserID , RequestType.GET, w => { }, data => { JObject root = JObject.Parse(data); string statusText = (string)root["status"]; Status status = Status.FAILURE; if (statusText.ToLower() == "ok") { status = Status.OK; } if (status == Status.OK) { scb("Successfully posted!"); //TODO: what's in this data } else { ecb((string)root["message"], null); } }, (err, ex) => { ecb("Failed to post", ex); }); }
public void PostInThread(int forumId, int threadId, string content, SuccessfulCallback scb, ErrorCallback ecb) { if (!LoggedIn) { ecb("Not logged in!", null); return; } if (forumId == 62) //Gold users can actually post in the camp - so yeah. no. { ecb("You cannot post in the Refugee Camp from this app.", null); return; } RequestData("author/post/?contents=" + content + "&threadid=" + threadId + "&_t=" + _sessionToken + "&_u=" + User.UserID, RequestType.GET, w => { }, data => { JObject root = JObject.Parse(data); string statusText = (string)root["status"]; Status status = Status.FAILURE; if (statusText.ToLower() == "ok") { status = Status.OK; } if (status == Status.OK) { scb("Successfully posted!"); //{"status":"ok","data":{"postid":43890609}} //nothing useful. } else { ecb((string)root["message"], null); } }, (err, ex) => { ecb("Failed to post", ex); }); }
public void GetForums(SuccessfulCallback scb, ErrorCallback ecb) { string url = "forum/list?"; if (LoggedIn) { url += "&_t=" + _sessionToken + "&_u=" + User.UserID; } RequestData(url, RequestType.GET, wb => { }, data => { JObject root = JObject.Parse(data); string status = (string)root["status"]; //todo Forums = new List <Forum>(); foreach (JObject obj in root["data"]) { int forumId = (int)obj["forumid"]; int parentId = (int)obj["parentid"]; string title = (string)obj["title"]; string description = (string)obj["description"]; if (forumId == 51) //Remove html... { description = "Holy shit! It's the news!"; } int postCount = (int)obj["postcount"]; int threadCount = (int)obj["threadcount"]; string threadTitle = (string)obj["thread_title"]; int threadId = (int)obj["thread_id"]; int threadDate = (int)obj["thread_date"]; int threadPostId = (int)obj["thread_postid"]; string author = (string)obj["thread_username"]; int userId = (int)obj["thread_userid"]; User user = new User() { Name = author, UserID = userId }; Thread thread = new Thread() { Author = user, LastPostTimestamp = threadDate, ThreadID = threadId, Title = threadTitle }; Forum forum = new Forum() { Description = description, LatestThread = thread, ParentID = parentId, ForumID = forumId, PostCount = postCount, ThreadCount = threadCount, Title = title }; for (int i = 0; i < forumOrder.Length; i++) { if (forumOrder[i] == forum.ForumID) { forum.OrderPriority = i; } } Forums.Add(forum); } //Hacky way to make it ordered "right". Forums = Forums.OrderBy(f => f.OrderPriority).ToList(); //.ThenBy(f => f.ForumID).ToList(); //Forums.Sort((x, y) => { return x.ParentID.CompareTo(y.ParentID); }); scb("Success."); }, ecb); }
private void RequestData(string url, RequestType type, WriteDataCallback write, SuccessfulCallback success, ErrorCallback error) { try { //Prevent caching by adding the datetime. WP y u so dum... var request = WebRequest.CreateHttp(BaseUrl + url + "&nocache=" + DateTime.Now.Ticks.ToString()); if (type == RequestType.POST) { request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; } else { request.Method = "GET"; } request.CookieContainer = _cookies; request.UserAgent = request.UserAgent; if (type == RequestType.POST) { request.BeginGetRequestStream(cb => { using (var sr = new StreamWriter(request.EndGetRequestStream(cb))) { write(sr); } request.BeginGetResponse( a => { try { var response = (HttpWebResponse)request.EndGetResponse(a); var responseStream = response.GetResponseStream(); using (var sr = new StreamReader(responseStream)) { success(sr.ReadToEnd()); } } catch (WebException ex) { error("Web exception", ex); } }, null); }, null); } else { request.BeginGetResponse( a => { try { var response = (HttpWebResponse)request.EndGetResponse(a); var responseStream = response.GetResponseStream(); using (var sr = new StreamReader(responseStream)) { string result = sr.ReadToEnd(); success(result); } } catch (WebException ex) { error("GET exception", ex); } }, null); } } catch (WebException ex) { error("Web exception", ex); } }