Skip to content

Instantly share code, notes, and snippets.

@bertt
Last active December 15, 2015 03:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bertt/5197922 to your computer and use it in GitHub Desktop.
Portable Class Libraries and webservices
public class GeonamesApi
{
public Earthquake[] GetEarthquakes()
{
var client = new HttpClient();
client.BaseAddress = new Uri("http://api.geonames.org/");
var response = client.GetAsync("earthquakesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&username=bertt").Result;
var earthquakesJson = response.Content.ReadAsStringAsync().Result;
var rootobject = JsonConvert.DeserializeObject<Rootobject>(earthquakesJson);
return rootobject.earthquakes;
}
}
public class Rootobject
{
public Earthquake[] earthquakes { get; set; }
}
public class Earthquake
{
public string eqid { get; set; }
public float magnitude { get; set; }
public float lng { get; set; }
public string src { get; set; }
public string datetime { get; set; }
public float depth { get; set; }
public float lat { get; set; }
}
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var names = new GeonamesApi().GetEarthquakes();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment