//如果還沒有json blob的url,就create一個,並回傳url path private string initDefaultStruct() { var data = new ArchiveHouse(); var response = makeApiRequest("", Method.POST, data); string location = response.Headers .Where(x => x.Name == "Location") .Select(x => x.Value) .FirstOrDefault().ToString(); var match = Regex.Match(location, ".*jsonBlob/(.+)"); var token = match.Groups[1].Value; return(token); }
//取得已發送過通知的房屋列表,並過濾出沒發送通知的列表 public IEnumerable <houseEntity> GetShouldAlertHouse(IEnumerable <houseEntity> houseList, ArchiveHouse archiveHouse) { if (archiveHouse.houseList != null && archiveHouse.houseList.Count > 0) { var archiveIds = archiveHouse.houseList.Select(x => x.postId).ToList(); return(houseList.Where(x => !archiveIds.Contains(x.post_id))); } else { return(houseList); } }
private IRestResponse makeApiRequest(string routeUrl, Method method = Method.GET, ArchiveHouse data = null) { var client = new RestClient(jsonBlobUrl); RestRequest request; if (string.IsNullOrEmpty(routeUrl)) { request = new RestRequest(); } else { request = new RestRequest(routeUrl); } IRestResponse response; request.Method = method; if (method != Method.GET && data != null) { request.AddHeader("Accept", "application/json"); request.AddJsonBody(data); response = client.Execute(request); } else { response = client.Get(request); } return(response); }