Skip to content

Commit

Permalink
Merge pull request #13 from Tearth/develop
Browse files Browse the repository at this point in the history
v2.0.0
  • Loading branch information
Tearth authored Jul 20, 2020
2 parents 813c7b7 + 6172189 commit 9320e64
Show file tree
Hide file tree
Showing 181 changed files with 3,697 additions and 4,126 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Version 2.0.0 (20-07-2020)
* Total refactoring of the library (a lot of changed endpoints and models)
* Add support for v4 API version (incompatible backward)
* Add support for the new query system
* Add lazy properties to the models
* Add internal cache for received data

# Version 1.0.13 (03-07-2020)
* Changed API version to v3
* Added new endpoints support for history, capsules and cores
Expand Down
197 changes: 125 additions & 72 deletions Examples/OverviewApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
using System.Threading.Tasks;
using Newtonsoft.Json.Serialization;
using Oddity;
using Oddity.API.Builders;
using Oddity.API.Models.Dragon;
using Oddity.API.Models.Launch.Rocket.SecondStage.Orbit;
using Oddity.API.Models.Rocket;
using Oddity.Events;

namespace OverviewApp
{
Expand All @@ -20,81 +17,132 @@ static async Task Main(string[] args)
oddity.OnRequestSend += Oddity_OnRequestSend;
oddity.OnResponseReceive += OddityOnResponseReceive;

// Get API information
var apiInfo = await oddity.Api.GetInfo().ExecuteAsync();

// Get company information
var company = await oddity.Company.GetInfo().ExecuteAsync();

// Get all history
var history = await oddity.History.GetAll().ExecuteAsync();

// Get history from the last two years and ordered descending
var historyWithFilter = await oddity.History.GetAll()
.WithRange(DateTime.Now.AddYears(-2), DateTime.Now)
.Descending()
.ExecuteAsync();

// Get single history event
var historyEvent = await oddity.History.GetEvent(5).ExecuteAsync();

// Get data about Falcon Heavy
var falconHeavy = await oddity.Rockets.GetAbout(RocketId.FalconHeavy).ExecuteAsync();

// Get list of all launchpads
var allLaunchpads = await oddity.Launchpads.GetAll().ExecuteAsync();

// Get information about the next launch
var nextLaunch = await oddity.Launches.GetNext().ExecuteAsync();

// Get information about the specified launch
var specifiedLaunch = await oddity.Launches.Get(65).ExecuteAsync();

// Get data about all launches of Falcon 9 which has been launched to ISS. Next, sort it ascending
var launchWithFilters = await oddity.Launches.GetAll()
.WithRocketName("Falcon 9")
.WithOrbit(OrbitType.ISS)
.Ascending()
.ExecuteAsync();

// Get all Dragon types
var dragonTypes = await oddity.Dragons.GetAll().ExecuteAsync();

// Get all Dragon types
var crewDragon = await oddity.Dragons.GetAbout(DragonId.Dragon2).ExecuteAsync();

// Get all capsules
var allCapsules = await oddity.Capsules.GetAll().ExecuteAsync();

// Past capsules
var pastCapsules = await oddity.Capsules.GetPast().ExecuteAsync();

// Upcoming capsules
var upcomingCapsules = await oddity.Capsules.GetUpcoming().ExecuteAsync();

// Get capsule which has been launched 2015-04-14 at 20:10
var capsuleWithFilters = await oddity.Capsules.GetAll()
.WithOriginalLaunch(new DateTime(2015, 4, 14, 20, 10, 0))
// Test of the /capsules endpoint
var allCapsules = await oddity.CapsulesEndpoint.GetAll().ExecuteAsync();
var capsule = await oddity.CapsulesEndpoint.Get("5e9e2c5bf35918ed873b2664").ExecuteAsync();
var capsuleLaunch = capsule.Launches[0].Value;

// Test of the /company endpoint
var company = await oddity.CompanyEndpoint.Get().ExecuteAsync();

// Test of the /cores endpoint
var allCores = await oddity.CoresEndpoint.GetAll().ExecuteAsync();
var core = await oddity.CoresEndpoint.Get("5e9e28a6f35918c0803b265c").ExecuteAsync();
var coreLaunch1 = core.Launches[0].Value;
var coreLaunch2 = core.Launches[1].Value;
var coreLaunch3 = core.Launches[2].Value;
var coreLaunch4 = core.Launches[3].Value;

// Test of the /crew endpoint
var allCrew = await oddity.CrewEndpoint.GetAll().ExecuteAsync();
var crewMember = await oddity.CrewEndpoint.Get("5ebf1b7323a9a60006e03a7b").ExecuteAsync();
var crewMemberLaunch = crewMember.Launches[0].Value;

// Test of the /crew endpoint
var crewLaunch = await oddity.LaunchesEndpoint.Get("5eb87d46ffd86e000604b388").ExecuteAsync();
var crewLaunchCore = crewLaunch.Cores[0].Core.Value;
var crewLaunchLandpad = crewLaunch.Cores[0].Landpad.Value;
var crewLaunchRocket = crewLaunch.Rocket.Value;
var crewLaunchCrew = crewLaunch.Crew[0].Value;
var crewLaunchShip = crewLaunch.Ships[0].Value;
var crewLaunchCapsule = crewLaunch.Capsules[0].Value;
var crewLaunchPayload = crewLaunch.Payloads[0].Value;
var crewLaunchLaunchpad = crewLaunch.Launchpad.Value;

// Test of the /dragons endpoint
var allDragons = await oddity.DragonsEndpoint.GetAll().ExecuteAsync();
var dragon = await oddity.DragonsEndpoint.Get("5e9d058759b1ff74a7ad5f8f").ExecuteAsync();

// Test of the /landpads endpoint
var allLandpads = await oddity.LandpadsEndpoint.GetAll().ExecuteAsync();
var landpad = await oddity.LandpadsEndpoint.Get("5e9e3032383ecb90a834e7c8").ExecuteAsync();
var landpadLaunch = landpad.Launches[0].Value;

// Test of the /launches endpoint
var launch = await oddity.LaunchesEndpoint.Get("5eb87d44ffd86e000604b386").ExecuteAsync();
var allLaunches = await oddity.LaunchesEndpoint.GetAll().ExecuteAsync();
var pastLaunches = await oddity.LaunchesEndpoint.GetPast().ExecuteAsync();
var upcomingLaunches = await oddity.LaunchesEndpoint.GetUpcoming().ExecuteAsync();
var latestLaunch = await oddity.LaunchesEndpoint.GetLatest().ExecuteAsync();
var nextLaunch = await oddity.LaunchesEndpoint.GetNext().ExecuteAsync();

// Test of the /launches endpoint
var commercialLaunch = await oddity.LaunchesEndpoint.Get("5eb87d46ffd86e000604b389").ExecuteAsync();
var commercialLaunchCore = commercialLaunch.Cores[0].Core.Value;
var commercialLaunchLandpad = commercialLaunch.Cores[0].Landpad.Value;
var commercialLaunchFairingShips = commercialLaunch.Fairings.Ships[0].Value;
var commercialLaunchRocket = commercialLaunch.Rocket.Value;
var commercialLaunchShip = commercialLaunch.Ships[0].Value;
var commercialLaunchPayload = commercialLaunch.Payloads[0].Value;
var commercialLaunchLaunchpad = commercialLaunch.Launchpad.Value;

// Test of the /launchpads endpoint
var allLaunchpads = await oddity.LaunchpadsEndpoint.GetAll().ExecuteAsync();
var launchpad = await oddity.LaunchpadsEndpoint.Get("5e9e4502f509092b78566f87").ExecuteAsync();
var launchpadLaunch1 = launchpad.Launches[0].Value;
var launchpadLaunch2 = launchpad.Launches[1].Value;
var launchpadLaunch3 = launchpad.Launches[2].Value;
var launchpadLaunch4 = launchpad.Launches[3].Value;
var launchpadRocket = launchpad.Rockets[0].Value;

// Test of the /payloads endpoint
var allPayloads = await oddity.PayloadsEndpoint.GetAll().ExecuteAsync();
var payload = await oddity.PayloadsEndpoint.Get("5eb0e4bbb6c3bb0006eeb1ed").ExecuteAsync();
var payloadLaunch = payload.Launch.Value;
var payloadCapsule = payload.Dragon.Capsule.Value;

// Test of the /roadster endpoint
var roadster = await oddity.RoadsterEndpoint.Get().ExecuteAsync();

// Test of the /rockets endpoint
var allRockets = await oddity.RocketsEndpoint.GetAll().ExecuteAsync();
var rocket = await oddity.RocketsEndpoint.Get("5e9d0d95eda69974db09d1ed").ExecuteAsync();

// Test of the /ships endpoint
var allShips = await oddity.ShipsEndpoint.GetAll().ExecuteAsync();
var ship = await oddity.ShipsEndpoint.Get("5ea6ed2e080df4000697c90a").ExecuteAsync();
var shipLaunch1 = ship.Launches[0].Value;
var shipLaunch2 = ship.Launches[1].Value;
var shipLaunch3 = ship.Launches[2].Value;
var shipLaunch4 = ship.Launches[3].Value;

// Test of the /starlink endpoint
var allStarlinks = await oddity.StarlinkEndpoint.GetAll().ExecuteAsync();
var starlink = await oddity.StarlinkEndpoint.Get("5eed7716096e590006985825").ExecuteAsync();
var starlinkLaunch = starlink.Launch.Value;

// Test of the pagination
var queryStarlink = await oddity.StarlinkEndpoint.Query()
.WithFieldGreaterThan(p => p.SpaceTrack.Apoapsis, 500)
.WithLimit(100)
.SortBy(p => p.SpaceTrack.Apoapsis, false)
.ExecuteAsync();

// Get all cores
var allCores = await oddity.Cores.GetAll().ExecuteAsync();

// Get past cores
var pastCores = await oddity.Cores.GetPast().ExecuteAsync();

// Get upcoming cores
var upcomingCores = await oddity.Cores.GetUpcoming().ExecuteAsync();

// Get Roadster info
var roadster = await oddity.Roadster.Get().ExecuteAsync();
await queryStarlink.GoToNextPage();
await queryStarlink.GoToNextPage();
await queryStarlink.GoToNextPage();
await queryStarlink.GoToPrevPage();
await queryStarlink.GoToPrevPage();
await queryStarlink.GoToPrevPage();
await queryStarlink.GoToLastPage();
await queryStarlink.GoToFirstPage();

// Test of cache
var queryLaunch = await oddity.LaunchesEndpoint.Query().WithLimit(1).ExecuteAsync();
var queryLaunchCached = await oddity.LaunchesEndpoint.Get("5eb87cd9ffd86e000604b32a").ExecuteAsync();

var launchCached = await oddity.LaunchesEndpoint.Get("5eb87d44ffd86e000604b386").ExecuteAsync();
var allLaunchesCached = await oddity.LaunchesEndpoint.GetAll().ExecuteAsync();
var pastLaunchesCached = await oddity.LaunchesEndpoint.GetPast().ExecuteAsync();
var upcomingLaunchesCached = await oddity.LaunchesEndpoint.GetUpcoming().ExecuteAsync();
var latestLaunchCached = await oddity.LaunchesEndpoint.GetLatest().ExecuteAsync();
var nextLaunchCached = await oddity.LaunchesEndpoint.GetNext().ExecuteAsync();

Console.Read();
}

private static void OddityOnDeserializationError(object sender, ErrorEventArgs errorEventArgs)
{
Console.WriteLine("Something went wrong.");
Console.WriteLine("Something went wrong");

// We don't want to stop program, just leave problematic field as null
errorEventArgs.ErrorContext.Handled = true;
Expand All @@ -103,6 +151,11 @@ private static void OddityOnDeserializationError(object sender, ErrorEventArgs e
private static void Oddity_OnRequestSend(object sender, RequestSendEventArgs e)
{
Console.WriteLine($"Sending request... URL: {e.Url}");

if (e.Query != null)
{
Console.WriteLine($"Query: {e.Query}");
}
}

private static void OddityOnResponseReceive(object sender, ResponseReceiveEventArgs e)
Expand Down
100 changes: 100 additions & 0 deletions Examples/StarlinkApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using Newtonsoft.Json.Serialization;
using Oddity;
using Oddity.Models.Starlink;

namespace StarlinkApp
{
public class Program
{
private static uint SatellitesPerTable = 4;

public static async Task Main()
{
var oddity = new OddityCore();
var stopWatch = Stopwatch.StartNew();

oddity.OnDeserializationError += OddityOnOnDeserializationError;

await DisplayWithHighestApoapsis(oddity, SatellitesPerTable);
await DisplayWithLowestPeriapsis(oddity, SatellitesPerTable);
await DisplayWithHighestSpeed(oddity, SatellitesPerTable);
await DisplayWithLowestSpeed(oddity, SatellitesPerTable);

Console.WriteLine($"Generated in {stopWatch.Elapsed.TotalSeconds:F1} seconds");
Console.Read();
}

private static async Task DisplayWithHighestApoapsis(OddityCore oddity, uint count)
{
var satellites = await oddity.StarlinkEndpoint.Query()
.SortBy(p => p.SpaceTrack.Apoapsis, false)
.WithLimit(count)
.ExecuteAsync();

DisplaySatelliteData(satellites.Data, "Satellites with the highest apoapsis:");
}

private static async Task DisplayWithLowestPeriapsis(OddityCore oddity, uint count)
{
var satellites = await oddity.StarlinkEndpoint.Query()
.SortBy(p => p.SpaceTrack.Periapsis)
.WithLimit(count)
.ExecuteAsync();

DisplaySatelliteData(satellites.Data, "Satellites with the lowest periapsis:");
}

private static async Task DisplayWithHighestSpeed(OddityCore oddity, uint count)
{
var satellites = await oddity.StarlinkEndpoint.Query()
.SortBy(p => p.VelocityKilometersPerSecond, false)
.WithLimit(count)
.ExecuteAsync();

DisplaySatelliteData(satellites.Data, "Satellites with the highest speed:");
}

private static async Task DisplayWithLowestSpeed(OddityCore oddity, uint count)
{
var satellites = await oddity.StarlinkEndpoint.Query()
.WithFieldGreaterThan(p => p.VelocityKilometersPerSecond, 0.0)
.SortBy(p => p.VelocityKilometersPerSecond)
.WithLimit(count)
.ExecuteAsync();

DisplaySatelliteData(satellites.Data, "Satellites with the lowest speed:");
}

private static void DisplaySatelliteData(IEnumerable<StarlinkInfo> satellitesList, string header)
{
Console.WriteLine(header);
Console.WriteLine("---------------------------------------------------------------------------");

foreach (var satellite in satellitesList)
{
var launch = satellite.Launch.Value;
var name = launch.Name;
var version = satellite.Version;
var date = launch.DateUtc;
var apoapsis = satellite.SpaceTrack.Apoapsis;
var periapsis = satellite.SpaceTrack.Periapsis;
var velocity = satellite.VelocityKilometersPerSecond;

Console.WriteLine($"{name} ({version}) launched at {date}): {apoapsis:F} km x {periapsis:F} km, " +
$"{velocity ?? double.NaN:F} km/s");
}

Console.WriteLine();
}

private static void OddityOnOnDeserializationError(object sender, ErrorEventArgs errorEventArgs)
{
Console.WriteLine($"Error: {errorEventArgs.ErrorContext.Path}");
errorEventArgs.ErrorContext.Handled = true;
}
}
}
13 changes: 13 additions & 0 deletions Examples/StarlinkApp/StarlinkApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Oddity\Oddity.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit 9320e64

Please sign in to comment.