-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from schulz3000/develop
Initial Release 0.0.0.1
- Loading branch information
Showing
20 changed files
with
679 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: 1.0.{build} | ||
os: Visual Studio 2015 | ||
pull_requests: | ||
do_not_increment_build_number: true | ||
environment: | ||
# Don't report back to the mothership | ||
DOTNET_CLI_TELEMETRY_OPTOUT: 1 | ||
skip_tags: true | ||
build_script: | ||
- ps: dotnet --info | ||
- ps: dotnet restore | ||
- ps: dotnet --verbose build .\src\OpenSkyNet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,53 @@ | ||
# openskyNet | ||
# OpenSkyNet | ||
============ | ||
|
||
dotnet lib for the opensky-network.org api | ||
|
||
##Builds | ||
[![Build status](https://ci.appveyor.com/api/projects/status/gwga69d3bnlmis7k?svg=true)](https://ci.appveyor.com/project/schulz3000/openskynet) | ||
|
||
##Usage | ||
|
||
```csharp | ||
var client = new OpenSkyApi(); | ||
|
||
//Alternative with credentials | ||
var client = new OpenSkyApi("Username", "Password"); | ||
|
||
// Close Connection to opensky-network.org endpoint | ||
client.Dispose(); | ||
``` | ||
|
||
##GetStates | ||
```csharp | ||
//Get all current states | ||
var result = await client.GetStatesAsync(); | ||
|
||
//Get all states from specific time. | ||
var result = await client.GetStatesAsync(time:DateTime.UtcNow); | ||
|
||
//Get all states for specific ICAO24 transponder address. ICAO24 must be given in hex representation. | ||
var result = await client.GetStatesAsync(icao24: new[] { "abc9f3", "3e1bf9" }); | ||
``` | ||
|
||
##GetMyStates | ||
Works only when credentials are given | ||
```csharp | ||
//Get all current states | ||
var result = await client.GetMyStatesAsync(); | ||
|
||
//Get all states from specific time. | ||
var result = await client.GetMyStatesAsync(time:DateTime.UtcNow); | ||
|
||
//Get all states for specific ICAO24 transponder address. ICAO24 must be given in hex representation. | ||
var result = await client.GetMyStatesAsync(icao24: new[] { "abc9f3", "3e1bf9" }); | ||
|
||
//Get all states for subset of your receivers. | ||
var result = await client.GetMyStatesAsync(serials: new[] { 1, 2, 3 }); | ||
``` | ||
##Result | ||
|
||
//TODO: Table for Result Propertys | ||
|
||
|
||
RestApi Reference: (https://opensky-network.org/apidoc) |
21 changes: 21 additions & 0 deletions
21
src/OpenSkyNet.ConsoleSample/OpenSkyNet.ConsoleSample.xproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
|
||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>b37cbc2b-38ce-4cea-9282-519f7bf0164e</ProjectGuid> | ||
<RootNamespace>OpenSkyNet.ConsoleSample</RootNamespace> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath> | ||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace OpenSkyNet.ConsoleSample | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
MainAsync(args).GetAwaiter().GetResult(); | ||
|
||
Console.Read(); | ||
} | ||
|
||
static Task MainAsync(string[] args) | ||
{ | ||
return Exec(); | ||
} | ||
|
||
async static Task Exec() | ||
{ | ||
using (var client = new OpenSkyApi()) | ||
{ | ||
var result = await client.GetStatesAsync(icao24: new[] { "abc9f3", "3e1bf9" }); | ||
|
||
Console.WriteLine(result.TimeStamp); | ||
|
||
foreach (var item in result.States) | ||
Console.WriteLine(item.OriginCountry); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
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: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("OpenSkyNet.ConsoleSample")] | ||
[assembly: AssemblyTrademark("")] | ||
|
||
// 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("b37cbc2b-38ce-4cea-9282-519f7bf0164e")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"title": "OpenSkyNet Console Sample", | ||
"copyright": "schulz3000", | ||
"description": "Console Sampleclient for OpenSkyNet", | ||
"authors": [ "schulz3000" ], | ||
"version": "0.0.0.1-alpha", | ||
"buildOptions": { | ||
"emitEntryPoint": true | ||
}, | ||
|
||
"dependencies": { | ||
"OpenSkyNet": "0.0.0.1-alpha", | ||
"Microsoft.NETCore.App": { | ||
"type": "platform", | ||
"version": "1.0.1" | ||
} | ||
}, | ||
|
||
"frameworks": { | ||
"netcoreapp1.0": { | ||
"imports": "dnxcore50" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.25420.1 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{562992F5-89D4-43F7-B4C4-2D89DCD01FA2}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6F8BF119-C82B-488A-9EBD-B78EB6340F03}" | ||
ProjectSection(SolutionItems) = preProject | ||
global.json = global.json | ||
EndProjectSection | ||
EndProject | ||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "OpenSkyNet", "OpenSkyNet\OpenSkyNet.xproj", "{436B0BA0-B68D-441F-A7AF-5B9FA403CF00}" | ||
EndProject | ||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "OpenSkyNet.ConsoleSample", "OpenSkyNet.ConsoleSample\OpenSkyNet.ConsoleSample.xproj", "{B37CBC2B-38CE-4CEA-9282-519F7BF0164E}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{436B0BA0-B68D-441F-A7AF-5B9FA403CF00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{436B0BA0-B68D-441F-A7AF-5B9FA403CF00}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{436B0BA0-B68D-441F-A7AF-5B9FA403CF00}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{436B0BA0-B68D-441F-A7AF-5B9FA403CF00}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{B37CBC2B-38CE-4CEA-9282-519F7BF0164E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{B37CBC2B-38CE-4CEA-9282-519F7BF0164E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{B37CBC2B-38CE-4CEA-9282-519F7BF0164E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{B37CBC2B-38CE-4CEA-9282-519F7BF0164E}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{436B0BA0-B68D-441F-A7AF-5B9FA403CF00} = {562992F5-89D4-43F7-B4C4-2D89DCD01FA2} | ||
{B37CBC2B-38CE-4CEA-9282-519F7BF0164E} = {562992F5-89D4-43F7-B4C4-2D89DCD01FA2} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Net.Http.Headers; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace OpenSkyNet | ||
{ | ||
/// <summary> | ||
/// Base class for HTTP Connection to opensky network | ||
/// </summary> | ||
public abstract class Connection : IDisposable | ||
{ | ||
const string baseurl = "opensky-network.org/api/"; | ||
|
||
readonly HttpClient client; | ||
|
||
/// <summary> | ||
/// Detect if Credentials are given | ||
/// </summary> | ||
protected bool HasCredentials { get { return client.DefaultRequestHeaders.Authorization != null; } } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
protected Connection() | ||
{ | ||
client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }, true); | ||
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | ||
client.BaseAddress = new Uri("https://" + baseurl); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="username"></param> | ||
/// <param name="password"></param> | ||
protected Connection(string username, string password) | ||
: this() | ||
{ | ||
if (string.IsNullOrWhiteSpace(username)) | ||
throw new ArgumentNullException(nameof(username)); | ||
|
||
if (string.IsNullOrWhiteSpace(password)) | ||
throw new ArgumentNullException(nameof(password)); | ||
|
||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{username}:{password}"))); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <typeparam name="TResult"></typeparam> | ||
/// <param name="uriPath"></param> | ||
/// <returns></returns> | ||
protected async Task<TResult> GetAsync<TResult>(string uriPath) | ||
{ | ||
var response = await client.GetAsync(uriPath); | ||
|
||
if (response.IsSuccessStatusCode) | ||
{ | ||
var result = await response.Content.ReadAsStringAsync(); | ||
return JsonConvert.DeserializeObject<TResult>(result); | ||
} | ||
|
||
throw new OpenSkyNetException(response.ReasonPhrase); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public void Dispose() | ||
{ | ||
Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
void Dispose(bool disposing) | ||
{ | ||
if (disposing) | ||
{ | ||
if (client != null) | ||
client.Dispose(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace OpenSkyNet | ||
{ | ||
/// <summary> | ||
/// Response | ||
/// </summary> | ||
public interface IOpenSkyStates | ||
{ | ||
/// <summary> | ||
/// The time which the state vectors in this response are associated with. All vectors represent the state of a vehicle with the interval [time−1,time][time−1,time]. | ||
/// </summary> | ||
int TimeStamp { get; } | ||
/// <summary> | ||
/// The state vectors. | ||
/// </summary> | ||
IStateVector[] States { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
namespace OpenSkyNet | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public interface IStateVector | ||
{ | ||
/// <summary> | ||
/// Unique ICAO 24-bit address of the transponder in hex string representation. | ||
/// </summary> | ||
string Icao24 { get; } | ||
/// <summary> | ||
/// Callsign of the vehicle (8 chars). Can be null if no callsign has been received. | ||
/// </summary> | ||
string CallSign { get; } | ||
/// <summary> | ||
/// Country name inferred from the ICAO 24-bit address. | ||
/// </summary> | ||
string OriginCountry { get; } | ||
/// <summary> | ||
/// Unix timestamp (seconds) for the last position update. Can be null if no position report was received by OpenSky within the past 15s. | ||
/// </summary> | ||
float? TimePosition { get; } | ||
/// <summary> | ||
/// Unix timestamp (seconds) for the last velocity update. Can be null if no velocity report was received by OpenSky within the past 15s. | ||
/// </summary> | ||
float? TimeVelocity { get; } | ||
/// <summary> | ||
/// WGS-84 longitude in decimal degrees. Can be null. | ||
/// </summary> | ||
float? Longitude { get; } | ||
/// <summary> | ||
/// WGS-84 latitude in decimal degrees. Can be null. | ||
/// </summary> | ||
float? Latitude { get; } | ||
/// <summary> | ||
/// Barometric or geometric altitude in meters. Can be null. | ||
/// </summary> | ||
float? Altitude { get; } | ||
/// <summary> | ||
/// Boolean value which indicates if the position was retrieved from a surface position report. | ||
/// </summary> | ||
bool OnGround { get; } | ||
/// <summary> | ||
/// Velocity over ground in m/s. Can be null. | ||
/// </summary> | ||
float? Velocity { get; } | ||
/// <summary> | ||
/// Heading in decimal degrees clockwise from north (i.e. north=0°). Can be null. | ||
/// </summary> | ||
float? Heading { get; } | ||
/// <summary> | ||
/// Vertical rate in m/s. A positive value indicates that the airplane is climbing, a negative value indicates that it descends. Can be null. | ||
/// </summary> | ||
float? VerticalRate { get; } | ||
/// <summary> | ||
/// IDs of the receivers which contributed to this state vector. Is null if no filtering for sensor was used in the request. | ||
/// </summary> | ||
int[] Sensors { get; } | ||
} | ||
} |
Oops, something went wrong.