Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit, MonoTouch and MonoDroid versions

  • Loading branch information...
commit 16894d2940983245718eee062d91cfd95401a6b4 1 parent 038e951
@joelmartinez authored
View
4 .gitignore
@@ -1,6 +1,6 @@
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
bin
obj
-
+*.userprefs
# mstest test results
-TestResults
+TestResults
View
67 DarkSky.MonoDroid/DarkSky.MonoDroid.csproj
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>10.0.0</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{DE1C0DE3-FB39-4967-8950-D26094DC54E9}</ProjectGuid>
+ <ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <OutputType>Library</OutputType>
+ <RootNamespace>DarkSky</RootNamespace>
+ <MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
+ <MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
+ <AssemblyName>DarkSky.MonoDroid</AssemblyName>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug</OutputPath>
+ <DefineConstants>DEBUG;</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ <AndroidLinkMode>None</AndroidLinkMode>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>none</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release</OutputPath>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ <AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
+ <AndroidLinkMode>SdkOnly</AndroidLinkMode>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" />
+ <Reference Include="Mono.Android" />
+ <Reference Include="System.Json" />
+ <Reference Include="System.Runtime.Serialization" />
+ <Reference Include="System.ServiceModel.Web" />
+ </ItemGroup>
+ <Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
+ <ItemGroup>
+ <Compile Include="..\DarkSky\Api.cs">
+ <Link>Api.cs</Link>
+ </Compile>
+ <Compile Include="..\DarkSky\Epoch.cs">
+ <Link>Epoch.cs</Link>
+ </Compile>
+ <Compile Include="..\DarkSky\Forecast.cs">
+ <Link>Forecast.cs</Link>
+ </Compile>
+ <Compile Include="..\DarkSky\Position.cs">
+ <Link>Position.cs</Link>
+ </Compile>
+ <Compile Include="..\DarkSky\TimePosition.cs">
+ <Link>TimePosition.cs</Link>
+ </Compile>
+ <Compile Include="..\DarkSky\WebHelper.cs">
+ <Link>WebHelper.cs</Link>
+ </Compile>
+ </ItemGroup>
+</Project>
View
62 DarkSky.MonoTouch/DarkSky.MonoTouch.csproj
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>10.0.0</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{FD66B7CA-278A-4D27-A64B-9EAF56098FD3}</ProjectGuid>
+ <ProjectTypeGuids>{6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <OutputType>Library</OutputType>
+ <RootNamespace>DarkSky.MonoTouch</RootNamespace>
+ <AssemblyName>DarkSky.MonoTouch</AssemblyName>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug</OutputPath>
+ <DefineConstants>DEBUG;</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>none</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release</OutputPath>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" />
+ <Reference Include="monotouch" />
+ <Reference Include="System.Runtime.Serialization" />
+ <Reference Include="System.ServiceModel.Web" />
+ <Reference Include="System.ServiceModel" />
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <ItemGroup>
+ <Compile Include="..\DarkSky\Api.cs">
+ <Link>Api.cs</Link>
+ </Compile>
+ <Compile Include="..\DarkSky\Epoch.cs">
+ <Link>Epoch.cs</Link>
+ </Compile>
+ <Compile Include="..\DarkSky\Forecast.cs">
+ <Link>Forecast.cs</Link>
+ </Compile>
+ <Compile Include="..\DarkSky\Position.cs">
+ <Link>Position.cs</Link>
+ </Compile>
+ <Compile Include="..\DarkSky\TimePosition.cs">
+ <Link>TimePosition.cs</Link>
+ </Compile>
+ <Compile Include="..\DarkSky\WebHelper.cs">
+ <Link>WebHelper.cs</Link>
+ </Compile>
+ </ItemGroup>
+</Project>
View
49 DarkSky/Api.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Linq;
+using System.Threading.Tasks;
+using System.Collections.Generic;
+
+namespace DarkSky
+{
+ public class Api
+ {
+ string apikey;
+
+ public Api(string key)
+ {
+ this.apikey = key;
+ }
+
+ public Task<FullForecast> Forecast(Position position)
+ {
+ //https://api.darkskyapp.com/v1/forecast/APIKEY/LAT,LON
+ string url = "https://api.darkskyapp.com/v1/forecast/{0}/{1},{2}";
+ url = string.Format(url, apikey, position.Latitude, position.Longitude);
+
+ return WebHelper.Json<FullForecast>(url);
+ }
+
+ public Task<Forecast> BriefForecast(Position position)
+ {
+ //https://api.darkskyapp.com/v1/brief_forecast/APIKEY/LAT,LON
+ string url = "https://api.darkskyapp.com/v1/forecast/{0}/{1},{2}";
+ url = string.Format(url, apikey, position.Latitude, position.Longitude);
+
+ return WebHelper.Json<Forecast>(url);
+ }
+
+ public Task<HourPrecipitation[]> Precipitation(params TimePosition[] values)
+ {
+ //https://api.darkskyapp.com/v1/precipitation/APIKEY/LAT1,LON1,TIME1;LAT2,LON2,TIME2;...
+ string url = "https://api.darkskyapp.com/v1/precipitation/{0}/{1}";
+
+ var stringLocations = values.Select(v => v.ToString()).ToArray();
+ string locations = string.Join(";", stringLocations);
+
+ url = string.Format(url, apikey, locations);
+
+ return WebHelper.Json<HourPrecipitation[]>(url);
+ }
+ }
+}
+
View
57 DarkSky/Epoch.cs
@@ -0,0 +1,57 @@
+using System;
+
+namespace Epoch
+{
+ /// <summary>Class from https://gist.github.com/1095252</summary>
+ public class Epoch
+ {
+ static readonly DateTime epochStart = new DateTime(1970, 1, 1, 0, 0, 0);
+
+ static readonly DateTimeOffset epochDateTimeOffset = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
+
+ public static DateTime FromUnix(int secondsSinceepoch)
+ {
+ return epochStart.AddSeconds(secondsSinceepoch);
+ }
+
+ public static DateTimeOffset FromUnix(int secondsSinceEpoch, int timeZoneOffsetInMinutes)
+ {
+ var utcDateTime = epochDateTimeOffset.AddSeconds(secondsSinceEpoch);
+ var offset = TimeSpan.FromMinutes(timeZoneOffsetInMinutes);
+ return new DateTimeOffset(utcDateTime.DateTime.Add(offset), offset);
+ }
+
+ public static int ToUnix(DateTime dateTime)
+ {
+ return (int)(dateTime.ToUniversalTime() - epochStart).TotalSeconds;
+ }
+
+ public static int Now {
+ get {
+ return (int)(DateTime.UtcNow - epochStart).TotalSeconds;
+ }
+ }
+ }
+
+ namespace Extensions
+ {
+ public static class EpochExtensions
+ {
+ public static int ToUnix(this DateTime dateTime)
+ {
+ return Epoch.ToUnix(dateTime);
+ }
+
+ public static DateTime FromUnix(this int secondsSinceEpoch)
+ {
+ return Epoch.FromUnix(secondsSinceEpoch);
+ }
+
+ public static DateTimeOffset FromUnix(this int secondsSinceEpoch, int timeZoneOffsetInMinutes)
+ {
+ return Epoch.FromUnix(secondsSinceEpoch, timeZoneOffsetInMinutes);
+ }
+
+ }
+ }
+}
View
94 DarkSky/Forecast.cs
@@ -0,0 +1,94 @@
+using System;
+using System.Runtime.Serialization;
+using Epoch.Extensions;
+
+namespace DarkSky
+{
+ [DataContract]
+ public class HourPrecipitation
+ {
+ [DataMember(Name="time")]
+ public int UnixTime { get; set; }
+
+ public DateTime Time { get { return this.UnixTime.FromUnix(); } }
+
+ [DataMember(Name="probability")]
+ public double Probability { get; set; }
+
+ [DataMember(Name="intensity")]
+ public double Intensity { get; set; }
+
+ [DataMember(Name="error")]
+ public double Error { get; set; }
+
+ [DataMember(Name="type")]
+ public string PrecipitationType { get; set; }
+
+
+ }
+
+ [DataContract]
+ public class DayPrecipitation
+ {
+ [DataMember(Name="time")]
+ public int UnixTime { get; set; }
+
+ public DateTime Time { get { return this.UnixTime.FromUnix(); } }
+
+ [DataMember(Name="probability")]
+ public double Probability { get; set; }
+
+ [DataMember(Name="type")]
+ public string PrecipitationType { get; set; }
+
+ [DataMember(Name="temp")]
+ public int Temperature { get; set; }
+ }
+
+ [DataContract]
+ public class Forecast
+ {
+ [DataMember(Name="isPrecipitating")]
+ public bool IsPrecipitating { get; set; }
+
+ [DataMember(Name="minutesUntilChange")]
+ public int MinutesUntilChange { get; set; }
+
+ public TimeSpan TimeUntilChange { get { return new TimeSpan(0, this.MinutesUntilChange, 0); } }
+
+ [DataMember(Name="currentSummary")]
+ public string CurrentSummary { get; set; }
+
+ [DataMember(Name="hourSummary")]
+ public string HourSummary { get; set; }
+
+ [DataMember(Name="currentTemp")]
+ public int CurrentTemperature { get; set; }
+
+ [DataMember(Name="checkTimeout")]
+ public int CheckTimeout { get; set; }
+ }
+
+ [DataContract]
+ public class FullForecast : Forecast
+ {
+ [DataMember(Name="timezone")]
+ public string TimeZone { get; set; }
+
+ [DataMember(Name="radarStation")]
+ public string RadarStation { get; set; }
+
+ [DataMember(Name="hourPrecipitation")]
+ public HourPrecipitation[] HourPrecipitation { get; set; }
+
+ [DataMember(Name="dayPrecipitation")]
+ public DayPrecipitation[] DayPrecipitation { get; set; }
+ }
+
+ [DataContract]
+ public class PrecipitationRoot
+ {
+ [DataMember(Name="precipitation")]
+ public HourPrecipitation[] Precipitation {get;set;}
+ }
+}
View
33 DarkSky/Position.cs
@@ -0,0 +1,33 @@
+using System;
+
+namespace DarkSky
+{
+ public struct Position : IEquatable<Position>
+ {
+ public float Latitude;
+ public float Longitude;
+
+ public override bool Equals (object obj)
+ {
+ if (obj == null || typeof(Position) != obj.GetType()) return false;
+
+ return this.Equals ((Position)obj);
+ }
+
+ public bool Equals(Position other)
+ {
+ return this.Longitude == other.Longitude && this.Latitude == other.Latitude;
+ }
+
+ public override int GetHashCode ()
+ {
+ return this.Longitude.GetHashCode () ^ this.Latitude.GetHashCode();
+ }
+
+ public override string ToString ()
+ {
+ return string.Format ("{0},{1}", this.Latitude, this.Longitude);
+ }
+ }
+}
+
View
35 DarkSky/TimePosition.cs
@@ -0,0 +1,35 @@
+using System;
+
+namespace DarkSky
+{
+ public struct TimePosition : IEquatable<TimePosition>
+ {
+ public float Latitude;
+ public float Longitude;
+ public DateTime Time;
+
+
+ public override bool Equals (object obj)
+ {
+ if (obj == null || typeof(TimePosition) != obj.GetType()) return false;
+
+ return this.Equals ((TimePosition)obj);
+ }
+
+ public bool Equals(TimePosition other)
+ {
+ return this.Longitude == other.Longitude && this.Latitude == other.Latitude && this.Time == other.Time;
+ }
+
+ public override int GetHashCode ()
+ {
+ return this.Longitude.GetHashCode () ^ this.Latitude.GetHashCode() ^ this.Time.GetHashCode();
+ }
+
+ public override string ToString ()
+ {
+ return string.Format ("{0},{1},{2}", this.Latitude, this.Longitude, this.Time);
+ }
+ }
+}
+
View
34 DarkSky/WebHelper.cs
@@ -0,0 +1,34 @@
+using System;
+using System.IO;
+using System.Threading.Tasks;
+using System.Net;
+using System.Runtime.Serialization.Json;
+using System.Text;
+
+namespace DarkSky
+{
+ internal static class WebHelper
+ {
+ public static Task<T> Json<T>(string url)
+ {
+ return Task.Factory.StartNew(() =>
+ {
+ var request = WebRequest.CreateHttp(url);
+
+ var response = request.GetResponse();
+ var sreader = new StreamReader(response.GetResponseStream());
+ var result = sreader.ReadToEnd();
+
+ DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
+ byte[] bytes = Encoding.UTF8.GetBytes(result);
+ using (var stream = new MemoryStream(bytes))
+ {
+ var deserialized = serializer.ReadObject(stream);
+
+ return (T)deserialized;
+ }
+ });
+ }
+ }
+}
+
View
26 darksky-csharp.sln
@@ -0,0 +1,26 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DarkSky.MonoDroid", "DarkSky.MonoDroid\DarkSky.MonoDroid.csproj", "{DE1C0DE3-FB39-4967-8950-D26094DC54E9}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DarkSky.MonoTouch", "DarkSky.MonoTouch\DarkSky.MonoTouch.csproj", "{FD66B7CA-278A-4D27-A64B-9EAF56098FD3}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {DE1C0DE3-FB39-4967-8950-D26094DC54E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {DE1C0DE3-FB39-4967-8950-D26094DC54E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {DE1C0DE3-FB39-4967-8950-D26094DC54E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {DE1C0DE3-FB39-4967-8950-D26094DC54E9}.Release|Any CPU.Build.0 = Release|Any CPU
+ {FD66B7CA-278A-4D27-A64B-9EAF56098FD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FD66B7CA-278A-4D27-A64B-9EAF56098FD3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FD66B7CA-278A-4D27-A64B-9EAF56098FD3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FD66B7CA-278A-4D27-A64B-9EAF56098FD3}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(MonoDevelopProperties) = preSolution
+ StartupItem = DarkSky.MonoDroid\DarkSky.MonoDroid.csproj
+ EndGlobalSection
+EndGlobal
Please sign in to comment.
Something went wrong with that request. Please try again.