Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
Added desktop version of the library. Also added notification classes…
Browse files Browse the repository at this point in the history
…/method
  • Loading branch information
joelmartinez committed Aug 11, 2012
1 parent 3e1a8c9 commit fa0082c
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 60 deletions.
Binary file added DarkSky.Mono.suo
Binary file not shown.
Binary file modified DarkSky.WindowsPhone/DarkSky.WindowsPhone.suo
Binary file not shown.
133 changes: 73 additions & 60 deletions DarkSky/Api.cs
@@ -1,60 +1,73 @@
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> GetForecastAsync(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> GetBriefForecastAsync(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[]> GetPrecipitationAsync(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<PrecipitationRoot>(url)
.ContinueWith<HourPrecipitation[]>(response => response.Result.Precipitation);
}

public Task<InterestingStorm[]> GetInterestingStormsAsync()
{
//https://api.darkskyapp.com/v1/interesting/APIKEY
string url = "https://api.darkskyapp.com/v1/interesting/{0}";
url = string.Format(url, apikey);

return WebHelper.Json<InterestingStormRoot>(url)
.ContinueWith<InterestingStorm[]>(r => r.Result.Storms);
}
}
}

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> GetForecastAsync(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> GetBriefForecastAsync(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[]> GetPrecipitationAsync(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<PrecipitationRoot>(url)
.ContinueWith<HourPrecipitation[]>(response => response.Result.Precipitation);
}

public Task<InterestingStorm[]> GetInterestingStormsAsync()
{
//https://api.darkskyapp.com/v1/interesting/APIKEY
string url = "https://api.darkskyapp.com/v1/interesting/{0}";
url = string.Format(url, apikey);

return WebHelper.Json<InterestingStormRoot>(url)
.ContinueWith<InterestingStorm[]>(r => r.Result.Storms);
}

#region Weather Notifications

public Task<Notification> GetNotification(string id)
{
//https://api.darkskyapp.com/v1/notification/APIKEY/ID
string url = "https://api.darkskyapp.com/v1/notification/{0}/{1}";
url = string.Format(url, apikey, Uri.EscapeDataString(id));

return WebHelper.Json<Notification>(url);
}

#endregion
}
}

59 changes: 59 additions & 0 deletions DarkSky/DarkSky.csproj
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{69AAA614-89A7-45B3-878C-EB04F2FDE89C}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DarkSky</RootNamespace>
<AssemblyName>DarkSky</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Api.cs" />
<Compile Include="Epoch.cs" />
<Compile Include="Forecast.cs" />
<Compile Include="Notification.cs" />
<Compile Include="Position.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TimePosition.cs" />
<Compile Include="WebHelper.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
6 changes: 6 additions & 0 deletions DarkSky/DarkSky.csproj.user
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
</PropertyGroup>
</Project>
20 changes: 20 additions & 0 deletions DarkSky/DarkSky.sln
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DarkSky", "DarkSky.csproj", "{69AAA614-89A7-45B3-878C-EB04F2FDE89C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{69AAA614-89A7-45B3-878C-EB04F2FDE89C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{69AAA614-89A7-45B3-878C-EB04F2FDE89C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{69AAA614-89A7-45B3-878C-EB04F2FDE89C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{69AAA614-89A7-45B3-878C-EB04F2FDE89C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
41 changes: 41 additions & 0 deletions DarkSky/Notification.cs
@@ -0,0 +1,41 @@
using System;
using System.Runtime.Serialization;
using Epoch.Extensions;

namespace DarkSky
{
[DataContract]
public class Notification
{
[DataMember(Name="id")]
public string Id { get; set; }

[DataMember(Name = "latitude")]
public double Latitude { get; set; }

[DataMember(Name = "longitude")]
public double Longitude { get; set; }

[DataMember(Name = "threshold")]
public string Threshold { get; set; }

[DataMember(Name = "createdAt")]
public int CreatedAtUnix { get; set; }

public DateTime CreatedAt { get { return this.CreatedAtUnix.FromUnix(); } }

[DataMember(Name = "lastNotificationAt")]
public int LastNotificationAtUnix { get; set; }

public DateTime LastNotificationAt { get { return this.LastNotificationAtUnix.FromUnix(); } }

[DataMember(Name = "notificationCount")]
public int NotificationCount { get; set; }

[DataMember(Name = "callback")]
public string CallBack { get; set; }

[DataMember(Name = "enabled")]
public bool Enabled { get; set; }
}
}
36 changes: 36 additions & 0 deletions DarkSky/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("DarkSky")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DarkSky")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("78848954-2100-4af2-906d-4a2e555d37b9")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

0 comments on commit fa0082c

Please sign in to comment.