// get Data from MAtch API public JObject getData() { ResMethods rs = new ResMethods(); String Endpoint = "https://rest.cricketapi.com/rest/v2/match/" + match_key + "/?access_token=" + rs.getAuth_Token(); String res_str_json = res.MakeRequest(Endpoint); RootObject1 ro1 = JsonConvert.DeserializeObject <RootObject1>(res_str_json); var schedule_str = ro1.data.ToString(); return(JObject.Parse(schedule_str)); }
public string getAuth_Token() { HttpReqRes res = new HttpReqRes(); // Req to Auth API string json_str = res.MakeRequest(null); RootObject ro = JsonConvert.DeserializeObject <RootObject>(json_str); // getting the access token string access_token = ro.auth.access_token.ToString(); return(access_token); }
private static IList <Attachment> Top_GetCardsAttachments() { HttpReqRes res = new HttpReqRes(); string res_topnews = res.MakeRequest(); RootObject ro = JsonConvert.DeserializeObject <RootObject>(res_topnews); // foreach (var v in ro.articles) //{ String auth = "Author" + ro.articles[0].author; //Uri uri = new Uri(ro.articles[0].url); // foreach(var v in ro.articles) { return(new List <Attachment>() {//foreach (var v in ro.articles) { GetHeroCard( ro.articles[0].title, auth, ro.articles[0].description, new CardImage(url: ro.articles[0].urlToImage), new CardAction(ActionTypes.OpenUrl, "Learn more", value: ro.articles[0].url)), GetHeroCard( ro.articles[1].title, auth, ro.articles[1].description, new CardImage(url: ro.articles[1].urlToImage), new CardAction(ActionTypes.OpenUrl, "Learn more", value: ro.articles[1].url)), GetHeroCard( ro.articles[2].title, auth, ro.articles[2].description, new CardImage(url: ro.articles[2].urlToImage), new CardAction(ActionTypes.OpenUrl, "Learn more", value: ro.articles[2].url)), GetHeroCard( ro.articles[3].title, auth, ro.articles[3].description, new CardImage(url: ro.articles[3].urlToImage), new CardAction(ActionTypes.OpenUrl, "Learn more", value: ro.articles[3].url)), GetHeroCard( ro.articles[4].title, auth, ro.articles[4].description, new CardImage(url: ro.articles[4].urlToImage), new CardAction(ActionTypes.OpenUrl, "Learn more", value: ro.articles[4].url)), }); }
private static IList <Attachment> Top_GetCardsAttachments() { HttpReqRes res = new HttpReqRes(); string EndPoint = "https://newsapi.org/v1/articles?source=espn-cric-info&sortBy=top&apiKey=70ecac24214846759b5ca1eb23c25329"; string res_topnews = res.MakeRequest(EndPoint); RootObject ro = JsonConvert.DeserializeObject <RootObject>(res_topnews); String auth = "Author" + ro.articles[0].author; return(new List <Attachment>() { GetHeroCard( ro.articles[0].title, auth, ro.articles[0].description, new CardImage(url: ro.articles[0].urlToImage), new CardAction(ActionTypes.OpenUrl, "Learn more", value: ro.articles[0].url)), GetHeroCard( ro.articles[1].title, auth, ro.articles[1].description, new CardImage(url: ro.articles[1].urlToImage), new CardAction(ActionTypes.OpenUrl, "Learn more", value: ro.articles[1].url)), GetHeroCard( ro.articles[2].title, auth, ro.articles[2].description, new CardImage(url: ro.articles[2].urlToImage), new CardAction(ActionTypes.OpenUrl, "Learn more", value: ro.articles[2].url)), GetHeroCard( ro.articles[3].title, auth, ro.articles[3].description, new CardImage(url: ro.articles[3].urlToImage), new CardAction(ActionTypes.OpenUrl, "Learn more", value: ro.articles[3].url)), GetHeroCard( ro.articles[4].title, auth, ro.articles[4].description, new CardImage(url: ro.articles[4].urlToImage), new CardAction(ActionTypes.OpenUrl, "Learn more", value: ro.articles[4].url)), }); }
/*public List<string> getMatches_DateList() * { * // List<string> matches_title = new List<string>(); * // string Endpoint = ""; * HttpReqRes res = new HttpReqRes(); * List<String> key = new List<string>(); * //for (int i = 0; i < s_keys.Count(); i++) * //{ * * // Recent Matches API * HttpReqRes res1 = new HttpReqRes(); * //https://rest.cricketapi.com/rest/v2/season/" + s_keys[i] + "/recent_matches/?access_token=" + getAuth_Token() * String Endpoint_recent_matches = "https://rest.cricketapi.com/rest/v2/recent_matches/?access_token=" + getAuth_Token(); * String json_str_recent_matches = res1.MakeRequest(Endpoint_recent_matches); * RootObject1 ro = JsonConvert.DeserializeObject<RootObject1>(json_str_recent_matches); * var data_str = ro.data.ToString(); * var data_obj = JObject.Parse(data_str); * JArray card = (JArray)data_obj["cards"]; * * //gets the keys to list * for (int j = 0; j < card.Count(); j++) * { * /*await connector.Conversations.ReplyToActivityAsync(activity.CreateReply($" Match Key : {card[i]["title"]}" + Environment.NewLine + * Environment.NewLine + $"{card[i]["status"]}")); * DateTime dt = DateTime.Parse(card[j]["start_date"]["iso"].ToString()); * string match_time = dt.ToLocalTime().ToShortTimeString(); * key.Add(DateTime.Parse(match_time).ToLocalTime().ToString()); * } * //} * return key; * }*/ /*public JObject getResponse() * { * HttpReqRes res = new HttpReqRes(); * * // Match API * String Endpoint_match = "https://rest.cricketapi.com/rest/v2/match/engrsa_2017_t20_01/?access_token=" + getAuth_Token(); * String json_str_match = res.MakeRequest(Endpoint_match); * RootObject1 ro_match = JsonConvert.DeserializeObject<RootObject1>(json_str_match); * var mdata_str = ro_match.data.ToString(); * var mdata_obj = JObject.Parse(mdata_str); * * return mdata_obj; * }*/ public List <string> getAllRecentList() { HttpReqRes res = new HttpReqRes(); // Recent Matches API String Endpoint_recent_matches = "https://rest.cricketapi.com/rest/v2/recent_matches/?access_token=" + getAuth_Token(); String json_str_recent_matches = res.MakeRequest(Endpoint_recent_matches); RootObject1 ro = JsonConvert.DeserializeObject <RootObject1>(json_str_recent_matches); var data_str = ro.data.ToString(); var data_obj = JObject.Parse(data_str); JArray card = (JArray)data_obj["cards"]; List <String> key = new List <string>(); //gets the keys to list for (int i = 0; i < card.Count(); i++) { key.Add(card[i]["key"].ToString()); } List <string> recent_upcoming = new List <string>(); List <string> recent_upcoming_status = new List <string>(); List <string> recent_today = new List <string>(); List <string> recent_today_status = new List <string>(); List <string> recent_completed = new List <string>(); List <string> recent_completed_status = new List <string>(); for (int k = 0; k < card.Count(); k++) { // today matches if (DateTime.Parse(card[k]["start_date"]["iso"].ToString()).Date == DateTime.Parse(DateTime.Now.ToString()).Date) { //recent_today.Add(card[k]["name"].ToString() + "-" + card[k]["related_name"].ToString()); // compare with current time & status started if (DateTime.Parse(card[k]["start_date"]["iso"].ToString()).ToLocalTime() >= DateTime.Parse(DateTime.Now.ToString())) { recent_today.Add(card[k]["name"].ToString() + "-" + card[k]["related_name"].ToString() + "-Start at: " + DateTime.Parse(card[k]["start_date"]["iso"].ToString()).ToLocalTime()); } else { recent_today.Add(card[k]["name"].ToString() + "-" + card[k]["related_name"].ToString() + "- Match Started"); } } // completed else if (DateTime.Parse(card[k]["start_date"]["iso"].ToString()).Date < DateTime.Parse(DateTime.Now.ToString()).Date) { recent_completed.Add(card[k]["name"].ToString() + "-" + card[k]["related_name"].ToString()); } // upcoming else { recent_upcoming.Add(card[k]["name"].ToString() + "-" + card[k]["related_name"].ToString()); } } List <string> All = new List <string>(); // adds recent to all list for (int v = 0; v < recent_today.Count(); v++) { All.Add(recent_today[v]); } // adds upcoming to all list for (int v = 0; v < recent_upcoming.Count(); v++) { All.Add(recent_upcoming[v]); } for (int v = 0; v < recent_completed.Count(); v++) { All.Add(recent_completed[v]); } /* for (int v = 0; v < All.Count(); v++) * { * await connector.Conversations.ReplyToActivityAsync(activity.CreateReply($" {All[v]}")); * // All.Add(recent_today[v] + "--" + recent_today_status[v]); * }*/ return(All); }