Skip to content

Commit

Permalink
Merge pull request #12 from Tearth/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Tearth committed Jul 4, 2020
2 parents bab586f + 9cd21c1 commit abd9973
Show file tree
Hide file tree
Showing 77 changed files with 1,276 additions and 478 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: csharp
dist: trusty
dist: xenial
mono: none
dotnet: 2.0.0
dotnet: 2.2.105
before_install:
- sudo apt-get update && sudo apt install -y doxygen
script:
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Version 1.0.13 (03-07-2020)
* Changed API version to v3
* Added new endpoints support for history, capsules and cores
* Added missing fields to the models
* Fixed models inconsistency

WARNING: this is the last release for v2/v3 API version. The next one will be completely rewritten to support v4 within a month or two - it won't be compatible backward. More info: https://github.com/r-spacex/SpaceX-API/issues/380

# Version 1.0.12 (26-02-2020)
* Added methods to retrieve information about API
* Cleaned up code
Expand Down
40 changes: 34 additions & 6 deletions Examples/OverviewApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;

Expand All @@ -19,18 +20,24 @@ 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.Company.GetHistory().ExecuteAsync();
var history = await oddity.History.GetAll().ExecuteAsync();

// Get history from the last two years and ordered descending
var historyWithFilter = await oddity.Company.GetHistory()
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();

Expand All @@ -40,23 +47,44 @@ static async Task Main(string[] args)
// 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 capsule types
var capsuleTypes = await oddity.Capsules.GetAll().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.DetailedCapsules.GetAll()
var capsuleWithFilters = await oddity.Capsules.GetAll()
.WithOriginalLaunch(new DateTime(2015, 4, 14, 20, 10, 0))
.ExecuteAsync();

// Get all cores
var allCores = await oddity.DetailedCores.GetAll().ExecuteAsync();
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();
Expand Down
21 changes: 21 additions & 0 deletions Oddity/API/Builders/BuilderBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net;
using System.Net.Http;
using System.Text;
Expand Down Expand Up @@ -74,6 +75,16 @@ protected void AddFilter(string name, int value)
_filters[name] = value.ToString();
}

/// <summary>
/// Adds or overrides filter with the specified name and double value.
/// </summary>
/// <param name="name">The filter name.</param>
/// <param name="value">The filter double value.</param>
protected void AddFilter(string name, double value)
{
_filters[name] = value.ToString(CultureInfo.InvariantCulture);
}

/// <summary>
/// Adds or overrides filter with the specified name and string value.
/// </summary>
Expand All @@ -94,6 +105,16 @@ protected void AddFilter(string name, bool value)
_filters[name] = value.ToString().ToLower();
}

/// <summary>
/// Adds or overrides filter with the specified name and date value.
/// </summary>
/// <param name="name">The filter name.</param>
/// <param name="value">The filter date value.</param>
protected void AddFilter(string name, DateTime value)
{
_filters[name] = value.ToString("O");
}

/// <summary>
/// Adds or overrides filter with the specified name and DateTime value.
/// </summary>
Expand Down
9 changes: 6 additions & 3 deletions Oddity/API/Builders/Capsules/AllCapsulesBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Oddity.API.Models.Capsule;
using Oddity.API.Models.Dragon;
using Oddity.Helpers;

namespace Oddity.API.Builders.Capsules
{
/// <summary>
/// Represents a set of methods to filter all capsules information and download them from API.
/// </summary>
public class AllCapsulesBuilder : BuilderBase<List<CapsuleInfo>>
public class AllCapsulesBuilder : CapsuleBuilderBase<AllCapsulesBuilder, List<CapsuleInfo>>
{
private const string CapsuleInfoEndpoint = "capsules";

Expand All @@ -19,7 +22,7 @@ public class AllCapsulesBuilder : BuilderBase<List<CapsuleInfo>>
/// <param name="builderDelegatesContainer">The builder delegates container.</param>
public AllCapsulesBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer)
{

}

/// <inheritdoc />
Expand Down
16 changes: 8 additions & 8 deletions Oddity/API/Builders/Capsules/CapsuleBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Oddity.API.Builders.Capsules
/// </summary>
public class CapsuleBuilder : BuilderBase<CapsuleInfo>
{
private CapsuleId? _capsuleType;
private string _capsuleSerial;
private const string CapsuleInfoEndpoint = "capsules";

/// <summary>
Expand All @@ -23,24 +23,24 @@ public CapsuleBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDe
}

/// <summary>
/// Filters capsule information by the specified capsule type. Note that you have to call <see cref="BuilderBase{TReturn}.Execute"/> or
/// <see cref="BuilderBase{TReturn}.ExecuteAsync"/> to get result from the API. Every next call of this method will override previously saved capsule type filter.
/// Filters capsule information by the specified capsule serial. Note that you have to call <see cref="BuilderBase{TReturn}.Execute"/> or
/// <see cref="BuilderBase{TReturn}.ExecuteAsync"/> to get result from the API. Every next call of this method will override previously saved capsule serial filter.
/// </summary>
/// <param name="type">The capsule type (Dragon1, Dragon2, etc).</param>
/// <param name="capsuleSerial">The capsule serial (C101, C102, etc).</param>
/// <returns>The capsule information.</returns>
public CapsuleBuilder WithType(CapsuleId type)
public CapsuleBuilder WithSerial(string capsuleSerial)
{
_capsuleType = type;
_capsuleSerial = capsuleSerial;
return this;
}

/// <inheritdoc />
protected override async Task<CapsuleInfo> ExecuteBuilder()
{
var link = BuildLink(CapsuleInfoEndpoint);
if (_capsuleType.HasValue)
if (_capsuleSerial != null)
{
link += $"/{_capsuleType.ToString().ToLower()}";
link += $"/{_capsuleSerial.ToUpper()}";
}

return await SendRequestToApi(link).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Oddity.API.Models.Capsule;
using Oddity.API.Models.DetailedCapsule;
using Oddity.API.Models.Dragon;
using Oddity.Helpers;

namespace Oddity.API.Builders.DetailedCapsules
namespace Oddity.API.Builders.Capsules
{
/// <summary>
/// Represents a set of methods to filter all detailed capsules information and download them from API.
/// Represents an abstract class for all capsule builders. Contains methods to the detailed filters that aren't present in other builders.
/// </summary>
public class AllDetailedCapsulesBuilder : BuilderBase<List<DetailedCapsuleInfo>>
/// <typeparam name="TBuilder">The launch builder type.</typeparam>
/// <typeparam name="TReturn">The returned object type.</typeparam>
public abstract class CapsuleBuilderBase<TBuilder, TReturn> : BuilderBase<TReturn> where TBuilder : CapsuleBuilderBase<TBuilder, TReturn> where TReturn : class
{
private const string CapsuleInfoEndpoint = "parts/caps";

/// <summary>
/// Initializes a new instance of the <see cref="AllDetailedCapsulesBuilder"/> class.
/// Initializes a new instance of the <see cref="CapsuleBuilderBase{TBuilder,TReturn}"/> class.
/// </summary>
/// <param name="httpClient">The HTTP client.</param>
/// <param name="builderDelegatesContainer">The builder delegates container.</param>
public AllDetailedCapsulesBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer)
protected CapsuleBuilderBase(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer)
{

}
Expand All @@ -30,90 +28,95 @@ public AllDetailedCapsulesBuilder(HttpClient httpClient, BuilderDelegatesContain
/// to get result from the API. Every next call of this method will override previously saved capsule serial filter.
/// </summary>
/// <param name="capsuleSerial">The capsule serial (C101, C102, etc).</param>
/// <returns>The detailed capsules builder.</returns>
public AllDetailedCapsulesBuilder WithCapsuleSerial(string capsuleSerial)
/// <returns>The capsules builder.</returns>
public TBuilder WithCapsuleSerial(string capsuleSerial)
{
AddFilter("capsule_serial", capsuleSerial);
return this;
return (TBuilder)this;
}

/// <summary>
/// Filters launches by capsule id. Note that you have to call <see cref="BuilderBase{TReturn}.Execute"/> or <see cref="BuilderBase{TReturn}.ExecuteAsync"/>
/// to get result from the API. Every next call of this method will override previously saved capsule id filter.
/// </summary>
/// <param name="capsuleId">The capsule id (Dragon 1, Dragon 2 etc).</param>
/// <returns>The detailed capsules builder.</returns>
public AllDetailedCapsulesBuilder WithCapsuleId(CapsuleId capsuleId)
/// <returns>The capsules builder.</returns>
public TBuilder WithCapsuleId(DragonId capsuleId)
{
AddFilter("capsule_id", capsuleId.GetEnumMemberAttributeValue(capsuleId));
return this;
return (TBuilder)this;
}

/// <summary>
/// Filters launches by capsule status. Note that you have to call <see cref="BuilderBase{TReturn}.Execute"/> or <see cref="BuilderBase{TReturn}.ExecuteAsync"/>
/// to get result from the API. Every next call of this method will override previously saved capsule status filter.
/// </summary>
/// <param name="status">The capsule status (active, retired etc).</param>
/// <returns>The detailed capsules builder.</returns>
public AllDetailedCapsulesBuilder WithStatus(DetailedCapsuleStatus status)
/// <returns>The capsules builder.</returns>
public TBuilder WithStatus(CapsuleStatus status)
{
AddFilter("status", status.GetEnumMemberAttributeValue(status));
return this;
return (TBuilder)this;
}

/// <summary>
/// Filters launches by original launch. Note that you have to call <see cref="BuilderBase{TReturn}.Execute"/> or <see cref="BuilderBase{TReturn}.ExecuteAsync"/>
/// to get result from the API. Every next call of this method will override previously saved original launch filter.
/// </summary>
/// <param name="originalLaunch">The capsule original launch.</param>
/// <returns>The detailed capsules builder.</returns>
public AllDetailedCapsulesBuilder WithOriginalLaunch(DateTime originalLaunch)
/// <returns>The capsules builder.</returns>
public TBuilder WithOriginalLaunch(DateTime originalLaunch)
{
AddFilter("original_launch", originalLaunch, DateFormatType.Long);
return this;
return (TBuilder)this;
}

/// <summary>
/// Filters launches by missions. Note that you have to call <see cref="BuilderBase{TReturn}.Execute"/> or <see cref="BuilderBase{TReturn}.ExecuteAsync"/>
/// to get result from the API. Every next call of this method will override previously saved missions filter.
/// </summary>
/// <param name="mission">The capsule mission (SpaceX CRS-8, ZUMA, etc).</param>
/// <returns>The detailed capsules builder.</returns>
public AllDetailedCapsulesBuilder WithMission(string mission)
/// <returns>The capsules builder.</returns>
public TBuilder WithMission(string mission)
{
AddFilter("mission", mission);
return this;
return (TBuilder)this;
}

/// <summary>
/// Filters launches by landings count. Note that you have to call <see cref="BuilderBase{TReturn}.Execute"/> or <see cref="BuilderBase{TReturn}.ExecuteAsync"/>
/// to get result from the API. Every next call of this method will override previously saved landings count filter.
/// </summary>
/// <param name="landingsCount">The capsule mission (SpaceX CRS-8, ZUMA, etc).</param>
/// <returns>The detailed capsules builder.</returns>
public AllDetailedCapsulesBuilder WithLandingsCount(int landingsCount)
/// <param name="landingsCount">Landing count.</param>
/// <returns>The capsules builder.</returns>
public TBuilder WithLandingsCount(int landingsCount)
{
AddFilter("landings", landingsCount);
return this;
return (TBuilder)this;
}

/// <summary>
/// Filters launches by capsule type. Note that you have to call <see cref="BuilderBase{TReturn}.Execute"/> or <see cref="BuilderBase{TReturn}.ExecuteAsync"/>
/// to get result from the API. Every next call of this method will override previously saved capsule type filter.
/// </summary>
/// <param name="capsuleType">The capsule type (Dragon 1.1, Dragon 2.0, etc).</param>
/// <returns>The detailed capsules builder.</returns>
public AllDetailedCapsulesBuilder WithCapsuleType(string capsuleType)
/// <returns>The capsules builder.</returns>
public TBuilder WithCapsuleType(string capsuleType)
{
AddFilter("type", capsuleType);
return this;
return (TBuilder)this;
}

/// <inheritdoc />
protected override async Task<List<DetailedCapsuleInfo>> ExecuteBuilder()
/// <summary>
/// Filters launches by reuse count. Note that you have to call <see cref="BuilderBase{TReturn}.Execute"/> or <see cref="BuilderBase{TReturn}.ExecuteAsync"/>
/// to get result from the API. Every next call of this method will override previously saved landings count filter.
/// </summary>
/// <param name="reuseCount">Reuse count.</param>
/// <returns>The capsules builder.</returns>
public TBuilder WithReuseCount(int reuseCount)
{
var link = BuildLink(CapsuleInfoEndpoint);
return await SendRequestToApi(link).ConfigureAwait(false);
AddFilter("reuse_count", reuseCount);
return (TBuilder)this;
}
}
}
}
Loading

0 comments on commit abd9973

Please sign in to comment.