Exemple #1
0
        /// <summary>
        /// WebAPI接続によるMLBのチームデータ取得
        /// </summary>
        /// <returns>リーグごと・地区ごとのチームデータ</returns>
        public async Task <Result> GetStandingData(Param param)
        {
            string uri = _endpoint + param.Year;
            Dictionary <string, string> headers = new Dictionary <string, string>
            {
                { "Ocp-Apim-Subscription-Key", _apiKey }
            };

            // WebAPIコールアウト
            HttpResponseMessage response =
                await ProcessUtility.CalloutAsync(_client, "GET", uri, headers, null);

            if (!response.IsSuccessStatusCode)
            {
                // WebAPIレスポンスが200台:OK以外の場合は例外発生
                throw new Exception();
            }

            string responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            Result result = new Result
            {
                ResultTeamList = JsonConvert.DeserializeObject <List <DetailResult> >(responseBody)
            };

            return(result);
        }