public AddressSearchForm(IAddressSearchService addressSearchService) { _addressSearchService = addressSearchService ?? AddressSearchServiceImpl.Current; InitializeComponent(); AddressResult = AddressResult.Empty(); }
public async Task <AddressResult> Search(string postalCode) { var query = HttpUtility.ParseQueryString(string.Empty); query["lang"] = "ja"; query["zipcode"] = postalCode; var response = await _client.GetAsync($"http://api.zipaddress.net/?{query}"); var json = await response.Content.ReadAsStringAsync(); dynamic o = JObject.Parse(json); if (o.code == "200") { dynamic data = o.data; return(AddressResult.Success(postalCode, (string)data.pref, (string)data.city, (string)data.town)); } return(AddressResult.Empty()); }
private async void button1_Click(object sender, EventArgs e) { AddressResult = await _addressSearchService.Search(input.Text); }