diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b95c9e..df28813 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Examples/OverviewApp/Program.cs b/Examples/OverviewApp/Program.cs index 258c385..cd50469 100644 --- a/Examples/OverviewApp/Program.cs +++ b/Examples/OverviewApp/Program.cs @@ -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 { @@ -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; @@ -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) diff --git a/Examples/StarlinkApp/Program.cs b/Examples/StarlinkApp/Program.cs new file mode 100644 index 0000000..50e593a --- /dev/null +++ b/Examples/StarlinkApp/Program.cs @@ -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 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; + } + } +} diff --git a/Examples/StarlinkApp/StarlinkApp.csproj b/Examples/StarlinkApp/StarlinkApp.csproj new file mode 100644 index 0000000..2638a80 --- /dev/null +++ b/Examples/StarlinkApp/StarlinkApp.csproj @@ -0,0 +1,13 @@ + + + + Exe + netcoreapp2.0 + latest + + + + + + + diff --git a/Examples/UpcomingLaunchesApp/Program.cs b/Examples/UpcomingLaunchesApp/Program.cs index 0010264..dc5ceb0 100644 --- a/Examples/UpcomingLaunchesApp/Program.cs +++ b/Examples/UpcomingLaunchesApp/Program.cs @@ -1,46 +1,80 @@ using System; +using System.Diagnostics; +using System.Globalization; using System.Linq; +using System.Threading.Tasks; using Newtonsoft.Json.Serialization; using Oddity; +using Oddity.Models.Launches; +using Oddity.Models.Payloads; namespace UpcomingLaunchesApp { public class Program { - public static void Main(string[] args) + public static async Task Main(string[] args) { var oddity = new OddityCore(); + var stopWatch = Stopwatch.StartNew(); + oddity.OnDeserializationError += OddityOnOnDeserializationError; - DisplayNextLaunch(oddity); - DisplayRestOfUpcomingLaunches(oddity); + await DisplayNextLaunch(oddity); + await DisplayRestOfUpcomingLaunches(oddity); + Console.WriteLine($"Generated in {stopWatch.Elapsed.TotalSeconds:F1} seconds"); Console.Read(); } - - private static void DisplayNextLaunch(OddityCore oddity) + + private static async Task DisplayNextLaunch(OddityCore oddity) { - var nextLaunchData = oddity.Launches.GetNext().Execute(); + var nextLaunchData = await oddity.LaunchesEndpoint.GetNext().ExecuteAsync(); + var formattedDate = GetFormattedDate(nextLaunchData.DateUtc, nextLaunchData.DatePrecision); Console.WriteLine("Next launch data:"); Console.WriteLine("---------------------------------------------------------------------------"); - Console.WriteLine("Mission name | " + nextLaunchData.MissionName); - Console.WriteLine("Launchpad | " + nextLaunchData.LaunchSite.SiteLongName); - Console.WriteLine("Launch date UTC | " + nextLaunchData.LaunchDateUtc); - Console.WriteLine("Rocket | " + nextLaunchData.Rocket.RocketName); - Console.WriteLine("Payloads | " + string.Join(',', nextLaunchData.Rocket.SecondStage.Payloads.Select(p => p.PayloadId))); + Console.WriteLine("Mission name | " + nextLaunchData.Name); + Console.WriteLine("Launchpad | " + nextLaunchData.Launchpad.Value.FullName); + Console.WriteLine("Launch date UTC | " + formattedDate); + Console.WriteLine("Rocket | " + nextLaunchData.Rocket.Value.Name); + Console.WriteLine("Payloads | " + string.Join(',', nextLaunchData.Payloads.Select(p => GetPayloadInfo(p.Value)))); Console.WriteLine(); } - private static void DisplayRestOfUpcomingLaunches(OddityCore oddity) + private static async Task DisplayRestOfUpcomingLaunches(OddityCore oddity) { - var upcomingLaunches = oddity.Launches.GetUpcoming().Execute(); + var upcomingLaunches = await oddity.LaunchesEndpoint.GetUpcoming().ExecuteAsync(); Console.WriteLine("All upcoming launches:"); Console.WriteLine("---------------------------------------------------------------------------"); + foreach (var launch in upcomingLaunches) { - Console.WriteLine($"{launch.MissionName} ({launch.LaunchDateUtc}) at {launch.LaunchSite.SiteName}"); + var formattedDate = GetFormattedDate(launch.DateUtc, launch.DatePrecision); + Console.WriteLine($"{launch.Name} ({formattedDate}) at {launch.Launchpad.Value.FullName}"); + } + + Console.WriteLine(); + } + + private static string GetPayloadInfo(PayloadInfo payload) + { + return payload.MassKilograms.HasValue ? $"{payload.Name} ({payload.MassKilograms} kg)" : payload.Name; + } + + private static string GetFormattedDate(DateTime? date, DatePrecision? precision) + { + if (date == null || precision == null) + { + return null; + } + + switch (precision) + { + case DatePrecision.Hour: return date.Value.ToString("f", CultureInfo.InvariantCulture); + case DatePrecision.Day: return date.Value.ToString("D", CultureInfo.InvariantCulture); + case DatePrecision.Month: return date.Value.ToString("Y", CultureInfo.InvariantCulture); + default: return date.Value.ToString("yyyy", CultureInfo.InvariantCulture); } } diff --git a/Examples/UpcomingLaunchesApp/UpcomingLaunchesApp.csproj b/Examples/UpcomingLaunchesApp/UpcomingLaunchesApp.csproj index c6f7159..2638a80 100644 --- a/Examples/UpcomingLaunchesApp/UpcomingLaunchesApp.csproj +++ b/Examples/UpcomingLaunchesApp/UpcomingLaunchesApp.csproj @@ -3,6 +3,7 @@ Exe netcoreapp2.0 + latest diff --git a/LICENSE b/LICENSE index 261eeb9..c7ce610 100644 --- a/LICENSE +++ b/LICENSE @@ -1,201 +1,21 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +MIT License + +Copyright (c) 2020 Tearth + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/Oddity.sln b/Oddity.sln index 11647c8..de70565 100644 --- a/Oddity.sln +++ b/Oddity.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27428.2037 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30011.22 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oddity", "Oddity\Oddity.csproj", "{700BB803-0731-47F0-BDA2-548866F9BABF}" EndProject @@ -14,9 +14,12 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F775217C-02FC-416C-BA91-365B4EF5C21B}" ProjectSection(SolutionItems) = preProject CHANGELOG.md = CHANGELOG.md + LICENSE = LICENSE README.md = README.md EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StarlinkApp", "Examples\StarlinkApp\StarlinkApp.csproj", "{9D5F6F6F-F11E-487F-AED3-47D367B85277}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -35,6 +38,10 @@ Global {38639F3F-2E63-46E0-BA14-E48271155135}.Debug|Any CPU.Build.0 = Debug|Any CPU {38639F3F-2E63-46E0-BA14-E48271155135}.Release|Any CPU.ActiveCfg = Release|Any CPU {38639F3F-2E63-46E0-BA14-E48271155135}.Release|Any CPU.Build.0 = Release|Any CPU + {9D5F6F6F-F11E-487F-AED3-47D367B85277}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9D5F6F6F-F11E-487F-AED3-47D367B85277}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9D5F6F6F-F11E-487F-AED3-47D367B85277}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9D5F6F6F-F11E-487F-AED3-47D367B85277}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -42,6 +49,7 @@ Global GlobalSection(NestedProjects) = preSolution {5A98F1DA-75D2-45B9-876A-D2827EA7697A} = {61A58620-C814-4639-81F5-99BDCAAA9F37} {38639F3F-2E63-46E0-BA14-E48271155135} = {61A58620-C814-4639-81F5-99BDCAAA9F37} + {9D5F6F6F-F11E-487F-AED3-47D367B85277} = {61A58620-C814-4639-81F5-99BDCAAA9F37} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {7D04DC6E-0A9B-46C0-A9B2-379C21BE1DF7} diff --git a/Oddity/API/Api.cs b/Oddity/API/Api.cs deleted file mode 100644 index 404695d..0000000 --- a/Oddity/API/Api.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Net.Http; -using Oddity.API.Builders; -using Oddity.API.Builders.Api; - -namespace Oddity.API -{ - /// - /// Represents a set of methods to get capsules information. - /// - public class Api - { - private readonly HttpClient _httpClient; - private readonly BuilderDelegatesContainer _builderDelegatesContainer; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public Api(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) - { - _httpClient = httpClient; - _builderDelegatesContainer = builderDelegatesContainer; - } - - /// - /// Gets information about the API. - /// - /// The API builder. - public ApiBuilder GetInfo() - { - return new ApiBuilder(_httpClient, _builderDelegatesContainer); - } - } -} diff --git a/Oddity/API/Builders/Api/ApiBuilder.cs b/Oddity/API/Builders/Api/ApiBuilder.cs deleted file mode 100644 index 9a8d558..0000000 --- a/Oddity/API/Builders/Api/ApiBuilder.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Oddity.API.Models.Api; - -namespace Oddity.API.Builders.Api -{ - /// - /// Represents a set of methods to retrieve information about API. - /// - public class ApiBuilder : BuilderBase - { - private const string ApiEndpoint = ""; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public ApiBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - protected override async Task ExecuteBuilder() - { - var link = BuildLink(ApiEndpoint); - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} diff --git a/Oddity/API/Builders/BuilderBase.cs b/Oddity/API/Builders/BuilderBase.cs deleted file mode 100644 index e6d21af..0000000 --- a/Oddity/API/Builders/BuilderBase.cs +++ /dev/null @@ -1,219 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Net; -using System.Net.Http; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; -using Oddity.API.Exceptions; - -namespace Oddity.API.Builders -{ - /// - /// Represents an abstract base class for all builders. - /// - public abstract class BuilderBase - { - /// - /// Gets or sets the http client which sends requests to the SpaceX API. - /// - protected HttpClient HttpClient { get; } - - private readonly BuilderDelegatesContainer _builderDelegatesContainer; - private readonly Dictionary _filters; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - protected BuilderBase(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) - { - HttpClient = httpClient; - - _builderDelegatesContainer = builderDelegatesContainer; - _filters = new Dictionary(); - } - - /// - /// Executes all filters and downloads result from API. If object with the specified filters is not available, - /// returns null or empty list (depends on which data is requested). - /// - /// The all capsules information or null/empty list if object is not available. - /// Thrown when SpaceX API is unavailable. - public TReturn Execute() - { - return ExecuteBuilder().GetAwaiter().GetResult(); - } - - /// - /// Executes all filters and downloads result from API asynchronously. If object with the specified filters is not available, - /// returns null or empty list (depends on which data is requested). - /// - /// The all capsules information or null/empty list if object is not available. - /// Thrown when SpaceX API is unavailable. - public async Task ExecuteAsync() - { - return await ExecuteBuilder().ConfigureAwait(false); - } - - /// - /// The main method of every builder. Builds request, retrieves data from API and deserializes JSON. - /// - /// The deserialized JSON. - protected abstract Task ExecuteBuilder(); - - /// - /// Adds or overrides filter with the specified name and integer value. - /// - /// The filter name. - /// The filter integer value. - protected void AddFilter(string name, int value) - { - _filters[name] = value.ToString(); - } - - /// - /// Adds or overrides filter with the specified name and double value. - /// - /// The filter name. - /// The filter double value. - protected void AddFilter(string name, double value) - { - _filters[name] = value.ToString(CultureInfo.InvariantCulture); - } - - /// - /// Adds or overrides filter with the specified name and string value. - /// - /// The filter name. - /// The filter string value. - protected void AddFilter(string name, string value) - { - _filters[name] = value; - } - - /// - /// Adds or overrides filter with the specified name and boolean value. - /// - /// The filter name. - /// The filter boolean value. - protected void AddFilter(string name, bool value) - { - _filters[name] = value.ToString().ToLower(); - } - - /// - /// Adds or overrides filter with the specified name and date value. - /// - /// The filter name. - /// The filter date value. - protected void AddFilter(string name, DateTime value) - { - _filters[name] = value.ToString("O"); - } - - /// - /// Adds or overrides filter with the specified name and DateTime value. - /// - /// The filter name. - /// The filter DateTime value. - /// Short (only date) and long (date and time). - protected void AddFilter(string name, DateTime value, DateFormatType formatType) - { - switch (formatType) - { - case DateFormatType.Short: - { - _filters[name] = value.ToString("yyyy-MM-dd"); - break; - } - - case DateFormatType.Long: - { - _filters[name] = value.ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'"); - break; - } - } - } - - /// - /// Build an link to the API with the specified endpoint and applied filters. - /// - /// The API endpoint. - /// The link to the API ready to call. - protected string BuildLink(string endpoint) - { - var stringBuilder = new StringBuilder(); - stringBuilder.Append(endpoint); - - var filters = SerializeFilters(); - if (!string.IsNullOrEmpty(filters)) - { - stringBuilder.Append("?"); - stringBuilder.Append(filters); - } - - return stringBuilder.ToString(); - } - - /// - /// Sends an request to the SpaceX API with the specified link. - /// - /// The request link. - /// The deserialized object returned from API. - /// Thrown when SpaceX is unavailable and data can't be retrieved. - protected async Task SendRequestToApi(string link) - { - _builderDelegatesContainer.RequestSend(new RequestSendEventArgs(HttpClient.BaseAddress + link, _filters)); - var response = await HttpClient.GetAsync(link).ConfigureAwait(false); - - if (response.StatusCode != HttpStatusCode.OK) - { - if (response.StatusCode == HttpStatusCode.NoContent) - { - return default(TReturn); - } - - throw new APIUnavailableException($"Status code: {(int)response.StatusCode}"); - } - - var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - _builderDelegatesContainer.ResponseReceived(new ResponseReceiveEventArgs(content, response.StatusCode, response.ReasonPhrase)); - - return DeserializeJson(content); - } - - private TReturn DeserializeJson(string content) - { - var deserializationSettings = new JsonSerializerSettings { Error = JsonDeserializationError }; - return JsonConvert.DeserializeObject(content, deserializationSettings); - } - - private void JsonDeserializationError(object sender, ErrorEventArgs errorEventArgs) - { - _builderDelegatesContainer.DeserializationError(errorEventArgs); - } - - private string SerializeFilters() - { - var stringBuilder = new StringBuilder(); - var first = true; - - foreach (var filter in _filters) - { - if (!first) - { - stringBuilder.Append("&"); - } - - stringBuilder.Append($"{filter.Key}={filter.Value}"); - first = false; - } - - return stringBuilder.ToString(); - } - } -} diff --git a/Oddity/API/Builders/BuilderDelegatesContainer.cs b/Oddity/API/Builders/BuilderDelegatesContainer.cs deleted file mode 100644 index fe11532..0000000 --- a/Oddity/API/Builders/BuilderDelegatesContainer.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Newtonsoft.Json.Serialization; - -namespace Oddity.API.Builders -{ - public delegate void DeserializationError(ErrorEventArgs args); - public delegate void RequestSend(RequestSendEventArgs args); - public delegate void ResponseReceived(ResponseReceiveEventArgs args); - - public class BuilderDelegatesContainer - { - public DeserializationError DeserializationError { get; set; } - public RequestSend RequestSend { get; set; } - public ResponseReceived ResponseReceived { get; set; } - } -} diff --git a/Oddity/API/Builders/Capsules/AllCapsulesBuilder.cs b/Oddity/API/Builders/Capsules/AllCapsulesBuilder.cs deleted file mode 100644 index 80dd575..0000000 --- a/Oddity/API/Builders/Capsules/AllCapsulesBuilder.cs +++ /dev/null @@ -1,35 +0,0 @@ -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 -{ - /// - /// Represents a set of methods to filter all capsules information and download them from API. - /// - public class AllCapsulesBuilder : CapsuleBuilderBase> - { - private const string CapsuleInfoEndpoint = "capsules"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public AllCapsulesBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - protected override async Task> ExecuteBuilder() - { - var link = BuildLink(CapsuleInfoEndpoint); - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} diff --git a/Oddity/API/Builders/Capsules/CapsuleBuilder.cs b/Oddity/API/Builders/Capsules/CapsuleBuilder.cs deleted file mode 100644 index 929fb21..0000000 --- a/Oddity/API/Builders/Capsules/CapsuleBuilder.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Oddity.API.Models.Capsule; - -namespace Oddity.API.Builders.Capsules -{ - /// - /// Represents a set of methods to filter capsule information and download them from API. - /// - public class CapsuleBuilder : BuilderBase - { - private string _capsuleSerial; - private const string CapsuleInfoEndpoint = "capsules"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public CapsuleBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - /// Filters capsule information by the specified capsule serial. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved capsule serial filter. - /// - /// The capsule serial (C101, C102, etc). - /// The capsule information. - public CapsuleBuilder WithSerial(string capsuleSerial) - { - _capsuleSerial = capsuleSerial; - return this; - } - - /// - protected override async Task ExecuteBuilder() - { - var link = BuildLink(CapsuleInfoEndpoint); - if (_capsuleSerial != null) - { - link += $"/{_capsuleSerial.ToUpper()}"; - } - - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} diff --git a/Oddity/API/Builders/Capsules/CapsuleBuilderBase.cs b/Oddity/API/Builders/Capsules/CapsuleBuilderBase.cs deleted file mode 100644 index 8664e29..0000000 --- a/Oddity/API/Builders/Capsules/CapsuleBuilderBase.cs +++ /dev/null @@ -1,122 +0,0 @@ -using System; -using System.Net.Http; -using Oddity.API.Models.Capsule; -using Oddity.API.Models.Dragon; -using Oddity.Helpers; - -namespace Oddity.API.Builders.Capsules -{ - /// - /// Represents an abstract class for all capsule builders. Contains methods to the detailed filters that aren't present in other builders. - /// - /// The launch builder type. - /// The returned object type. - public abstract class CapsuleBuilderBase : BuilderBase where TBuilder : CapsuleBuilderBase where TReturn : class - { - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - protected CapsuleBuilderBase(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - /// Filters launches by capsule serial. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved capsule serial filter. - /// - /// The capsule serial (C101, C102, etc). - /// The capsules builder. - public TBuilder WithCapsuleSerial(string capsuleSerial) - { - AddFilter("capsule_serial", capsuleSerial); - return (TBuilder)this; - } - - /// - /// Filters launches by capsule id. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved capsule id filter. - /// - /// The capsule id (Dragon 1, Dragon 2 etc). - /// The capsules builder. - public TBuilder WithCapsuleId(DragonId capsuleId) - { - AddFilter("capsule_id", capsuleId.GetEnumMemberAttributeValue(capsuleId)); - return (TBuilder)this; - } - - /// - /// Filters launches by capsule status. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved capsule status filter. - /// - /// The capsule status (active, retired etc). - /// The capsules builder. - public TBuilder WithStatus(CapsuleStatus status) - { - AddFilter("status", status.GetEnumMemberAttributeValue(status)); - return (TBuilder)this; - } - - /// - /// Filters launches by original launch. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved original launch filter. - /// - /// The capsule original launch. - /// The capsules builder. - public TBuilder WithOriginalLaunch(DateTime originalLaunch) - { - AddFilter("original_launch", originalLaunch, DateFormatType.Long); - return (TBuilder)this; - } - - /// - /// Filters launches by missions. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved missions filter. - /// - /// The capsule mission (SpaceX CRS-8, ZUMA, etc). - /// The capsules builder. - public TBuilder WithMission(string mission) - { - AddFilter("mission", mission); - return (TBuilder)this; - } - - /// - /// Filters launches by landings count. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved landings count filter. - /// - /// Landing count. - /// The capsules builder. - public TBuilder WithLandingsCount(int landingsCount) - { - AddFilter("landings", landingsCount); - return (TBuilder)this; - } - - /// - /// Filters launches by capsule type. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved capsule type filter. - /// - /// The capsule type (Dragon 1.1, Dragon 2.0, etc). - /// The capsules builder. - public TBuilder WithCapsuleType(string capsuleType) - { - AddFilter("type", capsuleType); - return (TBuilder)this; - } - - /// - /// Filters launches by reuse count. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved landings count filter. - /// - /// Reuse count. - /// The capsules builder. - public TBuilder WithReuseCount(int reuseCount) - { - AddFilter("reuse_count", reuseCount); - return (TBuilder)this; - } - } -} \ No newline at end of file diff --git a/Oddity/API/Builders/Capsules/PastCapsulesBuilder.cs b/Oddity/API/Builders/Capsules/PastCapsulesBuilder.cs deleted file mode 100644 index 3320fd3..0000000 --- a/Oddity/API/Builders/Capsules/PastCapsulesBuilder.cs +++ /dev/null @@ -1,35 +0,0 @@ -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 -{ - /// - /// Represents a set of methods to filter all upcoming capsules information and download them from API. - /// - public class PastCapsulesBuilder : CapsuleBuilderBase> - { - private const string CapsuleInfoEndpoint = "capsules/past"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public PastCapsulesBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - protected override async Task> ExecuteBuilder() - { - var link = BuildLink(CapsuleInfoEndpoint); - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} \ No newline at end of file diff --git a/Oddity/API/Builders/Capsules/UpcomingCapsulesBuilder.cs b/Oddity/API/Builders/Capsules/UpcomingCapsulesBuilder.cs deleted file mode 100644 index c548d35..0000000 --- a/Oddity/API/Builders/Capsules/UpcomingCapsulesBuilder.cs +++ /dev/null @@ -1,35 +0,0 @@ -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 -{ - /// - /// Represents a set of methods to filter all upcoming capsules information and download them from API. - /// - public class UpcomingCapsulesBuilder : CapsuleBuilderBase> - { - private const string CapsuleInfoEndpoint = "capsules/upcoming"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public UpcomingCapsulesBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - protected override async Task> ExecuteBuilder() - { - var link = BuildLink(CapsuleInfoEndpoint); - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} \ No newline at end of file diff --git a/Oddity/API/Builders/Company/InfoBuilder.cs b/Oddity/API/Builders/Company/InfoBuilder.cs deleted file mode 100644 index 2af78a1..0000000 --- a/Oddity/API/Builders/Company/InfoBuilder.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Oddity.API.Models.Company; - -namespace Oddity.API.Builders.Company -{ - /// - /// Represents a set of methods to filter company information and download them from API. - /// - public class InfoBuilder : BuilderBase - { - private const string CompanyInfoEndpoint = "info"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public InfoBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - protected override async Task ExecuteBuilder() - { - var link = BuildLink(CompanyInfoEndpoint); - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} diff --git a/Oddity/API/Builders/Cores/AllCoresBuilder.cs b/Oddity/API/Builders/Cores/AllCoresBuilder.cs deleted file mode 100644 index e0f213e..0000000 --- a/Oddity/API/Builders/Cores/AllCoresBuilder.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Threading.Tasks; -using Oddity.API.Models.DetailedCore; -using Oddity.Helpers; - -namespace Oddity.API.Builders.Cores -{ - /// - /// Represents a set of methods to filter all cores information and download them from API. - /// - public class AllCoresBuilder : CoreBuilderBase> - { - private const string CapsuleInfoEndpoint = "cores"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public AllCoresBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - protected override async Task> ExecuteBuilder() - { - var link = BuildLink(CapsuleInfoEndpoint); - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} diff --git a/Oddity/API/Builders/Cores/CoreBuilder.cs b/Oddity/API/Builders/Cores/CoreBuilder.cs deleted file mode 100644 index 9a7d8cf..0000000 --- a/Oddity/API/Builders/Cores/CoreBuilder.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Oddity.API.Models.DetailedCore; - -namespace Oddity.API.Builders.Cores -{ - /// - /// Represents a set of methods to filter core information and download them from API. - /// - public class CoreBuilder : BuilderBase - { - private string _coreSerial; - private const string CapsuleInfoEndpoint = "cores"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public CoreBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - /// Filters capsule information by the specified core serial. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved core serial filter. - /// - /// The capsule serial (C101, C113, etc). - /// The capsule information. - public CoreBuilder WithSerial(string coreSerial) - { - _coreSerial = coreSerial; - return this; - } - - /// - protected override async Task ExecuteBuilder() - { - var link = BuildLink(CapsuleInfoEndpoint); - if (_coreSerial != null) - { - link += $"/{_coreSerial.ToUpper()}"; - } - - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} diff --git a/Oddity/API/Builders/Cores/CoreBuilderBase.cs b/Oddity/API/Builders/Cores/CoreBuilderBase.cs deleted file mode 100644 index 7d725bb..0000000 --- a/Oddity/API/Builders/Cores/CoreBuilderBase.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System; -using System.Net.Http; -using Oddity.API.Models.DetailedCore; -using Oddity.Helpers; - -namespace Oddity.API.Builders.Cores -{ - /// - /// Represents an abstract class for all core builders. Contains methods to the detailed filters that aren't present in other builders. - /// - /// The launch builder type. - /// The returned object type. - public abstract class CoreBuilderBase : BuilderBase where TBuilder : CoreBuilderBase where TReturn : class - { - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - protected CoreBuilderBase(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - /// Filters launches by core serial. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved core serial filter. - /// - /// The core serial (B0005, B1012, etc). - /// The all cores builder. - public TBuilder WithCoreSerial(string coreSerial) - { - AddFilter("core_serial", coreSerial); - return (TBuilder)this; - } - - /// - /// Filters launches by core block number. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved core block number filter. - /// - /// The block number. - /// The all cores builder. - public TBuilder WithBlock(int block) - { - AddFilter("block", block); - return (TBuilder)this; - } - - /// - /// Filters launches by core status. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved core status filter. - /// - /// The core status (active, destroyed, etc). - /// The all cores builder. - public TBuilder WithStatus(CoreStatus status) - { - AddFilter("status", status.GetEnumMemberAttributeValue(status)); - return (TBuilder)this; - } - - /// - /// Filters launches by original launch. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved original launch filter. - /// - /// The core original launch. - /// vThe all cores builder. - public TBuilder WithOriginalLaunch(DateTime originalLaunch) - { - AddFilter("original_launch", originalLaunch, DateFormatType.Long); - return (TBuilder)this; - } - - /// - /// Filters launches by missions. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved missions filter. - /// - /// The core mission. - /// The all cores builder. - public TBuilder WithMission(string mission) - { - AddFilter("mission", mission); - return (TBuilder)this; - } - - /// - /// Filters launches by RTLS landing. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved RTLS landing filter. - /// - /// The core RTLS (return to launch site) landings count. - /// The all cores builder. - public TBuilder WithRtlsLanding(int rtlsLandings) - { - AddFilter("rtls_landings", rtlsLandings); - return (TBuilder)this; - } - - /// - /// Filters launches by ASDS landing. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved ASDS landing filter. - /// - /// The core ASDS (autonomous spaceport drone ship) landings count. - /// The all cores builder. - public TBuilder WithAsdsLanding(int asdsLandings) - { - AddFilter("asds_landings", asdsLandings); - return (TBuilder)this; - } - - /// - /// Filters launches by water landing. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved water landing filter. - /// - /// The core water landing. - /// The all cores builder. - public TBuilder WithWaterLanding(bool waterLanding) - { - AddFilter("water_landing", waterLanding); - return (TBuilder)this; - } - } -} \ No newline at end of file diff --git a/Oddity/API/Builders/Cores/PastCoresBuilder.cs b/Oddity/API/Builders/Cores/PastCoresBuilder.cs deleted file mode 100644 index b280edc..0000000 --- a/Oddity/API/Builders/Cores/PastCoresBuilder.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Threading.Tasks; -using Oddity.API.Models.DetailedCore; -using Oddity.Helpers; - -namespace Oddity.API.Builders.Cores -{ - /// - /// Represents a set of methods to filter past cores information and download them from API. - /// - public class PastCoresBuilder : CoreBuilderBase> - { - private const string CapsuleInfoEndpoint = "cores/past"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public PastCoresBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - protected override async Task> ExecuteBuilder() - { - var link = BuildLink(CapsuleInfoEndpoint); - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} \ No newline at end of file diff --git a/Oddity/API/Builders/Cores/UpcomingCoresBuilder.cs b/Oddity/API/Builders/Cores/UpcomingCoresBuilder.cs deleted file mode 100644 index 1ee7d09..0000000 --- a/Oddity/API/Builders/Cores/UpcomingCoresBuilder.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Threading.Tasks; -using Oddity.API.Models.DetailedCore; -using Oddity.Helpers; - -namespace Oddity.API.Builders.Cores -{ - /// - /// Represents a set of methods to filter upcoming cores information and download them from API. - /// - public class UpcomingCoresBuilder : CoreBuilderBase> - { - private const string CapsuleInfoEndpoint = "cores/upcoming"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public UpcomingCoresBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - protected override async Task> ExecuteBuilder() - { - var link = BuildLink(CapsuleInfoEndpoint); - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} \ No newline at end of file diff --git a/Oddity/API/Builders/DateFormatType.cs b/Oddity/API/Builders/DateFormatType.cs deleted file mode 100644 index d1c2837..0000000 --- a/Oddity/API/Builders/DateFormatType.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Oddity.API.Builders -{ - /// - /// Represents the types of date: short (only date) and long (date and time). - /// - public enum DateFormatType - { - Short, - Long - } -} diff --git a/Oddity/API/Builders/Dragons/AllDragonsBuilder.cs b/Oddity/API/Builders/Dragons/AllDragonsBuilder.cs deleted file mode 100644 index d380d41..0000000 --- a/Oddity/API/Builders/Dragons/AllDragonsBuilder.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Collections.Generic; -using System.Net.Http; -using System.Threading.Tasks; -using Oddity.API.Models.Dragon; - -namespace Oddity.API.Builders.Dragons -{ - /// - /// Represents a set of methods to filter all Dragon types information and download them from API. - /// - public class AllDragonsBuilder : BuilderBase> - { - private const string DragonEndpoint = "dragons"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public AllDragonsBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - protected override async Task> ExecuteBuilder() - { - var link = BuildLink(DragonEndpoint); - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} diff --git a/Oddity/API/Builders/Dragons/DragonBuilder.cs b/Oddity/API/Builders/Dragons/DragonBuilder.cs deleted file mode 100644 index cc5ecaf..0000000 --- a/Oddity/API/Builders/Dragons/DragonBuilder.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Oddity.API.Models.Dragon; - -namespace Oddity.API.Builders.Dragons -{ - /// - /// Represents a set of methods to filter Dragon type information and download them from API. - /// - public class DragonBuilder : BuilderBase - { - private DragonId? _capsuleType; - private const string DragonsEndpoint = "dragons"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public DragonBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - /// Filters Dragon type information by the specified capsule type. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved capsule type filter. - /// - /// The capsule type (Dragon1, Dragon2, etc). - /// The capsule information. - public DragonBuilder WithType(DragonId type) - { - _capsuleType = type; - return this; - } - - /// - protected override async Task ExecuteBuilder() - { - var link = BuildLink(DragonsEndpoint); - if (_capsuleType.HasValue) - { - link += $"/{_capsuleType.ToString().ToLower()}"; - } - - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} diff --git a/Oddity/API/Builders/History/EventBuilder.cs b/Oddity/API/Builders/History/EventBuilder.cs deleted file mode 100644 index 963fd67..0000000 --- a/Oddity/API/Builders/History/EventBuilder.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Oddity.API.Models.History; - -namespace Oddity.API.Builders.History -{ - /// - /// Represents a set of methods to filter history event and download them from API. - /// - public class EventBuilder : BuilderBase - { - private int? _eventId; - private const string CapsuleInfoEndpoint = "history"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public EventBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - /// Filters history event information by the specified ID. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved capsule serial filter. - /// - /// The history event ID. - /// The history event information. - public EventBuilder WithId(int eventId) - { - _eventId = eventId; - return this; - } - - /// - protected override async Task ExecuteBuilder() - { - var link = BuildLink(CapsuleInfoEndpoint); - if (_eventId != null) - { - link += $"/{_eventId.ToString().ToUpper()}"; - } - - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} diff --git a/Oddity/API/Builders/History/HistoryBuilder.cs b/Oddity/API/Builders/History/HistoryBuilder.cs deleted file mode 100644 index 8618238..0000000 --- a/Oddity/API/Builders/History/HistoryBuilder.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Threading.Tasks; -using Oddity.API.Models.History; - -namespace Oddity.API.Builders.History -{ - /// - /// Represents a set of methods to filter history events and download them from API. - /// - public class HistoryBuilder : BuilderBase> - { - private const string CompanyHistoryEndpoint = "history"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public HistoryBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - /// Filters history events by date range. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved date range filter. - /// - /// Filter from the specified date. - /// Filter to the specified date. - /// The history builder. - public HistoryBuilder WithRange(DateTime from, DateTime to) - { - AddFilter("start", from, DateFormatType.Short); - AddFilter("end", to, DateFormatType.Short); - return this; - } - - /// - /// Filters history events by flight number. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved flight number filter. - /// - /// The flight number. - /// The history builder. - public HistoryBuilder WithFlightNumber(int flightNumber) - { - AddFilter("order", flightNumber); - return this; - } - - /// - /// Sorts history events ascending. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved ordering filter. - /// - /// The history builder. - public HistoryBuilder Ascending() - { - AddFilter("order", "asc"); - return this; - } - - /// - /// Sorts history events descending. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved ordering filter. - /// - /// The history builder. - public HistoryBuilder Descending() - { - AddFilter("order", "desc"); - return this; - } - - /// - protected override async Task> ExecuteBuilder() - { - var link = BuildLink(CompanyHistoryEndpoint); - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} diff --git a/Oddity/API/Builders/Launches/AllLaunchesBuilder.cs b/Oddity/API/Builders/Launches/AllLaunchesBuilder.cs deleted file mode 100644 index 203a874..0000000 --- a/Oddity/API/Builders/Launches/AllLaunchesBuilder.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Collections.Generic; -using System.Net.Http; -using System.Threading.Tasks; -using Oddity.API.Models.Launch; - -namespace Oddity.API.Builders.Launches -{ - /// - /// Represents a set of methods to filter all launches information and download them from API. - /// - public class AllLaunchesBuilder : LaunchBuilderBase> - { - private const string LaunchpadInfoEndpoint = "launches"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public AllLaunchesBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - protected override async Task> ExecuteBuilder() - { - var link = BuildLink(LaunchpadInfoEndpoint); - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} diff --git a/Oddity/API/Builders/Launches/LatestLaunchBuilder.cs b/Oddity/API/Builders/Launches/LatestLaunchBuilder.cs deleted file mode 100644 index 46796d5..0000000 --- a/Oddity/API/Builders/Launches/LatestLaunchBuilder.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Oddity.API.Models.Launch; - -namespace Oddity.API.Builders.Launches -{ - /// - /// Represents a set of methods to filter past launch information and download them from API. - /// - public class LatestLaunchesBuilder : BuilderBase - { - private const string LaunchesEndpoint = "launches/latest"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public LatestLaunchesBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - protected override async Task ExecuteBuilder() - { - var link = BuildLink(LaunchesEndpoint); - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} diff --git a/Oddity/API/Builders/Launches/LaunchBuilder.cs b/Oddity/API/Builders/Launches/LaunchBuilder.cs deleted file mode 100644 index 5d75f70..0000000 --- a/Oddity/API/Builders/Launches/LaunchBuilder.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Oddity.API.Models.Launch; - -namespace Oddity.API.Builders.Launches -{ - /// - /// Represents a set of methods to get the specified launch information and download them from API. - /// - public class LaunchBuilder : BuilderBase - { - private int? _launchId; - private const string LaunchesEndpoint = "launches"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public LaunchBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - /// Filters launch information by the specified ID. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved capsule serial filter. - /// - /// The launch ID. - /// The launch information. - public LaunchBuilder WithId(int launchId) - { - _launchId = launchId; - return this; - } - - /// - protected override async Task ExecuteBuilder() - { - var link = BuildLink(LaunchesEndpoint); - if (_launchId != null) - { - link += $"/{_launchId.ToString().ToUpper()}"; - } - - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} \ No newline at end of file diff --git a/Oddity/API/Builders/Launches/LaunchBuilderBase.cs b/Oddity/API/Builders/Launches/LaunchBuilderBase.cs deleted file mode 100644 index f448bcb..0000000 --- a/Oddity/API/Builders/Launches/LaunchBuilderBase.cs +++ /dev/null @@ -1,629 +0,0 @@ -using System; -using System.Net.Http; -using Oddity.API.Models.Launch.Rocket.FirstStage; -using Oddity.API.Models.Launch.Rocket.SecondStage.Orbit; -using Oddity.API.Models.Launchpad; -using Oddity.API.Models.Rocket; -using Oddity.Helpers; - -namespace Oddity.API.Builders.Launches -{ - /// - /// Represents an abstract class for all launch builders. Contains methods to the detailed filters that aren't present in other builders. - /// - /// The launch builder type. - /// The returned object type. - public abstract class LaunchBuilderBase : BuilderBase where TBuilder: LaunchBuilderBase where TReturn: class - { - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - protected LaunchBuilderBase(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - /// Sorts launches ascending. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved ordering filter. - /// - /// The launch builder. - public TBuilder Ascending() - { - AddFilter("order", "asc"); - return (TBuilder)this; - } - - /// - /// Sorts launches descending. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved ordering filter. - /// - /// The launch builder. - public TBuilder Descending() - { - AddFilter("order", "desc"); - return (TBuilder)this; - } - - /// - /// Filters launches by date range. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved date range filter. - /// - /// Filter from the specified date. - /// Filter to the specified date. - /// The launch builder. - public TBuilder WithRange(DateTime from, DateTime to) - { - AddFilter("start", from, DateFormatType.Short); - AddFilter("end", to, DateFormatType.Short); - return (TBuilder)this; - } - - /// - /// Filters launches by flight number. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved flight number filter. - /// - /// The launch flight number. - /// The launch builder. - public TBuilder WithFlightNumber(int flightNumber) - { - AddFilter("flight_number", flightNumber); - return (TBuilder)this; - } - - /// - /// Filters launches by launch year. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved launch year filter. - /// - /// The launch year. - /// The launch builder. - public TBuilder WithLaunchYear(int year) - { - AddFilter("launch_year", year); - return (TBuilder)this; - } - - /// - /// Filters launches by UTC launch date. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved launch date filter. - /// - /// The UTC launch date. - /// The launch builder. - public TBuilder WithLaunchDateUtc(DateTime launchDateUtc) - { - AddFilter("launch_date_utc", launchDateUtc, DateFormatType.Long); - return (TBuilder)this; - } - - /// - /// Filters launches by local launch date. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved launch date filter. - /// - /// The local launch date. - /// The launch builder. - public TBuilder WithLaunchDateLocal(DateTime launchDateLocal) - { - AddFilter("launch_date_local", launchDateLocal, DateFormatType.Long); - return (TBuilder)this; - } - - /// - /// Filters launches by "to be dated" flag. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved rocket id filter. - /// - /// "To be dated" flag. - /// The launch builder. - public TBuilder WithToBeDated(bool toBeDated) - { - AddFilter("tbd", toBeDated); - return (TBuilder)this; - } - - /// - /// Filters launches by rocket id. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved rocket id filter. - /// - /// The rocket ID (Falcon1, Falcon9, etc). - /// The launch builder. - public TBuilder WithRocketId(RocketId rocketId) - { - AddFilter("rocket_id", rocketId.GetEnumMemberAttributeValue(rocketId)); - return (TBuilder)this; - } - - /// - /// Filters launches by rocket name. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved rocket name filter. - /// - /// The rocket name (Falcon 1, Falcon 9, etc). - /// The launch builder. - public TBuilder WithRocketName(string rocketName) - { - AddFilter("rocket_name", rocketName); - return (TBuilder)this; - } - - /// - /// Filters launches by rocket type. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved rocket type filter. - /// - /// The rocket type (v1.0, FT, etc). - /// The launch builder. - public TBuilder WithRocketType(string rocketType) - { - AddFilter("rocket_type", rocketType); - return (TBuilder)this; - } - - /// - /// Filters launches by core serial. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved core serial filter. - /// - /// The core serial (B0005, B1012, etc). - /// The launch builder. - public TBuilder WithCoreSerial(string coreSerial) - { - AddFilter("core_serial", coreSerial); - return (TBuilder)this; - } - - /// - /// Filters launches by a landing success. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved core serial filter. - /// - /// Land success flag. - /// The launch builder. - public TBuilder WithLandSuccess(bool landSuccess) - { - AddFilter("land_success", landSuccess); - return (TBuilder)this; - } - - /// - /// Filters launches by landing intention. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved core serial filter. - /// - /// Landing intention flag. - /// The launch builder. - public TBuilder WithLandingIntent(bool landingIntent) - { - AddFilter("landing_intent", landingIntent); - return (TBuilder)this; - } - - - /// - /// Filters launches by landing type. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved landing type filter. - /// - /// The landing type (ASDS, Ocean, etc). - /// The launch builder. - public TBuilder WithLandingType(LandingType landingType) - { - AddFilter("landing_type", landingType.GetEnumMemberAttributeValue(landingType)); - return (TBuilder)this; - } - - /// - /// Filters launches by landing vehicle. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved landing vehicle filter. - /// - /// The landing vehicle (OCISLY, LZ1, etc). - /// The launch builder. - public TBuilder WithLandingVehicle(LandingVehicleType landingVehicle) - { - AddFilter("landing_vehicle", landingVehicle.GetEnumMemberAttributeValue(landingVehicle)); - return (TBuilder)this; - } - - /// - /// Filters launches by capsule serial. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved capsule serial filter. - /// - /// The rocket serial (C110, C113, etc). - /// The launch builder. - public TBuilder WithCapsuleSerial(string capsuleSerial) - { - AddFilter("cap_serial", capsuleSerial); - return (TBuilder)this; - } - - /// - /// Filters launches by core flight number. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved core flight number filter. - /// - /// The core flight number. - /// The launch builder. - public TBuilder WithCoreFlightNumber(int flightNumber) - { - AddFilter("core_flight", flightNumber); - return (TBuilder)this; - } - - /// - /// Filters launches by block number. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved block number filter. - /// - /// The core block number. - /// The launch builder. - public TBuilder WithBlockNumber(int blockNumber) - { - AddFilter("block", blockNumber); - return (TBuilder)this; - } - - /// - /// Filters launches by grid fins presence. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved block number filter. - /// - /// Grid fins presence flag. - /// The launch builder. - public TBuilder WithGridFins(bool gridFins) - { - AddFilter("gridfins", gridFins); - return (TBuilder)this; - } - - /// - /// Filters launches by legs presence. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved block number filter. - /// - /// Legs presence flag. - /// The launch builder. - public TBuilder WithLegs(bool legs) - { - AddFilter("legs", legs); - return (TBuilder)this; - } - - /// - /// Filters launches by core reuse. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved core reuse filter. - /// - /// The core reuse. - /// The launch builder. - public TBuilder WithCoreReuse(bool coreReuse) - { - AddFilter("core_reuse", coreReuse); - return (TBuilder)this; - } - - /// - /// Filters launches by capsule reuse. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved capsule reuse filter. - /// - /// The capsule reuse. - /// The launch builder. - public TBuilder WithCapsuleReuse(bool capsuleReuse) - { - AddFilter("capsule_reuse", capsuleReuse); - return (TBuilder)this; - } - - /// - /// Filters launches by fairings reuse. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved fairings reuse filter. - /// - /// The fairings reuse. - /// The launch builder. - public TBuilder WithFairingsReuse(bool fairingsReuse) - { - AddFilter("fairings_reused", fairingsReuse); - return (TBuilder)this; - } - - /// - /// Filters launches by fairings recovery attempt. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved fairings reuse filter. - /// - /// Fairings recovery attempt flag. - /// The launch builder. - public TBuilder WithFairingsRecoveryAttempt(bool fairingsRecoveryAttempt) - { - AddFilter("fairings_recovery_attempt", fairingsRecoveryAttempt); - return (TBuilder)this; - } - - /// - /// Filters launches by fairings recovery result. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved fairings reuse filter. - /// - /// Fairings recovery status flag. - /// The launch builder. - public TBuilder WithFairingsRecovered(bool fairingsRecovered) - { - AddFilter("fairings_recovered", fairingsRecovered); - return (TBuilder)this; - } - - /// - /// Filters launches by fairings ship name. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved fairings reuse filter. - /// - /// Fairings ship name. - /// The launch builder. - public TBuilder WithFairingsShip(string fairingsShip) - { - AddFilter("fairings_ship", fairingsShip); - return (TBuilder)this; - } - - /// - /// Filters launches by site id. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved site id filter. - /// - /// The launchpad ID (CcafsSlc40, Stls, etc). - /// The launch builder. - public TBuilder WithSiteId(LaunchpadId siteId) - { - AddFilter("site_id", siteId.GetEnumMemberAttributeValue(siteId)); - return (TBuilder)this; - } - - /// - /// Filters launches by site name. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved site name filter. - /// - /// The launchpad name (KSC LC 39A, etc). - /// The launch builder. - public TBuilder WithSiteName(string siteName) - { - AddFilter("site_name", siteName); - return (TBuilder)this; - } - - /// - /// Filters launches by payload id. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved payload id filter. - /// - /// The payload ID (RatSat, Iridium NEXT 2, etc). - /// The launch builder. - public TBuilder WithPayloadId(string payloadId) - { - AddFilter("payload_id", payloadId); - return (TBuilder)this; - } - - /// - /// Filters launches by payload's NORAD ID. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved payload id filter. - /// - /// The payload NORAD ID. - /// The launch builder. - public TBuilder WithNoradId(int noradId) - { - AddFilter("norad_id", noradId); - return (TBuilder)this; - } - - /// - /// Filters launches by customer name. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved customer name filter. - /// - /// The customer (Iridium Communications, USAF, etc). - /// The launch builder. - public TBuilder WithCustomer(string customer) - { - AddFilter("customer", customer); - return (TBuilder)this; - } - - /// - /// Filters launches by customer's nationality. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved customer name filter. - /// - /// The payload's customer nationality. - /// The launch builder. - public TBuilder WithNationality(string nationality) - { - AddFilter("nationality", nationality); - return (TBuilder)this; - } - - /// - /// Filters launches by payload's manufacturer. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved customer name filter. - /// - /// The payload's manufacturer name. - /// The launch builder. - public TBuilder WithManufacturer(string manufacturer) - { - AddFilter("manufacturer", manufacturer); - return (TBuilder)this; - } - - /// - /// Filters launches by payload type. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved payload type filter. - /// - /// The customer (Satellite, Dragon 1.0, etc). - /// The launch builder. - public TBuilder WithPayloadType(string payloadType) - { - AddFilter("payload_type", payloadType); - return (TBuilder)this; - } - - /// - /// Filters launches by orbit type. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved orbit type filter. - /// - /// The orbit type (LEO, ISS, etc). - /// The launch builder. - public TBuilder WithOrbit(OrbitType orbit) - { - AddFilter("orbit", orbit.GetEnumMemberAttributeValue(orbit)); - return (TBuilder)this; - } - - /// - /// Filters launches by reference system. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved orbit type filter. - /// - /// The reference system. - /// The launch builder. - public TBuilder WithReferenceSystem(string referenceSystem) - { - AddFilter("reference_system", referenceSystem); - return (TBuilder)this; - } - - /// - /// Filters launches by orbit regime. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved orbit type filter. - /// - /// The orbit regime. - /// The launch builder. - public TBuilder WithRegime(string regime) - { - AddFilter("regime", regime); - return (TBuilder)this; - } - - /// - /// Filters launches by orbit longitude. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved orbit type filter. - /// - /// The orbit longitude. - /// The launch builder. - public TBuilder WithLongitude(double longitude) - { - AddFilter("longitude", longitude); - return (TBuilder)this; - } - - /// - /// Filters launches by orbit semi major axis. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved orbit type filter. - /// - /// The orbit semi major axis in kilometers. - /// The launch builder. - public TBuilder WithSemiMajorAxisKilometers(double semiMajorAxis) - { - AddFilter("semi_major_axis_km", semiMajorAxis); - return (TBuilder)this; - } - - /// - /// Filters launches by orbit eccentricity. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved orbit type filter. - /// - /// The orbit eccentricity. - /// The launch builder. - public TBuilder WithEccentricity(double eccentricity) - { - AddFilter("eccentricity", eccentricity); - return (TBuilder)this; - } - - /// - /// Filters launches by orbit periapsis. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved orbit type filter. - /// - /// The orbit periapsis in kilometers. - /// The launch builder. - public TBuilder WithPeriapsisKilometers(double periapsis) - { - AddFilter("periapsis_km", periapsis); - return (TBuilder)this; - } - - /// - /// Filters launches by orbit apoapsis. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved orbit type filter. - /// - /// The orbit apoapsis in kilometers. - /// The launch builder. - public TBuilder WithApoapsisKilometers(double apoapsis) - { - AddFilter("apoapsis_km", apoapsis); - return (TBuilder)this; - } - - /// - /// Filters launches by orbit inclination. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved orbit type filter. - /// - /// The orbit inclination. - /// The launch builder. - public TBuilder WithInclinationDegrees(double inclination) - { - AddFilter("inclination_deg", inclination); - return (TBuilder)this; - } - - /// - /// Filters launches by orbit period time. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved orbit type filter. - /// - /// The orbit period time in minutes. - /// The launch builder. - public TBuilder WithPeriodMinutes(double period) - { - AddFilter("period_min", period); - return (TBuilder)this; - } - - /// - /// Filters launches by orbit lifespan. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved orbit type filter. - /// - /// The orbit lifespan in years. - /// The launch builder. - public TBuilder WithLifespanYears(double lifespan) - { - AddFilter("lifespan_years", lifespan); - return (TBuilder)this; - } - - /// - /// Filters launches by orbit epoch. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved orbit type filter. - /// - /// The orbit epoch. - /// The launch builder. - public TBuilder WithEpoch(DateTime epoch) - { - AddFilter("epoch", epoch); - return (TBuilder)this; - } - - /// - /// Filters launches by orbit mean motion. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved orbit type filter. - /// - /// The orbit mean motion. - /// The launch builder. - public TBuilder WithMeanMotion(double meanMotion) - { - AddFilter("mean_motion", meanMotion); - return (TBuilder)this; - } - - /// - /// Filters launches by orbit RAAN. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved orbit type filter. - /// - /// The orbit RAAN (right ascension of the ascending node). - /// The launch builder. - public TBuilder WithRaan(double raan) - { - AddFilter("raan", raan); - return (TBuilder)this; - } - - /// - /// Filters launches by launch success. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved launch success filter. - /// - /// The launch success. - /// The launch builder. - public TBuilder WithLaunchSuccess(bool launchSuccess) - { - AddFilter("launch_success", launchSuccess); - return (TBuilder)this; - } - } -} \ No newline at end of file diff --git a/Oddity/API/Builders/Launches/NextLaunchBuilder.cs b/Oddity/API/Builders/Launches/NextLaunchBuilder.cs deleted file mode 100644 index 14d2e35..0000000 --- a/Oddity/API/Builders/Launches/NextLaunchBuilder.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Oddity.API.Models.Launch; - -namespace Oddity.API.Builders.Launches -{ - /// - /// Represents a set of methods to filter latest launch information and download them from API. - /// - public class NextLaunchesBuilder : BuilderBase - { - private const string LaunchesEndpoint = "launches/next"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public NextLaunchesBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - protected override async Task ExecuteBuilder() - { - var link = BuildLink(LaunchesEndpoint); - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} diff --git a/Oddity/API/Builders/Launches/PastLaunchesBuilder.cs b/Oddity/API/Builders/Launches/PastLaunchesBuilder.cs deleted file mode 100644 index fff125e..0000000 --- a/Oddity/API/Builders/Launches/PastLaunchesBuilder.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Collections.Generic; -using System.Net.Http; -using System.Threading.Tasks; -using Oddity.API.Models.Launch; - -namespace Oddity.API.Builders.Launches -{ - /// - /// Represents a set of methods to filter all launches information and download them from API. - /// - public class PastLaunchesBuilder : LaunchBuilderBase> - { - private const string LaunchesEndpoint = "launches"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public PastLaunchesBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - protected override async Task> ExecuteBuilder() - { - var link = BuildLink(LaunchesEndpoint); - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} diff --git a/Oddity/API/Builders/Launches/UpcomingLaunchesBuilder.cs b/Oddity/API/Builders/Launches/UpcomingLaunchesBuilder.cs deleted file mode 100644 index 9cf837f..0000000 --- a/Oddity/API/Builders/Launches/UpcomingLaunchesBuilder.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Collections.Generic; -using System.Net.Http; -using System.Threading.Tasks; -using Oddity.API.Models.Launch; - -namespace Oddity.API.Builders.Launches -{ - /// - /// Represents a set of methods to filter all launches information and download them from API. - /// - public class UpcomingLaunchesBuilder : LaunchBuilderBase> - { - private const string LaunchesEndpoint = "launches/upcoming"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public UpcomingLaunchesBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - protected override async Task> ExecuteBuilder() - { - var link = BuildLink(LaunchesEndpoint); - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} diff --git a/Oddity/API/Builders/Launchpads/AllLaunchpadsBuilder.cs b/Oddity/API/Builders/Launchpads/AllLaunchpadsBuilder.cs deleted file mode 100644 index 3701072..0000000 --- a/Oddity/API/Builders/Launchpads/AllLaunchpadsBuilder.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Collections.Generic; -using System.Net.Http; -using System.Threading.Tasks; -using Oddity.API.Models.Launchpad; - -namespace Oddity.API.Builders.Launchpads -{ - /// - /// Represents a set of methods to filter all launchpads information and download them from API. - /// - public class AllLaunchpadsBuilder : BuilderBase> - { - private const string LaunchpadInfoEndpoint = "launchpads"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public AllLaunchpadsBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - protected override async Task> ExecuteBuilder() - { - var link = BuildLink(LaunchpadInfoEndpoint); - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} diff --git a/Oddity/API/Builders/Launchpads/LaunchpadBuilder.cs b/Oddity/API/Builders/Launchpads/LaunchpadBuilder.cs deleted file mode 100644 index cbeb94c..0000000 --- a/Oddity/API/Builders/Launchpads/LaunchpadBuilder.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Oddity.API.Models.Launchpad; -using Oddity.Helpers; - -namespace Oddity.API.Builders.Launchpads -{ - /// - /// Represents a set of methods to filter launchpad information and download them from API. - /// - public class LaunchpadBuilder : BuilderBase - { - private LaunchpadId? _launchpadType; - private const string RocketInfoEndpoint = "launchpads"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public LaunchpadBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - /// Filters launchpad information by the specified launchpad type. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved launchpad type filter. - /// - /// The launchpad type (CcafsLc13, Stls, etc). - /// The launchpad builder. - public LaunchpadBuilder WithType(LaunchpadId type) - { - _launchpadType = type; - return this; - } - - /// - protected override async Task ExecuteBuilder() - { - var link = BuildLink(RocketInfoEndpoint); - if (_launchpadType.HasValue) - { - var launchpadName = _launchpadType.GetEnumMemberAttributeValue(_launchpadType); - link += $"/{launchpadName.ToLower()}"; - } - - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} diff --git a/Oddity/API/Builders/Roadster/RoadsterBuilder.cs b/Oddity/API/Builders/Roadster/RoadsterBuilder.cs deleted file mode 100644 index c2e24ec..0000000 --- a/Oddity/API/Builders/Roadster/RoadsterBuilder.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Oddity.API.Models.Roadster; - -namespace Oddity.API.Builders.Roadster -{ - /// - /// Represents a set of methods to retrieve information about the Tesla Roadster launched into the space. - /// - public class RoadsterBuilder : BuilderBase - { - private const string RoadsterInfoEndpoint = "roadster"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public RoadsterBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - protected override async Task ExecuteBuilder() - { - var link = BuildLink(RoadsterInfoEndpoint); - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} diff --git a/Oddity/API/Builders/Rockets/AllRocketsBuilder.cs b/Oddity/API/Builders/Rockets/AllRocketsBuilder.cs deleted file mode 100644 index a8da45f..0000000 --- a/Oddity/API/Builders/Rockets/AllRocketsBuilder.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Collections.Generic; -using System.Net.Http; -using System.Threading.Tasks; -using Oddity.API.Models.Rocket; - -namespace Oddity.API.Builders.Rockets -{ - /// - /// Represents a set of methods to filter all rockets information and download them from API. - /// - public class AllRocketsBuilder : BuilderBase> - { - private const string RocketInfoEndpoint = "rockets"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public AllRocketsBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - protected override async Task> ExecuteBuilder() - { - var link = BuildLink(RocketInfoEndpoint); - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} diff --git a/Oddity/API/Builders/Rockets/RocketBuilder.cs b/Oddity/API/Builders/Rockets/RocketBuilder.cs deleted file mode 100644 index f2cecb5..0000000 --- a/Oddity/API/Builders/Rockets/RocketBuilder.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Oddity.API.Models.Rocket; - -namespace Oddity.API.Builders.Rockets -{ - /// - /// Represents a set of methods to filter rocket information and download them from API. - /// - public class RocketBuilder : BuilderBase - { - private RocketId? _rocketType; - private const string RocketInfoEndpoint = "rockets"; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public RocketBuilder(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) : base(httpClient, builderDelegatesContainer) - { - - } - - /// - /// Filters rocket information by the specified rocket type. Note that you have to call or - /// to get result from the API. Every next call of this method will override previously saved rocket type filter. - /// - /// The rocket type (Falcon1, Falcon9, etc). - /// The rocket builder. - public RocketBuilder WithType(RocketId type) - { - _rocketType = type; - return this; - } - - /// - protected override async Task ExecuteBuilder() - { - var link = BuildLink(RocketInfoEndpoint); - if (_rocketType.HasValue) - { - link += $"/{_rocketType.ToString().ToLower()}"; - } - - return await SendRequestToApi(link).ConfigureAwait(false); - } - } -} diff --git a/Oddity/API/Capsules.cs b/Oddity/API/Capsules.cs deleted file mode 100644 index 5ec0cb8..0000000 --- a/Oddity/API/Capsules.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System.Net.Http; -using Oddity.API.Builders; -using Oddity.API.Builders.Capsules; - -namespace Oddity.API -{ - /// - /// Represents a set of methods to get capsules information. - /// - public class Capsules - { - private readonly HttpClient _httpClient; - private readonly BuilderDelegatesContainer _builderDelegatesContainer; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public Capsules(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) - { - _httpClient = httpClient; - _builderDelegatesContainer = builderDelegatesContainer; - } - - /// - /// Gets information about the specified capsule. This method returns only builder which doesn't retrieve data from API itself, so after apply - /// all necessary filters you should call or to - /// get the data from SpaceX API. - /// - /// The capsule serial. - /// The capsule builder. - public CapsuleBuilder GetAbout(string capsuleSerial) - { - return new CapsuleBuilder(_httpClient, _builderDelegatesContainer).WithSerial(capsuleSerial); - } - - /// - /// Gets detailed information about all capsules. This method returns only builder which doesn't retrieve data from API itself, so after apply - /// all necessary filters you should call or to - /// get the data from SpaceX API. - /// - /// The all capsules builder. - public AllCapsulesBuilder GetAll() - { - return new AllCapsulesBuilder(_httpClient, _builderDelegatesContainer); - } - - /// - /// Gets detailed information about upcoming capsules. This method returns only builder which doesn't retrieve data from API itself, so after apply - /// all necessary filters you should call or to - /// get the data from SpaceX API. - /// - /// The all capsules builder. - public UpcomingCapsulesBuilder GetUpcoming() - { - return new UpcomingCapsulesBuilder(_httpClient, _builderDelegatesContainer); - } - - /// - /// Gets detailed information about past capsules. This method returns only builder which doesn't retrieve data from API itself, so after apply - /// all necessary filters you should call or to - /// get the data from SpaceX API. - /// - /// The all capsules builder. - public PastCapsulesBuilder GetPast() - { - return new PastCapsulesBuilder(_httpClient, _builderDelegatesContainer); - } - } -} diff --git a/Oddity/API/Company.cs b/Oddity/API/Company.cs deleted file mode 100644 index e329ef5..0000000 --- a/Oddity/API/Company.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Net.Http; -using Oddity.API.Builders; -using Oddity.API.Builders.Company; -using Oddity.API.Builders.History; - -namespace Oddity.API -{ - /// - /// Represents a set of methods to get company information. - /// - public class Company - { - private readonly HttpClient _httpClient; - private readonly BuilderDelegatesContainer _builderDelegatesContainer; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public Company(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) - { - _httpClient = httpClient; - _builderDelegatesContainer = builderDelegatesContainer; - } - - /// - /// Gets information about the company. This method returns only builder which doesn't retrieve data from API itself, - /// you should call or to get the data from SpaceX API. - /// - /// The company information builder. - public InfoBuilder GetInfo() - { - return new InfoBuilder(_httpClient, _builderDelegatesContainer); - } - } -} diff --git a/Oddity/API/Cores.cs b/Oddity/API/Cores.cs deleted file mode 100644 index eb53d0d..0000000 --- a/Oddity/API/Cores.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System.Net.Http; -using Oddity.API.Builders; -using Oddity.API.Builders.Cores; - -namespace Oddity.API -{ - /// - /// Represents a set of methods to get cores information. - /// - public class Cores - { - private readonly HttpClient _httpClient; - private readonly BuilderDelegatesContainer _builderDelegatesContainer; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public Cores(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) - { - _httpClient = httpClient; - _builderDelegatesContainer = builderDelegatesContainer; - } - - /// - /// Gets information about the specified capsule. This method returns only builder which doesn't retrieve data from API itself, so after apply - /// all necessary filters you should call or to - /// get the data from SpaceX API. - /// - /// The core serial. - /// The capsule builder. - public CoreBuilder GetAbout(string coreSerial) - { - return new CoreBuilder(_httpClient, _builderDelegatesContainer).WithSerial(coreSerial); - } - - /// - /// Gets detailed information about all cores. This method returns only builder which doesn't retrieve data from API itself, so after apply - /// all necessary filters you should call or to - /// get the data from SpaceX API. - /// - /// The all core builder. - public AllCoresBuilder GetAll() - { - return new AllCoresBuilder(_httpClient, _builderDelegatesContainer); - } - - /// - /// Gets detailed information about upcoming cores. This method returns only builder which doesn't retrieve data from API itself, so after apply - /// all necessary filters you should call or to - /// get the data from SpaceX API. - /// - /// The all capsules builder. - public UpcomingCoresBuilder GetUpcoming() - { - return new UpcomingCoresBuilder(_httpClient, _builderDelegatesContainer); - } - - /// - /// Gets detailed information about past cores. This method returns only builder which doesn't retrieve data from API itself, so after apply - /// all necessary filters you should call or to - /// get the data from SpaceX API. - /// - /// The all capsules builder. - public PastCoresBuilder GetPast() - { - return new PastCoresBuilder(_httpClient, _builderDelegatesContainer); - } - } -} diff --git a/Oddity/API/Dragons.cs b/Oddity/API/Dragons.cs deleted file mode 100644 index ca278de..0000000 --- a/Oddity/API/Dragons.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Net.Http; -using Oddity.API.Builders; -using Oddity.API.Builders.Dragons; -using Oddity.API.Models.Dragon; - -namespace Oddity.API -{ - /// - /// Represents a set of methods to get Dragon information. - /// - public class Dragons - { - private readonly HttpClient _httpClient; - private readonly BuilderDelegatesContainer _builderDelegatesContainer; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public Dragons(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) - { - _httpClient = httpClient; - _builderDelegatesContainer = builderDelegatesContainer; - } - - /// - /// Gets information about the specified Dragon type. This method returns only builder which doesn't retrieve data from API itself, so after apply - /// all necessary filters you should call or to - /// get the data from SpaceX API. - /// - /// The Dragon type. - /// The capsule builder. - public DragonBuilder GetAbout(DragonId dragonType) - { - return new DragonBuilder(_httpClient, _builderDelegatesContainer).WithType(dragonType); - } - - /// - /// Gets information about all Dragon types. This method returns only builder which doesn't retrieve data from API itself, so after apply - /// all necessary filters you should call or to - /// get the data from SpaceX API. - /// - /// The all capsules builder. - public AllDragonsBuilder GetAll() - { - return new AllDragonsBuilder(_httpClient, _builderDelegatesContainer); - } - } -} diff --git a/Oddity/API/History.cs b/Oddity/API/History.cs deleted file mode 100644 index 16fe3f1..0000000 --- a/Oddity/API/History.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.Net.Http; -using Oddity.API.Builders; -using Oddity.API.Builders.History; - -namespace Oddity.API -{ - /// - /// Represents a set of methods to get company history. - /// - public class History - { - private readonly HttpClient _httpClient; - private readonly BuilderDelegatesContainer _builderDelegatesContainer; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public History(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) - { - _httpClient = httpClient; - _builderDelegatesContainer = builderDelegatesContainer; - } - - /// - /// Gets company history event. This method returns only builder which doesn't retrieve data from API itself, - /// you should call or to get the data from SpaceX API. - /// - /// The company history events builder. - public EventBuilder GetEvent(int eventId) - { - return new EventBuilder(_httpClient, _builderDelegatesContainer).WithId(eventId); - } - - /// - /// Gets company history events. This method returns only builder which doesn't retrieve data from API itself, - /// you should call or to get the data from SpaceX API. - /// - /// The company history events builder. - public HistoryBuilder GetAll() - { - return new HistoryBuilder(_httpClient, _builderDelegatesContainer); - } - } -} diff --git a/Oddity/API/Launches.cs b/Oddity/API/Launches.cs deleted file mode 100644 index 54aab8b..0000000 --- a/Oddity/API/Launches.cs +++ /dev/null @@ -1,93 +0,0 @@ -using System.Net.Http; -using Oddity.API.Builders; -using Oddity.API.Builders.Launches; - -namespace Oddity.API -{ - /// - /// Represents a set of methods to get launches information. - /// - public class Launches - { - private readonly HttpClient _httpClient; - private readonly BuilderDelegatesContainer _builderDelegatesContainer; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public Launches(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) - { - _httpClient = httpClient; - _builderDelegatesContainer = builderDelegatesContainer; - } - - /// - /// Gets information about the specified launch. This method returns only builder which doesn't retrieve data from API itself, so after apply - /// all necessary filters you should call or to - /// get the data from SpaceX API. - /// - /// The launch builder. - public LaunchBuilder Get(int launchId) - { - return new LaunchBuilder(_httpClient, _builderDelegatesContainer).WithId(launchId); - } - - /// - /// Gets information about all launches (past and upcoming). This method returns only builder which doesn't retrieve data from API itself, so after apply - /// all necessary filters you should call or to - /// get the data from SpaceX API. - /// - /// The all launches builder. - public AllLaunchesBuilder GetAll() - { - return new AllLaunchesBuilder(_httpClient, _builderDelegatesContainer); - } - - /// - /// Gets information about latest launch. This method returns only builder which doesn't retrieve data from API itself, so after apply - /// all necessary filters you should call or to - /// get the data from SpaceX API. - /// - /// The latest launch builder. - public LatestLaunchesBuilder GetLatest() - { - return new LatestLaunchesBuilder(_httpClient, _builderDelegatesContainer); - } - - /// - /// Gets information about next launch. This method returns only builder which doesn't retrieve data from API itself, so after apply - /// all necessary filters you should call or to - /// get the data from SpaceX API. - /// - /// The next launch builder. - public NextLaunchesBuilder GetNext() - { - return new NextLaunchesBuilder(_httpClient, _builderDelegatesContainer); - } - - /// - /// Gets information about all upcoming launches. This method returns only builder which doesn't retrieve data from API itself, so after apply - /// all necessary filters you should call or to - /// get the data from SpaceX API. - /// - /// The all upcoming launches builder. - public UpcomingLaunchesBuilder GetUpcoming() - { - return new UpcomingLaunchesBuilder(_httpClient, _builderDelegatesContainer); - } - - - /// - /// Gets information about past launches. This method returns only builder which doesn't retrieve data from API itself, so after apply - /// all necessary filters you should call or to - /// get the data from SpaceX API. - /// - /// The past launches builder. - public PastLaunchesBuilder GetPast() - { - return new PastLaunchesBuilder(_httpClient, _builderDelegatesContainer); - } - } -} diff --git a/Oddity/API/Launchpads.cs b/Oddity/API/Launchpads.cs deleted file mode 100644 index 3fce58a..0000000 --- a/Oddity/API/Launchpads.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Net.Http; -using Oddity.API.Builders; -using Oddity.API.Builders.Launchpads; -using Oddity.API.Models.Launchpad; - -namespace Oddity.API -{ - /// - /// Represents a set of methods to get launchpad information. - /// - public class Launchpads - { - private readonly HttpClient _httpClient; - private readonly BuilderDelegatesContainer _builderDelegatesContainer; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public Launchpads(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) - { - _httpClient = httpClient; - _builderDelegatesContainer = builderDelegatesContainer; - } - - /// - /// Gets information about the specified launchpad. This method returns only builder which doesn't retrieve data from API itself, so after apply - /// all necessary filters you should call or to - /// get the data from SpaceX API. - /// - /// The launchpad type. - /// The launchpad builder. - public LaunchpadBuilder GetAbout(LaunchpadId launchpadType) - { - return new LaunchpadBuilder(_httpClient, _builderDelegatesContainer).WithType(launchpadType); - } - - /// - /// Gets information about all launchpads. This method returns only builder which doesn't retrieve data from API itself, so after apply - /// all necessary filters you should call or to - /// get the data from SpaceX API. - /// - /// The all launchpads builder. - public AllLaunchpadsBuilder GetAll() - { - return new AllLaunchpadsBuilder(_httpClient, _builderDelegatesContainer); - } - } -} diff --git a/Oddity/API/Models/Api/ApiInfo.cs b/Oddity/API/Models/Api/ApiInfo.cs deleted file mode 100644 index cdbdb74..0000000 --- a/Oddity/API/Models/Api/ApiInfo.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Newtonsoft.Json; - -namespace Oddity.API.Models.Api -{ - public class ApiInfo - { - [JsonProperty("project_name")] - public string ProjectName { get; set; } - - public string Version { get; set; } - - [JsonProperty("project_link")] - public string ProjectLink { get; set; } - - public string Docs { get; set; } - public string Organization { get; set; } - - [JsonProperty("organization_link")] - public string OrganizationLink { get; set; } - - public string Description { get; set; } - } -} diff --git a/Oddity/API/Models/Capsule/CapsuleInfo.cs b/Oddity/API/Models/Capsule/CapsuleInfo.cs deleted file mode 100644 index 65549f0..0000000 --- a/Oddity/API/Models/Capsule/CapsuleInfo.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; -using Oddity.API.Models.Dragon; - -namespace Oddity.API.Models.Capsule -{ - public class CapsuleInfo - { - [JsonProperty("capsule_serial")] - public string CapsuleSerial { get; set; } - - [JsonProperty("capsule_id")] - public DragonId? CapsuleId { get; set; } - - public CapsuleStatus? Status { get; set; } - - [JsonProperty("original_launch")] - public DateTime? OriginalLaunch { get; set; } - - [JsonProperty("original_launch_unix")] - public ulong? OriginalLaunchUnix { get; set; } - - public List Missions { get; set; } - public uint? Landings { get; set; } - public string Type { get; set; } - public string Details { get; set; } - - [JsonProperty("reuse_count")] - public int? ReuseCount { get; set; } - } -} diff --git a/Oddity/API/Models/Capsule/CapsuleMissionInfo.cs b/Oddity/API/Models/Capsule/CapsuleMissionInfo.cs deleted file mode 100644 index 32c8e43..0000000 --- a/Oddity/API/Models/Capsule/CapsuleMissionInfo.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Oddity.API.Models.Capsule -{ - public class CapsuleMissionInfo - { - public string Name { get; set; } - public int? Flight { get; set; } - } -} diff --git a/Oddity/API/Models/Capsule/CapsuleStatus.cs b/Oddity/API/Models/Capsule/CapsuleStatus.cs deleted file mode 100644 index 172fd8c..0000000 --- a/Oddity/API/Models/Capsule/CapsuleStatus.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Runtime.Serialization; - -namespace Oddity.API.Models.Capsule -{ - public enum CapsuleStatus - { - [EnumMember(Value = "active")] - Active, - - [EnumMember(Value = "destroyed")] - Destroyed, - - [EnumMember(Value = "retired")] - Retired, - - [EnumMember(Value = "unknown")] - Unknown - } -} diff --git a/Oddity/API/Models/Common/SizeInfo.cs b/Oddity/API/Models/Common/SizeInfo.cs deleted file mode 100644 index b69fdaa..0000000 --- a/Oddity/API/Models/Common/SizeInfo.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Oddity.API.Models.Common -{ - public class SizeInfo - { - public double? Meters { get; set; } - public double? Feet { get; set; } - } -} diff --git a/Oddity/API/Models/Common/ThrustInfo.cs b/Oddity/API/Models/Common/ThrustInfo.cs deleted file mode 100644 index a129a8f..0000000 --- a/Oddity/API/Models/Common/ThrustInfo.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Newtonsoft.Json; - -namespace Oddity.API.Models.Common -{ - public class ThrustInfo - { - [JsonProperty("kn")] - public double? Kilonewtons { get; set; } - - [JsonProperty("lbf")] - public double? PoundsForce { get; set; } - } -} diff --git a/Oddity/API/Models/Core/CoreInfo.cs b/Oddity/API/Models/Core/CoreInfo.cs deleted file mode 100644 index 5efd2ac..0000000 --- a/Oddity/API/Models/Core/CoreInfo.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; - -namespace Oddity.API.Models.DetailedCore -{ - public class CoreInfo - { - [JsonProperty("core_serial")] - public string CoreSerial { get; set; } - - public uint? Block { get; set; } - public CoreStatus? Status { get; set; } - - [JsonProperty("original_launch")] - public DateTime? OriginalLaunch { get; set; } - - [JsonProperty("original_launch_unix")] - public ulong? OriginalLaunchUnix { get; set; } - - public List Missions { get; set; } - - [JsonProperty("reuse_count")] - public uint? ReuseCount { get; set; } - - [JsonProperty("rtls_attempts")] - public uint? RtlsAttempts { get; set; } - - [JsonProperty("rtls_landings")] - public uint? RtlsLandings { get; set; } - - [JsonProperty("asds_attempts")] - public uint? AsdsAttempts { get; set; } - - [JsonProperty("asds_landings")] - public uint? AsdsLandings { get; set; } - - [JsonProperty("water_landing")] - public bool? WaterLanding { get; set; } - - public string Details { get; set; } - } -} diff --git a/Oddity/API/Models/Core/CoreMissionInfo.cs b/Oddity/API/Models/Core/CoreMissionInfo.cs deleted file mode 100644 index a914f87..0000000 --- a/Oddity/API/Models/Core/CoreMissionInfo.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Oddity.API.Models.DetailedCore -{ - public class CoreMissionInfo - { - public string Name { get; set; } - public int? Flight { get; set; } - } -} diff --git a/Oddity/API/Models/Core/CoreStatus.cs b/Oddity/API/Models/Core/CoreStatus.cs deleted file mode 100644 index 9f1b16d..0000000 --- a/Oddity/API/Models/Core/CoreStatus.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Runtime.Serialization; - -namespace Oddity.API.Models.DetailedCore -{ - public enum CoreStatus - { - [EnumMember(Value = "active")] - Active, - - [EnumMember(Value = "lost")] - Lost, - - [EnumMember(Value = "inactive")] - Inactive, - - [EnumMember(Value = "unknown")] - Unknown - } -} diff --git a/Oddity/API/Models/Dragon/DragonId.cs b/Oddity/API/Models/Dragon/DragonId.cs deleted file mode 100644 index 74cbd1b..0000000 --- a/Oddity/API/Models/Dragon/DragonId.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Runtime.Serialization; - -namespace Oddity.API.Models.Dragon -{ - public enum DragonId - { - [EnumMember(Value = "dragon1")] - Dragon1, - - [EnumMember(Value = "dragon2")] - Dragon2 - } -} diff --git a/Oddity/API/Models/Dragon/Payload/TrunkInfo.cs b/Oddity/API/Models/Dragon/Payload/TrunkInfo.cs deleted file mode 100644 index 951a5a4..0000000 --- a/Oddity/API/Models/Dragon/Payload/TrunkInfo.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Newtonsoft.Json; -using Oddity.API.Models.Common; - -namespace Oddity.API.Models.Dragon.Payload -{ - public class TrunkInfo - { - [JsonProperty("trunk_volume")] - public VolumeInfo TrunkVolume { get; set; } - - public CargoInfo Cargo { get; set; } - } -} diff --git a/Oddity/API/Models/Dragon/Thrusters/ThrusterType.cs b/Oddity/API/Models/Dragon/Thrusters/ThrusterType.cs deleted file mode 100644 index 7c3c376..0000000 --- a/Oddity/API/Models/Dragon/Thrusters/ThrusterType.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Oddity.API.Models.Dragon.Thrusters -{ - public enum ThrusterType - { - Draco, - SuperDraco - } -} diff --git a/Oddity/API/Models/Dragon/Thrusters/ThrustersInfo.cs b/Oddity/API/Models/Dragon/Thrusters/ThrustersInfo.cs deleted file mode 100644 index 2ee93d2..0000000 --- a/Oddity/API/Models/Dragon/Thrusters/ThrustersInfo.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Newtonsoft.Json; -using Oddity.API.Models.Common; - -namespace Oddity.API.Models.Dragon.Thrusters -{ - public class ThrustersInfo - { - public ThrusterType? Type { get; set; } - public uint? Amount { get; set; } - public uint? Pods { get; set; } - - [JsonProperty("fuel_1")] - public string FirstPropellant { get; set; } - - [JsonProperty("fuel_2")] - public string SecondPropellant { get; set; } - - public ThrustInfo Thrust { get; set; } - } -} diff --git a/Oddity/API/Models/History/EventLinks.cs b/Oddity/API/Models/History/EventLinks.cs deleted file mode 100644 index 59f4db1..0000000 --- a/Oddity/API/Models/History/EventLinks.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Oddity.API.Models.History -{ - public class EventLinks - { - public string Reddit { get; set; } - public string Article { get; set; } - public string Wikipedia { get; set; } - } -} diff --git a/Oddity/API/Models/History/HistoryEvent.cs b/Oddity/API/Models/History/HistoryEvent.cs deleted file mode 100644 index a89c217..0000000 --- a/Oddity/API/Models/History/HistoryEvent.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using Newtonsoft.Json; - -namespace Oddity.API.Models.History -{ - public class HistoryEvent - { - public int? Id { get; set; } - public string Title { get; set; } - - [JsonProperty("event_date_utc")] - public DateTime? EventDate { get; set; } - - [JsonProperty("event_date_unix")] - public ulong? EventDataUnix { get; set; } - - [JsonProperty("flight_number")] - public uint? FlightNumber { get; set; } - - public string Details { get; set; } - public EventLinks Links { get; set; } - } -} diff --git a/Oddity/API/Models/Launch/LaunchInfo.cs b/Oddity/API/Models/Launch/LaunchInfo.cs deleted file mode 100644 index 9ab013c..0000000 --- a/Oddity/API/Models/Launch/LaunchInfo.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; -using Oddity.API.Models.Launch.Rocket; - -namespace Oddity.API.Models.Launch -{ - public class LaunchInfo - { - [JsonProperty("flight_number")] - public uint? FlightNumber { get; set; } - - [JsonProperty("mission_name")] - public string MissionName { get; set; } - - [JsonProperty("mission_id")] - public List MissionId { get; set; } - - [JsonProperty("launch_year")] - public uint? LaunchYear { get; set; } - - [JsonProperty("launch_date_unix")] - public ulong? LaunchDateUnix { get; set; } - - [JsonProperty("launch_date_utc")] - public DateTime? LaunchDateUtc { get; set; } - - [JsonProperty("launch_date_local")] - public DateTime? LaunchDateLocal { get; set; } - - [JsonProperty("is_tentative")] - public bool? IsTentative { get; set; } - - [JsonProperty("tentative_max_precision")] - public TentativeMaxPrecision? TentativeMaxPrecision { get; set; } - - [JsonProperty("tbd")] - public bool? ToBeDated { get; set; } - - [JsonProperty("launch_window")] - public int? LaunchWindow { get; set; } - - public RocketInfo Rocket { get; set; } - - [JsonProperty("ships")] - public List Ships { get; set; } - - public TelemetryInfo Telemetry { get; set; } - - [JsonProperty("launch_site")] - public LaunchSiteInfo LaunchSite { get; set; } - - [JsonProperty("launch_success")] - public bool? LaunchSuccess { get; set; } - - public LinksInfo Links { get; set; } - public string Details { get; set; } - public bool? Upcoming { get; set; } - - [JsonProperty("static_fire_date_utc")] - public DateTime? StaticFireDateUtc { get; set; } - - [JsonProperty("static_fire_date_unix")] - public ulong? StaticFireDateUnix { get; set; } - - public Dictionary Timeline { get; set; } - } -} diff --git a/Oddity/API/Models/Launch/LaunchSiteInfo.cs b/Oddity/API/Models/Launch/LaunchSiteInfo.cs deleted file mode 100644 index 494f097..0000000 --- a/Oddity/API/Models/Launch/LaunchSiteInfo.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Newtonsoft.Json; -using Oddity.API.Models.Launchpad; - -namespace Oddity.API.Models.Launch -{ - public class LaunchSiteInfo - { - [JsonProperty("site_id")] - public LaunchpadId? SiteId { get; set; } - - [JsonProperty("site_name")] - public string SiteName { get; set; } - - [JsonProperty("site_name_long")] - public string SiteLongName { get; set; } - } -} diff --git a/Oddity/API/Models/Launch/LinksInfo.cs b/Oddity/API/Models/Launch/LinksInfo.cs deleted file mode 100644 index 490abb7..0000000 --- a/Oddity/API/Models/Launch/LinksInfo.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Collections.Generic; -using Newtonsoft.Json; - -namespace Oddity.API.Models.Launch -{ - public class LinksInfo - { - [JsonProperty("mission_patch")] - public string MissionPatch { get; set; } - - [JsonProperty("mission_patch_small")] - public string MissionPatchSmall { get; set; } - - [JsonProperty("reddit_campaign")] - public string RedditCampaign { get; set; } - - [JsonProperty("reddit_launch")] - public string RedditLaunch { get; set; } - - [JsonProperty("reddit_recovery")] - public string RedditRecovery { get; set; } - - [JsonProperty("reddit_media")] - public string RedditMedia { get; set; } - - public string Presskit { get; set; } - - [JsonProperty("article_link")] - public string ArticleLink { get; set; } - - public string Wikipedia { get; set; } - - [JsonProperty("video_link")] - public string VideoLink { get; set; } - - [JsonProperty("youtube_id")] - public string YoutubeId { get; set; } - - [JsonProperty("flickr_images")] - public List FlickrImages { get; set; } - } -} diff --git a/Oddity/API/Models/Launch/Rocket/Fairings/FairingsRecoveryInfo.cs b/Oddity/API/Models/Launch/Rocket/Fairings/FairingsRecoveryInfo.cs deleted file mode 100644 index 0e68534..0000000 --- a/Oddity/API/Models/Launch/Rocket/Fairings/FairingsRecoveryInfo.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Newtonsoft.Json; - -namespace Oddity.API.Models.Launch.Rocket.Fairings -{ - public class FairingsRecoveryInfo - { - public bool? Reused { get; set; } - - [JsonProperty("recovery_attempt")] - public bool? RecoveryAttempt { get; set; } - - public bool? Recovered { get; set; } - public string Ship { get; set; } - } -} diff --git a/Oddity/API/Models/Launch/Rocket/FirstStage/CoreInfo.cs b/Oddity/API/Models/Launch/Rocket/FirstStage/CoreInfo.cs deleted file mode 100644 index 191df8c..0000000 --- a/Oddity/API/Models/Launch/Rocket/FirstStage/CoreInfo.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Newtonsoft.Json; - -namespace Oddity.API.Models.Launch.Rocket.FirstStage -{ - public class CoreInfo - { - [JsonProperty("core_serial")] - public string CoreSerial { get; set; } - - public uint? Flight { get; set; } - public uint? Block { get; set; } - public bool? GridFins { get; set; } - public bool? Legs { get; set; } - public bool? Reused { get; set; } - - [JsonProperty("land_success")] - public bool? LandSuccess { get; set; } - - [JsonProperty("landing_intent")] - public bool? LandingIntent { get; set; } - - [JsonProperty("landing_type")] - public LandingType? LandingType { get; set; } - - [JsonProperty("landing_vehicle")] - public LandingVehicleType? LandingVehicle { get; set; } - } -} diff --git a/Oddity/API/Models/Launch/Rocket/FirstStage/FirstStageInfo.cs b/Oddity/API/Models/Launch/Rocket/FirstStage/FirstStageInfo.cs deleted file mode 100644 index 0cc73d1..0000000 --- a/Oddity/API/Models/Launch/Rocket/FirstStage/FirstStageInfo.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections.Generic; - -namespace Oddity.API.Models.Launch.Rocket.FirstStage -{ - public class FirstStageInfo - { - public List Cores { get; set; } - } -} diff --git a/Oddity/API/Models/Launch/Rocket/FirstStage/LandingType.cs b/Oddity/API/Models/Launch/Rocket/FirstStage/LandingType.cs deleted file mode 100644 index fb4a262..0000000 --- a/Oddity/API/Models/Launch/Rocket/FirstStage/LandingType.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Runtime.Serialization; - -namespace Oddity.API.Models.Launch.Rocket.FirstStage -{ - public enum LandingType - { - [EnumMember(Value = "ASDS")] - ASDS, - - [EnumMember(Value = "RTLC")] - RTLS, - - [EnumMember(Value = "Ocean")] - Ocean - } -} diff --git a/Oddity/API/Models/Launch/Rocket/FirstStage/LandingVehicleType.cs b/Oddity/API/Models/Launch/Rocket/FirstStage/LandingVehicleType.cs deleted file mode 100644 index b432d27..0000000 --- a/Oddity/API/Models/Launch/Rocket/FirstStage/LandingVehicleType.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.Runtime.Serialization; - -namespace Oddity.API.Models.Launch.Rocket.FirstStage -{ - public enum LandingVehicleType - { - [EnumMember(Value = "OCISLY")] - OCISLY, - - [EnumMember(Value = "JRTI")] - JRTI, - - [EnumMember(Value = "JRTI-1")] - JRTI_1, - - [EnumMember(Value = "LZ-1")] - LZ1, - - [EnumMember(Value = "LZ-2")] - LZ2, - - [EnumMember(Value = "LZ-3")] - LZ3, - - [EnumMember(Value = "LZ-4")] - LZ4 - } -} diff --git a/Oddity/API/Models/Launch/Rocket/RocketInfo.cs b/Oddity/API/Models/Launch/Rocket/RocketInfo.cs deleted file mode 100644 index 3055fcf..0000000 --- a/Oddity/API/Models/Launch/Rocket/RocketInfo.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Newtonsoft.Json; -using Oddity.API.Models.Launch.Rocket.Fairings; -using Oddity.API.Models.Launch.Rocket.FirstStage; -using Oddity.API.Models.Launch.Rocket.SecondStage; -using Oddity.API.Models.Rocket; - -namespace Oddity.API.Models.Launch.Rocket -{ - public class RocketInfo - { - [JsonProperty("rocket_id")] - public RocketId? Id { get; set; } - - [JsonProperty("rocket_name")] - public string RocketName { get; set; } - - [JsonProperty("rocket_type")] - public string RocketType { get; set; } - - [JsonProperty("first_stage")] - public FirstStageInfo FirstStage { get; set; } - - [JsonProperty("second_stage")] - public SecondStageInfo SecondStage { get; set; } - - public FairingsRecoveryInfo Fairings { get; set; } - } -} diff --git a/Oddity/API/Models/Launch/Rocket/SecondStage/Orbit/OrbitParameters.cs b/Oddity/API/Models/Launch/Rocket/SecondStage/Orbit/OrbitParameters.cs deleted file mode 100644 index 8fc3ab4..0000000 --- a/Oddity/API/Models/Launch/Rocket/SecondStage/Orbit/OrbitParameters.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using Newtonsoft.Json; - -namespace Oddity.API.Models.Launch.Rocket.SecondStage.Orbit -{ - public class OrbitParameters - { - [JsonProperty("reference_system")] - public ReferenceSystemType? ReferenceSystem { get; set; } - - public OrbitRegime? Regime { get; set; } - public double? Longitude { get; set; } - - [JsonProperty("semi_major_axis_km")] - public double? SemiMajorAxisKilometers { get; set; } - - public double? Eccentricity { get; set; } - - [JsonProperty("periapsis_km")] - public double? PeriapsisKilometers { get; set; } - - [JsonProperty("apoapsis_km")] - public double? ApoapsisKilometers { get; set; } - - [JsonProperty("inclination_deg")] - public double? InclinationDegrees { get; set; } - - [JsonProperty("period_min")] - public double? PeriodMinutes { get; set; } - - [JsonProperty("lifespan_years")] - public double? LifespanYears { get; set; } - - public DateTime? Epoch { get; set; } - - [JsonProperty("mean_motion")] - public double? MeanMotion { get; set; } - - [JsonProperty("raan")] - public double? Raan { get; set; } - - [JsonProperty("arg_of_pericenter")] - public double? ArgOfPericenter { get; set; } - - [JsonProperty("mean_anomaly")] - public double? MeanAnomaly { get; set; } - } -} diff --git a/Oddity/API/Models/Launch/Rocket/SecondStage/Orbit/OrbitRegime.cs b/Oddity/API/Models/Launch/Rocket/SecondStage/Orbit/OrbitRegime.cs deleted file mode 100644 index 70cab32..0000000 --- a/Oddity/API/Models/Launch/Rocket/SecondStage/Orbit/OrbitRegime.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Runtime.Serialization; - -namespace Oddity.API.Models.Launch.Rocket.SecondStage.Orbit -{ - public enum OrbitRegime - { - [EnumMember(Value = "very-low-earth")] - VeryLowEarth, - - [EnumMember(Value = "low-earth")] - LowEarth, - - [EnumMember(Value = "medium-earth")] - MediumEarth, - - [EnumMember(Value = "high-earth")] - HighEarth, - - [EnumMember(Value = "geostationary")] - Geostationary, - - [EnumMember(Value = "geosynchronous")] - Geosynchronous, - - [EnumMember(Value = "L1-point")] - L1Point, - - [EnumMember(Value = "sun-synchronous")] - SunSynchronous, - - [EnumMember(Value = "semi-synchronous")] - SemiSynchronous, - - [EnumMember(Value = "sub-orbital")] - SubOrbital, - - [EnumMember(Value = "highly-elliptical")] - HighlyElliptical, - } -} diff --git a/Oddity/API/Models/Launch/Rocket/SecondStage/Orbit/OrbitType.cs b/Oddity/API/Models/Launch/Rocket/SecondStage/Orbit/OrbitType.cs deleted file mode 100644 index e7ef858..0000000 --- a/Oddity/API/Models/Launch/Rocket/SecondStage/Orbit/OrbitType.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.Runtime.Serialization; - -namespace Oddity.API.Models.Launch.Rocket.SecondStage.Orbit -{ - public enum OrbitType - { - [EnumMember(Value = "VLEO")] - VLEO, - - [EnumMember(Value = "PO")] - PO, - - [EnumMember(Value = "LEO")] - LEO, - - [EnumMember(Value = "GEO")] - GEO, - - [EnumMember(Value = "ISS")] - ISS, - - [EnumMember(Value = "GTO")] - GTO, - - [EnumMember(Value = "SSO")] - SSO, - - [EnumMember(Value = "HCO")] - HCO, - - [EnumMember(Value = "HEO")] - HEO, - - [EnumMember(Value = "MEO")] - MEO, - - [EnumMember(Value = "SO")] - SO, - - [EnumMember(Value = "ES-L1")] - ESL1, - - [EnumMember(Value = "TLI")] - TLI, - } -} diff --git a/Oddity/API/Models/Launch/Rocket/SecondStage/Orbit/ReferenceSystemType.cs b/Oddity/API/Models/Launch/Rocket/SecondStage/Orbit/ReferenceSystemType.cs deleted file mode 100644 index df61250..0000000 --- a/Oddity/API/Models/Launch/Rocket/SecondStage/Orbit/ReferenceSystemType.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Runtime.Serialization; - -namespace Oddity.API.Models.Launch.Rocket.SecondStage.Orbit -{ - public enum ReferenceSystemType - { - [EnumMember(Value = "geocentric")] - Geocentric, - - [EnumMember(Value = "heliocentric")] - Heliocentric, - - [EnumMember(Value = "highly-elliptical")] - HighlyElliptical, - - [EnumMember(Value = "selenocentric")] - Selenocentric - } -} diff --git a/Oddity/API/Models/Launch/Rocket/SecondStage/PayloadInfo.cs b/Oddity/API/Models/Launch/Rocket/SecondStage/PayloadInfo.cs deleted file mode 100644 index c999523..0000000 --- a/Oddity/API/Models/Launch/Rocket/SecondStage/PayloadInfo.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Collections.Generic; -using Newtonsoft.Json; -using Oddity.API.Models.Launch.Rocket.SecondStage.Orbit; - -namespace Oddity.API.Models.Launch.Rocket.SecondStage -{ - public class PayloadInfo - { - [JsonProperty("payload_id")] - public string PayloadId { get; set; } - - [JsonProperty("norad_id")] - public List NoradId { get; set; } - - public bool? Reused { get; set; } - public List Customers { get; set; } - public string Nationality { get; set; } - public string Manufacturer { get; set; } - - [JsonProperty("payload_type")] - public string PayloadType { get; set; } - - [JsonProperty("payload_mass_kg")] - public double? PayloadMassKilograms { get; set; } - - [JsonProperty("payload_mass_lbs")] - public double? PayloadMassPounds { get; set; } - - public OrbitType? Orbit { get; set; } - - [JsonProperty("orbit_params")] - public OrbitParameters OrbitParameters { get; set; } - } -} diff --git a/Oddity/API/Models/Launch/Rocket/SecondStage/SecondStageInfo.cs b/Oddity/API/Models/Launch/Rocket/SecondStage/SecondStageInfo.cs deleted file mode 100644 index 320c390..0000000 --- a/Oddity/API/Models/Launch/Rocket/SecondStage/SecondStageInfo.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Collections.Generic; - -namespace Oddity.API.Models.Launch.Rocket.SecondStage -{ - public class SecondStageInfo - { - public int? Block { get; set; } - public List Payloads { get; set; } - } -} diff --git a/Oddity/API/Models/Launch/TelemetryInfo.cs b/Oddity/API/Models/Launch/TelemetryInfo.cs deleted file mode 100644 index 7b59488..0000000 --- a/Oddity/API/Models/Launch/TelemetryInfo.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Newtonsoft.Json; - -namespace Oddity.API.Models.Launch -{ - public class TelemetryInfo - { - [JsonProperty("flight_club")] - public string FlightClub { get; set; } - } -} diff --git a/Oddity/API/Models/Launch/TentativeMaxPrecision.cs b/Oddity/API/Models/Launch/TentativeMaxPrecision.cs deleted file mode 100644 index 3242db8..0000000 --- a/Oddity/API/Models/Launch/TentativeMaxPrecision.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Runtime.Serialization; - -namespace Oddity.API.Models.Launch -{ - public enum TentativeMaxPrecision - { - [EnumMember(Value = "hour")] - Hour, - - [EnumMember(Value = "day")] - Day, - - [EnumMember(Value = "month")] - Month, - - [EnumMember(Value = "quarter")] - Quarter, - - [EnumMember(Value = "half")] - Half, - - [EnumMember(Value = "year")] - Year - } -} diff --git a/Oddity/API/Models/Launchpad/LaunchpadId.cs b/Oddity/API/Models/Launchpad/LaunchpadId.cs deleted file mode 100644 index 48a2236..0000000 --- a/Oddity/API/Models/Launchpad/LaunchpadId.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Runtime.Serialization; - -namespace Oddity.API.Models.Launchpad -{ - public enum LaunchpadId - { - [EnumMember(Value = "kwajalein_atoll")] - KwajaleinAtoll, - - [EnumMember(Value = "ccafs_slc_40")] - CcafsSlc40, - - [EnumMember(Value = "ccafs_lc_13")] - CcafsLc13, - - [EnumMember(Value = "ksc_lc_39a")] - KscLc39a, - - [EnumMember(Value = "vafb_slc_3w")] - VafbSlc3w, - - [EnumMember(Value = "vafb_slc_4e")] - VafbSlc4e, - - [EnumMember(Value = "vafb_slc_4w")] - VafbSlc4w, - - [EnumMember(Value = "stls")] - Stls - } -} diff --git a/Oddity/API/Models/Launchpad/LaunchpadInfo.cs b/Oddity/API/Models/Launchpad/LaunchpadInfo.cs deleted file mode 100644 index 8aaaf29..0000000 --- a/Oddity/API/Models/Launchpad/LaunchpadInfo.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Collections.Generic; -using Newtonsoft.Json; - -namespace Oddity.API.Models.Launchpad -{ - public class LaunchpadInfo - { - public int? Id { get; set; } - - [JsonProperty("site_id")] - public LaunchpadId? SiteId { get; set; } - - public LaunchpadStatus? Status { get; set; } - public LaunchpadLocation Location { get; set; } - - [JsonProperty("vehicles_launched")] - public List VehiclesLaunched { get; set; } - - [JsonProperty("attempted_launches")] - public int? AttemptedLaunches { get; set; } - - [JsonProperty("successful_launches")] - public int? SuccessfulLaunches { get; set; } - - public string Wikipedia { get; set; } - public string Details { get; set; } - - [JsonProperty("site_name_long")] - public string FullName { get; set; } - - } -} diff --git a/Oddity/API/Models/Launchpad/LaunchpadLocation.cs b/Oddity/API/Models/Launchpad/LaunchpadLocation.cs deleted file mode 100644 index cd7f004..0000000 --- a/Oddity/API/Models/Launchpad/LaunchpadLocation.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Oddity.API.Models.Launchpad -{ - public class LaunchpadLocation - { - public string Name { get; set; } - public string Region { get; set; } - public double? Latitude { get; set; } - public double? Longitude { get; set; } - } -} diff --git a/Oddity/API/Models/Rocket/Engines/EngineType.cs b/Oddity/API/Models/Rocket/Engines/EngineType.cs deleted file mode 100644 index 32780d6..0000000 --- a/Oddity/API/Models/Rocket/Engines/EngineType.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Oddity.API.Models.Rocket.Engines -{ - public enum EngineType - { - Merlin, - Raptor - } -} diff --git a/Oddity/API/Models/Rocket/LandingLegs/LandingLegsInfo.cs b/Oddity/API/Models/Rocket/LandingLegs/LandingLegsInfo.cs deleted file mode 100644 index 083b285..0000000 --- a/Oddity/API/Models/Rocket/LandingLegs/LandingLegsInfo.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Newtonsoft.Json; - -namespace Oddity.API.Models.Rocket.LandingLegs -{ - public class LandingLegsInfo - { - [JsonProperty("Number")] - public uint? Count { get; set; } - - public string Material { get; set; } - } -} diff --git a/Oddity/API/Models/Rocket/PayloadWeights/PayloadType.cs b/Oddity/API/Models/Rocket/PayloadWeights/PayloadType.cs deleted file mode 100644 index f9783ac..0000000 --- a/Oddity/API/Models/Rocket/PayloadWeights/PayloadType.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Oddity.API.Models.Rocket.PayloadWeights -{ - public enum PayloadType - { - LEO, - GTO, - Mars, - Pluto, - Moon - } -} diff --git a/Oddity/API/Models/Rocket/PayloadWeights/PayloadWeightInfo.cs b/Oddity/API/Models/Rocket/PayloadWeights/PayloadWeightInfo.cs deleted file mode 100644 index acb7b5b..0000000 --- a/Oddity/API/Models/Rocket/PayloadWeights/PayloadWeightInfo.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Newtonsoft.Json; - -namespace Oddity.API.Models.Rocket.PayloadWeights -{ - public class PayloadWeightInfo - { - [JsonProperty("id")] - public PayloadType? Type { get; set; } - - public string Name { get; set; } - - [JsonProperty("kg")] - public uint? Kilograms { get; set; } - - [JsonProperty("lb")] - public uint? Pounds { get; set; } - } -} diff --git a/Oddity/API/Models/Rocket/RocketId.cs b/Oddity/API/Models/Rocket/RocketId.cs deleted file mode 100644 index 2404033..0000000 --- a/Oddity/API/Models/Rocket/RocketId.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Runtime.Serialization; - -namespace Oddity.API.Models.Rocket -{ - public enum RocketId - { - [EnumMember(Value = "falcon1")] - Falcon1, - - [EnumMember(Value = "falcon9")] - Falcon9, - - [EnumMember(Value = "falconheavy")] - FalconHeavy, - - [EnumMember(Value = "starship")] - Starship - } -} diff --git a/Oddity/API/Models/Rocket/Stages/Payloads/FairingInfo.cs b/Oddity/API/Models/Rocket/Stages/Payloads/FairingInfo.cs deleted file mode 100644 index 77d07be..0000000 --- a/Oddity/API/Models/Rocket/Stages/Payloads/FairingInfo.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Oddity.API.Models.Common; - -namespace Oddity.API.Models.Rocket.Stages.Payloads -{ - public class FairingInfo - { - public SizeInfo Height { get; set; } - public SizeInfo Diameter { get; set; } - } -} diff --git a/Oddity/API/Models/Rocket/Stages/Payloads/PayloadInfo.cs b/Oddity/API/Models/Rocket/Stages/Payloads/PayloadInfo.cs deleted file mode 100644 index 6f04e42..0000000 --- a/Oddity/API/Models/Rocket/Stages/Payloads/PayloadInfo.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Newtonsoft.Json; - -namespace Oddity.API.Models.Rocket.Stages.Payloads -{ - public class PayloadInfo - { - [JsonProperty("composite_fairing")] - public FairingInfo Fairing { get; set; } - } -} diff --git a/Oddity/API/Roadster.cs b/Oddity/API/Roadster.cs deleted file mode 100644 index 0493cb6..0000000 --- a/Oddity/API/Roadster.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Net.Http; -using Oddity.API.Builders; -using Oddity.API.Builders.Roadster; - -namespace Oddity.API -{ - /// - /// Represents a set of methods to get Roadster information. - /// - public class Roadster - { - private readonly HttpClient _httpClient; - private readonly BuilderDelegatesContainer _builderDelegatesContainer; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public Roadster(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) - { - _httpClient = httpClient; - _builderDelegatesContainer = builderDelegatesContainer; - } - - /// - /// Gets information about Tesla Roadster sent on Falcon Heavy. This method returns only builder which doesn't retrieve data from API itself, so after apply - /// all necessary filters you should call or to - /// get the data from SpaceX API. - /// - /// The Roadster builder. - public RoadsterBuilder Get() - { - return new RoadsterBuilder(_httpClient, _builderDelegatesContainer); - } - } -} diff --git a/Oddity/API/Rockets.cs b/Oddity/API/Rockets.cs deleted file mode 100644 index 746491c..0000000 --- a/Oddity/API/Rockets.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Net.Http; -using Oddity.API.Builders; -using Oddity.API.Builders.Rockets; -using Oddity.API.Models.Rocket; - -namespace Oddity.API -{ - /// - /// Represents a set of methods to get rockets information. - /// - public class Rockets - { - private readonly HttpClient _httpClient; - private readonly BuilderDelegatesContainer _builderDelegatesContainer; - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The builder delegates container. - public Rockets(HttpClient httpClient, BuilderDelegatesContainer builderDelegatesContainer) - { - _httpClient = httpClient; - _builderDelegatesContainer = builderDelegatesContainer; - } - - /// - /// Gets information about the specified rocket. This method returns only builder which doesn't retrieve data from API itself, so after apply - /// all necessary filters you should call or to - /// get the data from SpaceX API. - /// - /// The rocket type. - /// The rocket builder. - public RocketBuilder GetAbout(RocketId rocketType) - { - return new RocketBuilder(_httpClient, _builderDelegatesContainer).WithType(rocketType); - } - - /// - /// Gets information about all rockets. This method returns only builder which doesn't retrieve data from API itself, so after apply - /// all necessary filters you should call or to - /// get the data from SpaceX API. - /// - /// The all rockets builder. - public AllRocketsBuilder GetAll() - { - return new AllRocketsBuilder(_httpClient, _builderDelegatesContainer); - } - } -} diff --git a/Oddity/APIConfiguration.cs b/Oddity/APIConfiguration.cs deleted file mode 100644 index 236b240..0000000 --- a/Oddity/APIConfiguration.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Oddity -{ - public class ApiConfiguration - { - public const string ApiEndpoint = "https://api.spacexdata.com/v3/"; - public const int DefaultTimeoutSeconds = 5; - - public const string LibraryName = "Oddity"; - public const string GitHubLink = "https://github.com/Tearth/Oddity"; - } -} diff --git a/Oddity/Builders/BuilderBase.cs b/Oddity/Builders/BuilderBase.cs new file mode 100644 index 0000000..47be829 --- /dev/null +++ b/Oddity/Builders/BuilderBase.cs @@ -0,0 +1,132 @@ +using System.Net; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using Oddity.Events; +using Oddity.Exceptions; + +namespace Oddity.Builders +{ + /// + /// Represents an abstract base class for all builders. + /// + /// Type which will be returned after successful API request. + public abstract class BuilderBase + { + protected readonly OddityCore Context; + + private readonly JsonSerializerSettings _serializationSettings; + + protected BuilderBase(OddityCore context) + { + Context = context; + + _serializationSettings = new JsonSerializerSettings + { + Error = JsonDeserializationError, +#if DEBUG + CheckAdditionalContent = true, + MissingMemberHandling = MissingMemberHandling.Error +#endif + }; + } + + /// + /// Performs an synchronous request to the API and returns deserialized JSON. + /// + /// The deserialized object retrieved from the API or null for non existing ID. + /// Thrown when SpaceX API is unavailable and can't process any request. + /// Thrown when SpaceX API received an invalid request which cannot be processed. + public abstract TReturn Execute(); + + /// + /// Performs an synchronous request to the API and fills passed model in parameter with deserialized JSON. + /// + /// The model which will be filled with deserialized JSON. + /// The flag indicating if the API request and model fill has been done with success or not. + /// Thrown when SpaceX API is unavailable and can't process any request. + /// Thrown when SpaceX API received an invalid request which cannot be processed. + public abstract bool Execute(TReturn model); + + /// + /// Performs an asynchronous request to the API and returns deserialized JSON. + /// + /// The deserialized object retrieved from the API or null for non existing ID. + /// Thrown when SpaceX API is unavailable and can't process any request. + /// Thrown when SpaceX API received an invalid request which cannot be processed. + public abstract Task ExecuteAsync(); + + /// + /// Performs an asynchronous request to the API and fills passed model in parameter with deserialized JSON. + /// + /// The model which will be filled with deserialized JSON. + /// The flag indicating if the API request and model fill has been done with success or not. + /// Thrown when SpaceX API is unavailable and can't process any request. + /// Thrown when SpaceX API received an invalid request which cannot be processed. + public abstract Task ExecuteAsync(TReturn model); + + protected async Task GetResponseFromEndpoint(string link, string postBody = null) + { + Context.BuilderDelegates.RequestSend(new RequestSendEventArgs(link, postBody)); + + HttpResponseMessage response; + if (postBody == null) + { + response = await Context.HttpClient.GetAsync(link).ConfigureAwait(false); + } + else + { + var httpContent = new StringContent(postBody, Encoding.UTF8, "application/json"); + response = await Context.HttpClient.PostAsync(link, httpContent).ConfigureAwait(false); + } + + var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var eventArgs = new ResponseReceiveEventArgs(content, response.StatusCode, response.ReasonPhrase); + + if (response.StatusCode != HttpStatusCode.OK) + { + switch (response.StatusCode) + { + case HttpStatusCode.NotFound: + { + return null; + } + case HttpStatusCode.BadRequest: + { + throw new ApiBadRequestException(content); + } + default: + { + throw new ApiUnavailableException($"Status code: {(int)response.StatusCode}"); + } + } + } + + Context.BuilderDelegates.ResponseReceived(eventArgs); + + return content; + } + + protected string SerializeJson(object model) + { + return JsonConvert.SerializeObject(model); + } + + protected TReturn DeserializeJson(string content) + { + return JsonConvert.DeserializeObject(content, _serializationSettings); + } + + protected void DeserializeJson(string content, TReturn model) + { + JsonConvert.PopulateObject(content, model, _serializationSettings); + } + + private void JsonDeserializationError(object sender, ErrorEventArgs errorEventArgs) + { + Context.BuilderDelegates.DeserializationError(errorEventArgs); + } + } +} diff --git a/Oddity/Builders/ListBuilder.cs b/Oddity/Builders/ListBuilder.cs new file mode 100644 index 0000000..50d8142 --- /dev/null +++ b/Oddity/Builders/ListBuilder.cs @@ -0,0 +1,80 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Oddity.Cache; +using Oddity.Models; + +namespace Oddity.Builders +{ + /// + /// Represents a list builder used to retrieve data (collection of objects) without any filters. + /// + /// Type which will be returned after successful API request. + public class ListBuilder : BuilderBase> where TReturn : ModelBase, IIdentifiable, new() + { + private readonly CacheService _cache; + private readonly string _endpoint; + + /// + /// Initializes a new instance of the class. + /// + /// The Oddity context used to interact with API. + /// Cache service used to speed up requests. + /// The endpoint used in this instance to retrieve data from API. + public ListBuilder(OddityCore context, CacheService cache, string endpoint) : base(context) + { + _cache = cache; + _endpoint = endpoint; + } + + /// + public override List Execute() + { + return ExecuteAsync().GetAwaiter().GetResult(); + } + + /// + public override bool Execute(List model) + { + return ExecuteAsync(model).GetAwaiter().GetResult(); + } + + /// + public override async Task> ExecuteAsync() + { + var model = new List(); + await ExecuteAsync(model); + + return model; + } + + /// + public override async Task ExecuteAsync(List models) + { + if (Context.CacheEnabled && _cache.GetListIfAvailable(out var list, _endpoint)) + { + models.AddRange(list); + return true; + } + + var content = await GetResponseFromEndpoint($"{_endpoint}"); + if (content == null) + { + return false; + } + + DeserializeJson(content, models); + + foreach (var deserializedObject in models) + { + deserializedObject.SetContext(Context); + } + + if (Context.CacheEnabled) + { + _cache.UpdateList(models, _endpoint); + } + + return true; + } + } +} diff --git a/Oddity/Builders/QueryBuilder.cs b/Oddity/Builders/QueryBuilder.cs new file mode 100644 index 0000000..622b51a --- /dev/null +++ b/Oddity/Builders/QueryBuilder.cs @@ -0,0 +1,240 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Oddity.Cache; +using Oddity.Models; +using Oddity.Models.Query; +using Oddity.Models.Query.Filters; + +namespace Oddity.Builders +{ + /// + /// Represents a query builder used to retrieve data with filters specified by the user. + /// + /// Type which will be returned after successful API request. + public class QueryBuilder : BuilderBase> where TReturn : ModelBase, IIdentifiable, new() + { + private readonly CacheService _cache; + private readonly string _endpoint; + private readonly QueryModel _query; + + /// + /// Initializes a new instance of the class. + /// + /// The Oddity context used to interact with API. + /// Cache service used to speed up requests. + /// The endpoint used in this instance to retrieve data from API. + public QueryBuilder(OddityCore context, CacheService cache, string endpoint) : base(context) + { + _cache = cache; + _endpoint = endpoint; + _query = new QueryModel(); + } + + /// + /// Adds an "equal" filter for the specified field. API will return all models with a field + /// value equal to the specified in the parameter. + /// + /// Type of the property (JSON field). + /// Property (JSON field) selector. + /// Value of the field to match. + /// Builder instance. + public QueryBuilder WithFieldEqual(Expression> selector, TField value) + { + var fieldPath = GetPathFromExpression(selector); + _query.Filters.Add(fieldPath, value); + return this; + } + + /// + /// Adds a "greater than" filter for the specified field. API will return all models with a field + /// value greater than the specified in the parameter. + /// + /// Type of the property (JSON field). + /// Property (JSON field) selector. + /// Value of the field to match. + /// Builder instance. + public QueryBuilder WithFieldGreaterThan(Expression> selector, TField value) + { + var fieldPath = GetPathFromExpression(selector); + _query.Filters.Add(fieldPath, new GreaterThanFilter(value)); + return this; + } + + /// + /// Adds a "less than" filter for the specified field. API will return all models with a field + /// value less than the specified in the parameter. + /// + /// Type of the property (JSON field). + /// Property (JSON field) selector. + /// Value of the field to match. + /// Builder instance. + public QueryBuilder WithFieldLessThan(Expression> selector, TField value) + { + var fieldPath = GetPathFromExpression(selector); + _query.Filters.Add(fieldPath, new LessThanFilter(value)); + return this; + } + + /// + /// Adds a "between" filter for the specified field. API will return all models with a field + /// value greater than the bounds specified in the parameters. + /// + /// Type of the property (JSON field). + /// Property (JSON field) selector. + /// Left bound of the value to match. + /// Right bound of the value to match. + /// Builder instance. + public QueryBuilder WithFieldBetween(Expression> selector, TField from, TField to) + { + var fieldPath = GetPathFromExpression(selector); + _query.Filters.Add(fieldPath, new BetweenFilter(from, to)); + return this; + } + + /// + /// Adds an "in" filter for the specified field. API will return all models with a field + /// value containing one of the specified in the parameter. + /// + /// Type of the property (JSON field). + /// Property (JSON field) selector. + /// List of values to match. + /// Builder instance. + public QueryBuilder WithFieldIn(Expression> selector, params TField[] values) + { + var fieldPath = GetPathFromExpression(selector); + _query.Filters.Add(fieldPath, new InFilter(values)); + return this; + } + + + /// + /// Sorts result using the specified field and order (ascending/descending). + /// + /// Type of the property (JSON field). + /// Property (JSON field) selector. + /// Sort order (ascending/descending). + /// Builder instance. + public QueryBuilder SortBy(Expression> selector, bool ascending = true) + { + var fieldPath = GetPathFromExpression(selector); + if (_query.Options.Sort == null) + { + _query.Options.Sort = new Dictionary(); + } + + var sortMode = ascending ? SortMode.Ascending : SortMode.Descending; + + _query.Options.Sort[fieldPath] = sortMode; + return this; + } + + /// + /// Sets page number which will be returned from API. Don't use this method together with (offset will + /// be set to null in this case). + /// + /// Selected page number (starting from 1). + /// Builder instance. + public QueryBuilder WithPage(uint page) + { + _query.Options.Page = page; + _query.Options.Offset = null; + return this; + } + + /// + /// Sets how many elements should be returned from API in the single page. + /// + /// Number of elements to return. + /// Builder instance. + public QueryBuilder WithLimit(uint limit) + { + _query.Options.Limit = limit; + return this; + } + + /// + /// Sets page number which will be returned from API. Don't use this method together with (page will + /// be set to null in this case). + /// + /// Number of elements to skip. + /// Builder instance. + public QueryBuilder WithOffset(uint offset) + { + _query.Options.Offset = offset; + _query.Options.Page = null; + return this; + } + + /// + public override PaginatedModel Execute() + { + return ExecuteAsync().GetAwaiter().GetResult(); + } + + /// + public override bool Execute(PaginatedModel model) + { + return ExecuteAsync(model).GetAwaiter().GetResult(); + } + + /// + public override async Task> ExecuteAsync() + { + var model = new PaginatedModel(); + await ExecuteAsync(model); + + return model; + } + + /// + public override async Task ExecuteAsync(PaginatedModel paginatedModel) + { + var serializedQuery = SerializeJson(_query); + var content = await GetResponseFromEndpoint($"{_endpoint}", serializedQuery); + if (content == null) + { + return false; + } + + DeserializeJson(content, paginatedModel); + + foreach (var deserializedObject in paginatedModel.Data) + { + deserializedObject.SetContext(Context); + _cache.Update(deserializedObject, deserializedObject.Id); + } + + paginatedModel.SetBuilder(this); + return true; + } + + private string GetPathFromExpression(Expression> selector) + { + var members = new List(); + var memberExpression = (MemberExpression) selector.Body; + + while (memberExpression != null) + { + var customAttributes = memberExpression.Member.CustomAttributes; + var jsonPropertyAttribute = customAttributes.FirstOrDefault(p => p.AttributeType == typeof(JsonPropertyAttribute)); + + if (jsonPropertyAttribute != null && jsonPropertyAttribute.ConstructorArguments.Count > 0) + { + members.Insert(0, (string) jsonPropertyAttribute.ConstructorArguments[0].Value); + } + else + { + members.Insert(0, memberExpression.Member.Name); + } + + memberExpression = memberExpression.Expression as MemberExpression; + } + + return string.Join(".", members); + } + } +} \ No newline at end of file diff --git a/Oddity/Builders/SimpleBuilder.cs b/Oddity/Builders/SimpleBuilder.cs new file mode 100644 index 0000000..c43af96 --- /dev/null +++ b/Oddity/Builders/SimpleBuilder.cs @@ -0,0 +1,89 @@ +using System.Threading.Tasks; +using Oddity.Cache; +using Oddity.Models; + +namespace Oddity.Builders +{ + /// + /// Represents a simple builder used to retrieve data without any filters. + /// + /// Type which will be returned after successful API request. + public class SimpleBuilder : BuilderBase where TReturn : ModelBase, IIdentifiable, new() + { + private readonly CacheService _cache; + private readonly string _endpoint; + private readonly string _id; + + /// + /// Initializes a new instance of the class. + /// + /// The Oddity context used to interact with API. + /// Cache service used to speed up requests. + /// The endpoint used in this instance to retrieve data from API. + public SimpleBuilder(OddityCore context, CacheService cache, string endpoint) : this(context, cache, endpoint, null) + { + + } + + /// + /// Initializes a new instance of the class. + /// + /// The Oddity context used to interact with API. + /// Cache service used to speed up requests. + /// The endpoint used in this instance to retrieve data from API. + /// The ID of the specified object to retrieve from API. + public SimpleBuilder(OddityCore context, CacheService cache, string endpoint, string id) : base(context) + { + _cache = cache; + _endpoint = endpoint; + _id = id; + } + + /// + public override TReturn Execute() + { + return ExecuteAsync().GetAwaiter().GetResult(); + } + + /// + public override bool Execute(TReturn model) + { + return ExecuteAsync(model).GetAwaiter().GetResult(); + } + + /// + public override async Task ExecuteAsync() + { + var model = new TReturn(); + await ExecuteAsync(model); + + return model; + } + + /// + public override async Task ExecuteAsync(TReturn model) + { + if (Context.CacheEnabled && _cache.GetIfAvailable(out var data, _id ?? _endpoint)) + { + data.CopyTo(model); + return true; + } + + var content = await GetResponseFromEndpoint($"{_endpoint}/{_id}"); + if (content == null) + { + return false; + } + + DeserializeJson(content, model); + model.SetContext(Context); + + if (Context.CacheEnabled) + { + _cache.Update(model, _id ?? _endpoint); + } + + return true; + } + } +} diff --git a/Oddity/Cache/CacheItem.cs b/Oddity/Cache/CacheItem.cs new file mode 100644 index 0000000..8ad4934 --- /dev/null +++ b/Oddity/Cache/CacheItem.cs @@ -0,0 +1,32 @@ +using System; + +namespace Oddity.Cache +{ + /// + /// Represents an container for the cached data. + /// + /// Type of the cached data. + public class CacheItem + { + /// + /// Gets or sets the cached data. + /// + public TData Data { get; set; } + + /// + /// Gets or sets the update time of the cached data. + /// + public DateTime UpdateTime { get; set; } + + /// + /// Initializes a new instance of the class. + /// + /// The data which will be cached. + /// The time at the moment when the data has been cached. + public CacheItem(TData data, DateTime updateTime) + { + Data = data; + UpdateTime = updateTime; + } + } +} diff --git a/Oddity/Cache/CacheService.cs b/Oddity/Cache/CacheService.cs new file mode 100644 index 0000000..f4a96f0 --- /dev/null +++ b/Oddity/Cache/CacheService.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using Oddity.Models; + +namespace Oddity.Cache +{ + /// + /// Represents an cache service used to manage cached data. + /// + /// Type of the cached data. + public class CacheService where TData : ModelBase, IIdentifiable + { + /// + /// Gets or sets the number of seconds after which the data should be updated (retrieved from API again). + /// + public int LifetimeSeconds { get; set; } + + private readonly Dictionary> _cachedData; + private readonly Dictionary>> _cachedLists; + + /// + /// Initializes a new instance of the class. + /// + /// The number of seconds after which the data should be updated (retrieved from API again). + public CacheService(int lifetimeSeconds) + { + LifetimeSeconds = lifetimeSeconds; + + _cachedData = new Dictionary>(); + _cachedLists = new Dictionary>>(); + } + + /// + /// Checks if there is a cached model with the specified parameter. If yes, then appropriate flag is returned and + /// out parameter is filled. + /// + /// Out parameter which will be used to return cached model (or null if the parameter is new). + /// The parameter used for the identification of the cached model. + /// True if the cached model has been found and returned in the out parameter, otherwise false. + public bool GetIfAvailable(out TData data, string parameter) + { + if (_cachedData.ContainsKey(parameter)) + { + var item = _cachedData[parameter]; + if ((DateTime.Now - item.UpdateTime).TotalSeconds < LifetimeSeconds) + { + data = item.Data; + return true; + } + } + + data = default; + return false; + } + + /// + /// Checks if there is a cached list of models with the specified parameter. If yes, then appropriate flag is returned and + /// out parameter is filled. + /// + /// Out parameter which will be used to return cached list of models (or null if the parameter is new). + /// The parameter used for the identification of the cached list of models. + /// True if the cached list of models has been found and returned in the out parameter, otherwise false. + public bool GetListIfAvailable(out List data, string parameter) + { + if (_cachedLists.ContainsKey(parameter)) + { + var item = _cachedLists[parameter]; + if ((DateTime.Now - item.UpdateTime).TotalSeconds < LifetimeSeconds) + { + data = item.Data; + return true; + } + } + + data = default; + return false; + } + + /// + /// Updates a model with the specified parameter. + /// + /// The model which will be cached. + /// The parameter used for model identification. + public void Update(TData data, string parameter) + { + _cachedData[parameter] = new CacheItem(data, DateTime.Now); + } + + /// + /// Updates a list of models with the specified parameter. + /// + /// The list of models which will be cached. + /// The parameter used for list of models identification. + public void UpdateList(List data, string parameter) + { + _cachedLists[parameter] = new CacheItem>(data, DateTime.Now); + + foreach (var item in data) + { + Update(item, item.Id); + } + } + + /// + /// Clears all cached data. + /// + /// Number of purged cached elements. + public int Clear() + { + var count = _cachedData.Count + _cachedLists.Count; + + _cachedData.Clear(); + _cachedLists.Clear(); + + return count; + } + } +} diff --git a/Oddity/Configuration/APIConfiguration.cs b/Oddity/Configuration/APIConfiguration.cs new file mode 100644 index 0000000..c8ff5aa --- /dev/null +++ b/Oddity/Configuration/APIConfiguration.cs @@ -0,0 +1,18 @@ +namespace Oddity.Configuration +{ + /// + /// Contains a set of constant parameters with API configuration. + /// + public class ApiConfiguration + { + /// + /// Entry point of the API, used as base for all HTTP requests. + /// + public const string ApiEndpoint = "https://api.spacexdata.com/v4/"; + + /// + /// Default time after which timeout exception will be thrown. + /// + public const int DefaultTimeoutSeconds = 5; + } +} diff --git a/Oddity/Configuration/LibraryConfiguration.cs b/Oddity/Configuration/LibraryConfiguration.cs new file mode 100644 index 0000000..1ecfc1d --- /dev/null +++ b/Oddity/Configuration/LibraryConfiguration.cs @@ -0,0 +1,33 @@ +namespace Oddity.Configuration +{ + /// + /// Contains a set of constant parameters with library configuration. + /// + public class LibraryConfiguration + { + /// + /// Library name used to generate user agent. + /// + public const string LibraryName = "Oddity"; + + /// + /// Library's GitHub used to generate user agent. + /// + public const string GitHubLink = "https://github.com/Tearth/Oddity"; + + /// + /// Lifetime of low-priority cached data (24 hours). + /// + public const int LowPriorityCacheLifetime = 60 * 60 * 24; + + /// + /// Lifetime of medium-priority cached data (5 minutes). + /// + public const int MediumPriorityCacheLifetime = 60 * 5; + + /// + /// Lifetime of high-priority cached data (20 seconds). + /// + public const int HighPriorityCacheLifetime = 20; + } +} diff --git a/Oddity/Endpoints/CapsulesEndpoint.cs b/Oddity/Endpoints/CapsulesEndpoint.cs new file mode 100644 index 0000000..9cd9f1e --- /dev/null +++ b/Oddity/Endpoints/CapsulesEndpoint.cs @@ -0,0 +1,50 @@ +using Oddity.Builders; +using Oddity.Configuration; +using Oddity.Models; + +namespace Oddity.Endpoints +{ + /// + /// Represents an entry point of /capsules endpoint. + /// + /// Type of the data returned from API. + public class CapsulesEndpoint : EndpointBase where TData : ModelBase, IIdentifiable, new() + { + /// + /// Initializes a new instance of the class. + /// + /// The Oddity context used to interact with API. + public CapsulesEndpoint(OddityCore context) : base(context, LibraryConfiguration.MediumPriorityCacheLifetime) + { + + } + + /// + /// Gets data about the specified capsule from the /capsules/:id endpoint. + /// + /// ID of the specified capsule. + /// Deserialized JSON returned from the API. + public SimpleBuilder Get(string id) + { + return new SimpleBuilder(Context, Cache, "capsules", id); + } + + /// + /// Gets data about all capsules from the /capsules endpoint. + /// + /// Deserialized JSON returned from the API. + public ListBuilder GetAll() + { + return new ListBuilder(Context, Cache, "capsules"); + } + + /// + /// Gets filtered and paginated data about all capsules from the /capsules/query endpoint. + /// + /// Deserialized JSON returned from the API. + public QueryBuilder Query() + { + return new QueryBuilder(Context, Cache, "capsules/query"); + } + } +} \ No newline at end of file diff --git a/Oddity/Endpoints/CompanyEndpoint.cs b/Oddity/Endpoints/CompanyEndpoint.cs new file mode 100644 index 0000000..f654bd4 --- /dev/null +++ b/Oddity/Endpoints/CompanyEndpoint.cs @@ -0,0 +1,31 @@ +using Oddity.Builders; +using Oddity.Configuration; +using Oddity.Models; + +namespace Oddity.Endpoints +{ + /// + /// Represents an entry point of /company endpoint. + /// + /// Type of the data returned from API. + public class CompanyEndpoint : EndpointBase where TData : ModelBase, IIdentifiable, new() + { + /// + /// Initializes a new instance of the class. + /// + /// The Oddity context used to interact with API. + public CompanyEndpoint(OddityCore context) : base(context, LibraryConfiguration.LowPriorityCacheLifetime) + { + + } + + /// + /// Gets data about company from the /company endpoint. + /// + /// Deserialized JSON returned from the API. + public SimpleBuilder Get() + { + return new SimpleBuilder(Context, Cache, "company"); + } + } +} \ No newline at end of file diff --git a/Oddity/Endpoints/CoresEndpoint.cs b/Oddity/Endpoints/CoresEndpoint.cs new file mode 100644 index 0000000..e015f6b --- /dev/null +++ b/Oddity/Endpoints/CoresEndpoint.cs @@ -0,0 +1,50 @@ +using Oddity.Builders; +using Oddity.Configuration; +using Oddity.Models; + +namespace Oddity.Endpoints +{ + /// + /// Represents an entry point of /cores endpoint. + /// + /// Type of the data returned from API. + public class CoresEndpoint : EndpointBase where TData : ModelBase, IIdentifiable, new() + { + /// + /// Initializes a new instance of the class. + /// + /// The Oddity context used to interact with API. + public CoresEndpoint(OddityCore context) : base(context, LibraryConfiguration.MediumPriorityCacheLifetime) + { + + } + + /// + /// Gets data about the specified core from the /cores/:id endpoint. + /// + /// ID of the specified cores. + /// Deserialized JSON returned from the API. + public SimpleBuilder Get(string id) + { + return new SimpleBuilder(Context, Cache, "cores", id); + } + + /// + /// Gets data about all cores from the /cores endpoint. + /// + /// Deserialized JSON returned from the API. + public ListBuilder GetAll() + { + return new ListBuilder(Context, Cache, "cores"); + } + + /// + /// Gets filtered and paginated data about all cores from the /cores/query endpoint. + /// + /// Deserialized JSON returned from the API. + public QueryBuilder Query() + { + return new QueryBuilder(Context, Cache, "cores/query"); + } + } +} \ No newline at end of file diff --git a/Oddity/Endpoints/CrewEndpoint.cs b/Oddity/Endpoints/CrewEndpoint.cs new file mode 100644 index 0000000..d18f8e5 --- /dev/null +++ b/Oddity/Endpoints/CrewEndpoint.cs @@ -0,0 +1,50 @@ +using Oddity.Builders; +using Oddity.Configuration; +using Oddity.Models; + +namespace Oddity.Endpoints +{ + /// + /// Represents an entry point of /crew endpoint. + /// + /// Type of the data returned from API. + public class CrewEndpoint : EndpointBase where TData : ModelBase, IIdentifiable, new() + { + /// + /// Initializes a new instance of the class. + /// + /// The Oddity context used to interact with API. + public CrewEndpoint(OddityCore context) : base(context, LibraryConfiguration.MediumPriorityCacheLifetime) + { + + } + + /// + /// Gets data about the specified crew member from the /crew/:id endpoint. + /// + /// ID of the specified crew member. + /// Deserialized JSON returned from the API. + public SimpleBuilder Get(string id) + { + return new SimpleBuilder(Context, Cache, "crew", id); + } + + /// + /// Gets data about crew from the /crew endpoint. + /// + /// Deserialized JSON returned from the API. + public ListBuilder GetAll() + { + return new ListBuilder(Context, Cache, "crew"); + } + + /// + /// Gets filtered and paginated data about crew from the /crew/query endpoint. + /// + /// Deserialized JSON returned from the API. + public QueryBuilder Query() + { + return new QueryBuilder(Context, Cache, "crew/query"); + } + } +} \ No newline at end of file diff --git a/Oddity/Endpoints/DragonEndpoint.cs b/Oddity/Endpoints/DragonEndpoint.cs new file mode 100644 index 0000000..99f860b --- /dev/null +++ b/Oddity/Endpoints/DragonEndpoint.cs @@ -0,0 +1,50 @@ +using Oddity.Builders; +using Oddity.Configuration; +using Oddity.Models; + +namespace Oddity.Endpoints +{ + /// + /// Represents an entry point of /dragons endpoint. + /// + /// Type of the data returned from API. + public class DragonsEndpoint : EndpointBase where TData : ModelBase, IIdentifiable, new() + { + /// + /// Initializes a new instance of the class. + /// + /// The Oddity context used to interact with API. + public DragonsEndpoint(OddityCore context) : base(context, LibraryConfiguration.LowPriorityCacheLifetime) + { + + } + + /// + /// Gets data about the specified Dragon from the /dragons/:id endpoint. + /// + /// ID of the specified Dragon. + /// Deserialized JSON returned from the API. + public SimpleBuilder Get(string id) + { + return new SimpleBuilder(Context, Cache, "dragons", id); + } + + /// + /// Gets data about all Dragons from the /dragons endpoint. + /// + /// Deserialized JSON returned from the API. + public ListBuilder GetAll() + { + return new ListBuilder(Context, Cache, "dragons"); + } + + /// + /// Gets filtered and paginated data about all Dragon from the /dragons/query endpoint. + /// + /// Deserialized JSON returned from the API. + public QueryBuilder Query() + { + return new QueryBuilder(Context, Cache, "dragons/query"); + } + } +} \ No newline at end of file diff --git a/Oddity/Endpoints/EndpointBase.cs b/Oddity/Endpoints/EndpointBase.cs new file mode 100644 index 0000000..efadd4f --- /dev/null +++ b/Oddity/Endpoints/EndpointBase.cs @@ -0,0 +1,35 @@ +using Oddity.Cache; +using Oddity.Models; + +namespace Oddity.Endpoints +{ + /// + /// Represents a base class for all endpoints. + /// + /// Type of the data returned from API. + public abstract class EndpointBase where TData : ModelBase, IIdentifiable + { + protected readonly OddityCore Context; + protected readonly CacheService Cache; + + /// + /// Initializes a new instance of the class. + /// + /// The Oddity context used to interact with API. + /// The builder delegates container. + protected EndpointBase(OddityCore context, int cacheLifetime) + { + Context = context; + Cache = new CacheService(cacheLifetime); + } + + /// + /// Clears all cached data. + /// + /// Number of purged cached elements. + public int ClearCache() + { + return Cache.Clear(); + } + } +} diff --git a/Oddity/Endpoints/LandpadsEndpoint.cs b/Oddity/Endpoints/LandpadsEndpoint.cs new file mode 100644 index 0000000..1a9faf9 --- /dev/null +++ b/Oddity/Endpoints/LandpadsEndpoint.cs @@ -0,0 +1,50 @@ +using Oddity.Builders; +using Oddity.Configuration; +using Oddity.Models; + +namespace Oddity.Endpoints +{ + /// + /// Represents an entry point of /landpads endpoint. + /// + /// Type of the data returned from API. + public class LandpadsEndpoint : EndpointBase where TData : ModelBase, IIdentifiable, new() + { + /// + /// Initializes a new instance of the class. + /// + /// The Oddity context used to interact with API. + public LandpadsEndpoint(OddityCore context) : base(context, LibraryConfiguration.MediumPriorityCacheLifetime) + { + + } + + /// + /// Gets data about the specified landpad from the /landpads/:id endpoint. + /// + /// ID of the specified landpad. + /// Deserialized JSON returned from the API. + public SimpleBuilder Get(string id) + { + return new SimpleBuilder(Context, Cache, "landpads", id); + } + + /// + /// Gets data about all landpads from the /landpads endpoint. + /// + /// Deserialized JSON returned from the API. + public ListBuilder GetAll() + { + return new ListBuilder(Context, Cache, "landpads"); + } + + /// + /// Gets filtered and paginated data about all landpads from the /landpads/query endpoint. + /// + /// Deserialized JSON returned from the API. + public QueryBuilder Query() + { + return new QueryBuilder(Context, Cache, "landpads/query"); + } + } +} \ No newline at end of file diff --git a/Oddity/Endpoints/LaunchesEndpoint.cs b/Oddity/Endpoints/LaunchesEndpoint.cs new file mode 100644 index 0000000..07c15b1 --- /dev/null +++ b/Oddity/Endpoints/LaunchesEndpoint.cs @@ -0,0 +1,86 @@ +using Oddity.Builders; +using Oddity.Configuration; +using Oddity.Models; + +namespace Oddity.Endpoints +{ + /// + /// Represents an entry point of /launches endpoint. + /// + /// Type of the data returned from API. + public class LaunchesEndpoint : EndpointBase where TData : ModelBase, IIdentifiable, new() + { + /// + /// Initializes a new instance of the class. + /// + /// The Oddity context used to interact with API. + public LaunchesEndpoint(OddityCore context) : base(context, LibraryConfiguration.HighPriorityCacheLifetime) + { + + } + + /// + /// Gets data about the specified launch from the /launches/:id endpoint. + /// + /// ID of the specified launch. + /// Deserialized JSON returned from the API. + public SimpleBuilder Get(string id) + { + return new SimpleBuilder(Context, Cache, "launches", id); + } + + /// + /// Gets data about the latest launch from the /launches/latest endpoint. + /// + /// Deserialized JSON returned from the API. + public SimpleBuilder GetLatest() + { + return new SimpleBuilder(Context, Cache, "launches/latest"); + } + + /// + /// Gets data about the next launch from the /launches/next endpoint. + /// + /// Deserialized JSON returned from the API. + public SimpleBuilder GetNext() + { + return new SimpleBuilder(Context, Cache, "launches/next"); + } + + /// + /// Gets data about all launches from the /launches endpoint. + /// + /// Deserialized JSON returned from the API. + public ListBuilder GetAll() + { + return new ListBuilder(Context, Cache, "launches"); + } + + /// + /// Gets data about all past launches from the /launches/past endpoint. + /// + /// Deserialized JSON returned from the API. + public ListBuilder GetPast() + { + return new ListBuilder(Context, Cache, "launches/past"); + } + + /// + /// Gets data about all upcoming launches from the /launches/upcoming endpoint. + /// + /// Deserialized JSON returned from the API. + public ListBuilder GetUpcoming() + { + return new ListBuilder(Context, Cache, "launches/upcoming"); + } + + /// + /// Gets filtered and paginated data about all launches from the /launches/query endpoint. + /// + /// Deserialized JSON returned from the API. + public QueryBuilder Query() + { + return new QueryBuilder(Context, Cache, "launches/query"); + } + } +} \ No newline at end of file diff --git a/Oddity/Endpoints/LaunchpadsEndpoint.cs b/Oddity/Endpoints/LaunchpadsEndpoint.cs new file mode 100644 index 0000000..748a572 --- /dev/null +++ b/Oddity/Endpoints/LaunchpadsEndpoint.cs @@ -0,0 +1,50 @@ +using Oddity.Builders; +using Oddity.Configuration; +using Oddity.Models; + +namespace Oddity.Endpoints +{ + /// + /// Represents an entry point of /launchpads endpoint. + /// + /// Type of the data returned from API. + public class LaunchpadsEndpoint : EndpointBase where TData : ModelBase, IIdentifiable, new() + { + /// + /// Initializes a new instance of the class. + /// + /// The Oddity context used to interact with API. + public LaunchpadsEndpoint(OddityCore context) : base(context, LibraryConfiguration.MediumPriorityCacheLifetime) + { + + } + + /// + /// Gets data about the specified launchpad from the /launchpads/:id endpoint. + /// + /// ID of the specified launchpad. + /// Deserialized JSON returned from the API. + public SimpleBuilder Get(string id) + { + return new SimpleBuilder(Context, Cache, "launchpads", id); + } + + /// + /// Gets data about all launchpads from the /launchpads endpoint. + /// + /// Deserialized JSON returned from the API. + public ListBuilder GetAll() + { + return new ListBuilder(Context, Cache, "launchpads"); + } + + /// + /// Gets filtered and paginated data about all launchpads from the /launchpads/query endpoint. + /// + /// Deserialized JSON returned from the API. + public QueryBuilder Query() + { + return new QueryBuilder(Context, Cache, "launchpads/query"); + } + } +} \ No newline at end of file diff --git a/Oddity/Endpoints/PayloadsEndpoint.cs b/Oddity/Endpoints/PayloadsEndpoint.cs new file mode 100644 index 0000000..3a7f56d --- /dev/null +++ b/Oddity/Endpoints/PayloadsEndpoint.cs @@ -0,0 +1,50 @@ +using Oddity.Builders; +using Oddity.Configuration; +using Oddity.Models; + +namespace Oddity.Endpoints +{ + /// + /// Represents an entry point of /payloads endpoint. + /// + /// Type of the data returned from API. + public class PayloadsEndpoint : EndpointBase where TData : ModelBase, IIdentifiable, new() + { + /// + /// Initializes a new instance of the class. + /// + /// The Oddity context used to interact with API. + public PayloadsEndpoint(OddityCore context) : base(context, LibraryConfiguration.MediumPriorityCacheLifetime) + { + + } + + /// + /// Gets data about the specified payload from the /payloads/:id endpoint. + /// + /// ID of the specified payload. + /// Deserialized JSON returned from the API. + public SimpleBuilder Get(string id) + { + return new SimpleBuilder(Context, Cache, "payloads", id); + } + + /// + /// Gets data about all payloads from the /payloads endpoint. + /// + /// Deserialized JSON returned from the API. + public ListBuilder GetAll() + { + return new ListBuilder(Context, Cache, "payloads"); + } + + /// + /// Gets filtered and paginated data about all payloads from the /payloads/query endpoint. + /// + /// Deserialized JSON returned from the API. + public QueryBuilder Query() + { + return new QueryBuilder(Context, Cache, "payloads/query"); + } + } +} \ No newline at end of file diff --git a/Oddity/Endpoints/RoadsterEndpoint.cs b/Oddity/Endpoints/RoadsterEndpoint.cs new file mode 100644 index 0000000..e04c8c3 --- /dev/null +++ b/Oddity/Endpoints/RoadsterEndpoint.cs @@ -0,0 +1,31 @@ +using Oddity.Builders; +using Oddity.Configuration; +using Oddity.Models; + +namespace Oddity.Endpoints +{ + /// + /// Represents an entry point of /roadster endpoint. + /// + /// Type of the data returned from API. + public class RoadsterEndpoint : EndpointBase where TData : ModelBase, IIdentifiable, new() + { + /// + /// Initializes a new instance of the class. + /// + /// The Oddity context used to interact with API. + public RoadsterEndpoint(OddityCore context) : base(context, LibraryConfiguration.MediumPriorityCacheLifetime) + { + + } + + /// + /// Gets data about Roadster from the /roadster endpoint. + /// + /// Deserialized JSON returned from the API. + public SimpleBuilder Get() + { + return new SimpleBuilder(Context, Cache, "roadster"); + } + } +} diff --git a/Oddity/Endpoints/RocketsEndpoint.cs b/Oddity/Endpoints/RocketsEndpoint.cs new file mode 100644 index 0000000..5e5d19c --- /dev/null +++ b/Oddity/Endpoints/RocketsEndpoint.cs @@ -0,0 +1,50 @@ +using Oddity.Builders; +using Oddity.Configuration; +using Oddity.Models; + +namespace Oddity.Endpoints +{ + /// + /// Represents an entry point of /rockets endpoint. + /// + /// Type of the data returned from API. + public class RocketsEndpoint : EndpointBase where TData : ModelBase, IIdentifiable, new() + { + /// + /// Initializes a new instance of the class. + /// + /// The Oddity context used to interact with API. + public RocketsEndpoint(OddityCore context) : base(context, LibraryConfiguration.LowPriorityCacheLifetime) + { + + } + + /// + /// Gets data about the specified rocket from the /rockets/:id endpoint. + /// + /// ID of the specified rocket. + /// Deserialized JSON returned from the API. + public SimpleBuilder Get(string id) + { + return new SimpleBuilder(Context, Cache, "rockets", id); + } + + /// + /// Gets data about all rockets from the /rockets endpoint. + /// + /// Deserialized JSON returned from the API. + public ListBuilder GetAll() + { + return new ListBuilder(Context, Cache, "rockets"); + } + + /// + /// Gets filtered and paginated data about all rockets from the /rockets/query endpoint. + /// + /// Deserialized JSON returned from the API. + public QueryBuilder Query() + { + return new QueryBuilder(Context, Cache, "rockets/query"); + } + } +} \ No newline at end of file diff --git a/Oddity/Endpoints/ShipsEndpoint.cs b/Oddity/Endpoints/ShipsEndpoint.cs new file mode 100644 index 0000000..ec3bda0 --- /dev/null +++ b/Oddity/Endpoints/ShipsEndpoint.cs @@ -0,0 +1,50 @@ +using Oddity.Builders; +using Oddity.Configuration; +using Oddity.Models; + +namespace Oddity.Endpoints +{ + /// + /// Represents an entry point of /ships endpoint. + /// + /// Type of the data returned from API. + public class ShipsEndpoint : EndpointBase where TData : ModelBase, IIdentifiable, new() + { + /// + /// Initializes a new instance of the class. + /// + /// The Oddity context used to interact with API. + public ShipsEndpoint(OddityCore context) : base(context, LibraryConfiguration.MediumPriorityCacheLifetime) + { + + } + + /// + /// Gets data about the specified ship from the /ships/:id endpoint. + /// + /// ID of the specified ship. + /// Deserialized JSON returned from the API. + public SimpleBuilder Get(string id) + { + return new SimpleBuilder(Context, Cache, "ships", id); + } + + /// + /// Gets data about all ships from the /ships endpoint. + /// + /// Deserialized JSON returned from the API. + public ListBuilder GetAll() + { + return new ListBuilder(Context, Cache, "ships"); + } + + /// + /// Gets filtered and paginated data about all ships from the /ships/query endpoint. + /// + /// Deserialized JSON returned from the API. + public QueryBuilder Query() + { + return new QueryBuilder(Context, Cache, "ships/query"); + } + } +} \ No newline at end of file diff --git a/Oddity/Endpoints/StarlinkEndpoint.cs b/Oddity/Endpoints/StarlinkEndpoint.cs new file mode 100644 index 0000000..dfff52d --- /dev/null +++ b/Oddity/Endpoints/StarlinkEndpoint.cs @@ -0,0 +1,50 @@ +using Oddity.Builders; +using Oddity.Configuration; +using Oddity.Models; + +namespace Oddity.Endpoints +{ + /// + /// Represents an entry point of /starlink endpoint. + /// + /// Type of the data returned from API. + public class StarlinkEndpoint : EndpointBase where TData : ModelBase, IIdentifiable, new() + { + /// + /// Initializes a new instance of the class. + /// + /// The Oddity context used to interact with API. + public StarlinkEndpoint(OddityCore context) : base(context, LibraryConfiguration.MediumPriorityCacheLifetime) + { + + } + + /// + /// Gets data about the specified Starlink satellite from the /starlink/:id endpoint. + /// + /// ID of the specified Starlink satellite. + /// Deserialized JSON returned from the API. + public SimpleBuilder Get(string id) + { + return new SimpleBuilder(Context, Cache, "starlink", id); + } + + /// + /// Gets data about all Starlink satellites from the /starlink endpoint. + /// + /// Deserialized JSON returned from the API. + public ListBuilder GetAll() + { + return new ListBuilder(Context, Cache, "starlink"); + } + + /// + /// Gets filtered and paginated data about all Starlink satellites from the /starlink/query endpoint. + /// + /// Deserialized JSON returned from the API. + public QueryBuilder Query() + { + return new QueryBuilder(Context, Cache, "starlink/query"); + } + } +} \ No newline at end of file diff --git a/Oddity/Events/BuilderDelegates.cs b/Oddity/Events/BuilderDelegates.cs new file mode 100644 index 0000000..2b81bf6 --- /dev/null +++ b/Oddity/Events/BuilderDelegates.cs @@ -0,0 +1,29 @@ +using Newtonsoft.Json.Serialization; + +namespace Oddity.Events +{ + public delegate void DeserializationError(ErrorEventArgs args); + public delegate void RequestSend(RequestSendEventArgs args); + public delegate void ResponseReceived(ResponseReceiveEventArgs args); + + /// + /// Container for all delegates invoked during processing a request. + /// + public class BuilderDelegates + { + /// + /// Delegate invoked when there was an error during JSON deserialization. + /// + public DeserializationError DeserializationError { get; set; } + + /// + /// Delegate invoked just before request send. + /// + public RequestSend RequestSend { get; set; } + + /// + /// Delegate invoked after response receive. + /// + public ResponseReceived ResponseReceived { get; set; } + } +} diff --git a/Oddity/API/Builders/RequestSendEventArgs.cs b/Oddity/Events/RequestSendEventArgs.cs similarity index 52% rename from Oddity/API/Builders/RequestSendEventArgs.cs rename to Oddity/Events/RequestSendEventArgs.cs index 5e3f2f4..c4999cc 100644 --- a/Oddity/API/Builders/RequestSendEventArgs.cs +++ b/Oddity/Events/RequestSendEventArgs.cs @@ -1,7 +1,6 @@ using System; -using System.Collections.Generic; -namespace Oddity.API.Builders +namespace Oddity.Events { /// /// Contains OnRequestSend event arguments. @@ -14,19 +13,28 @@ public class RequestSendEventArgs : EventArgs public string Url { get; } /// - /// Gets the dictionary of filters which has been applied. + /// Gets the query used to filter data. /// - public Dictionary Filters { get; } + public string Query { get; set; } /// /// Initializes a new instance of the class. /// /// The URL which has been called to retrieve the specified data. - /// The dictionary of filters which has been applied. - public RequestSendEventArgs(string url, Dictionary filters) + public RequestSendEventArgs(string url) { Url = url; - Filters = filters; + } + + /// + /// Initializes a new instance of the class. + /// + /// The URL which has been called to retrieve the specified data. + /// The query used to filter data. + public RequestSendEventArgs(string url, string query) + { + Url = url; + Query = query; } } } diff --git a/Oddity/API/Builders/ResponseReceiveEventArgs.cs b/Oddity/Events/ResponseReceiveEventArgs.cs similarity index 84% rename from Oddity/API/Builders/ResponseReceiveEventArgs.cs rename to Oddity/Events/ResponseReceiveEventArgs.cs index aa21c09..d748412 100644 --- a/Oddity/API/Builders/ResponseReceiveEventArgs.cs +++ b/Oddity/Events/ResponseReceiveEventArgs.cs @@ -1,7 +1,7 @@ using System; using System.Net; -namespace Oddity.API.Builders +namespace Oddity.Events { /// /// Contains OnResponseReceive event arguments. @@ -27,8 +27,8 @@ public class ResponseReceiveEventArgs : EventArgs /// Initializes a new instance of the class. /// /// The raw response from the SpaceX API server. - /// The response status code. - /// The reason phrase. + /// The response status code returned from the API. + /// The reason phrase returned from the API. public ResponseReceiveEventArgs(string response, HttpStatusCode statusCode, string reasonPhrase) { Response = response; diff --git a/Oddity/Exceptions/ApiBadRequestException.cs b/Oddity/Exceptions/ApiBadRequestException.cs new file mode 100644 index 0000000..3028cbd --- /dev/null +++ b/Oddity/Exceptions/ApiBadRequestException.cs @@ -0,0 +1,28 @@ +using System; + +namespace Oddity.Exceptions +{ + /// + /// The exception that is thrown when SpaceX API has received invalid request which cannot be processed. + /// + public class ApiBadRequestException : Exception + { + /// + public ApiBadRequestException() + { + + } + + /// + public ApiBadRequestException(string message) : base(message) + { + + } + + /// + public ApiBadRequestException(string message, Exception inner) : base(message, inner) + { + + } + } +} \ No newline at end of file diff --git a/Oddity/API/Exceptions/APIUnavailableException.cs b/Oddity/Exceptions/ApiUnavailableException.cs similarity index 57% rename from Oddity/API/Exceptions/APIUnavailableException.cs rename to Oddity/Exceptions/ApiUnavailableException.cs index 349073b..be09fe0 100644 --- a/Oddity/API/Exceptions/APIUnavailableException.cs +++ b/Oddity/Exceptions/ApiUnavailableException.cs @@ -1,26 +1,26 @@ using System; -namespace Oddity.API.Exceptions +namespace Oddity.Exceptions { /// /// The exception that is thrown when SpaceX API is unavailable and data can't be loaded. /// - public class APIUnavailableException : Exception + public class ApiUnavailableException : Exception { /// - public APIUnavailableException() + public ApiUnavailableException() { } /// - public APIUnavailableException(string message) : base(message) + public ApiUnavailableException(string message) : base(message) { } /// - public APIUnavailableException(string message, Exception inner) : base(message, inner) + public ApiUnavailableException(string message, Exception inner) : base(message, inner) { } diff --git a/Oddity/Helpers/EnumExtensions.cs b/Oddity/Helpers/EnumExtensions.cs deleted file mode 100644 index cde4901..0000000 --- a/Oddity/Helpers/EnumExtensions.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Linq; -using System.Reflection; -using System.Runtime.Serialization; - -namespace Oddity.Helpers -{ - internal static class EnumExtensions - { - public static string GetEnumMemberAttributeValue(this Enum enumObject, object enumValue) - { - var enumType = enumObject.GetType().GetTypeInfo(); - - var memberInfo = enumType.GetDeclaredField(enumValue.ToString()); - var enumMemberAttribute = memberInfo.GetCustomAttributes(false).OfType().FirstOrDefault(); - - return enumMemberAttribute?.Value; - } - } -} diff --git a/Oddity/Models/Capsules/CapsuleInfo.cs b/Oddity/Models/Capsules/CapsuleInfo.cs new file mode 100644 index 0000000..39bcb7d --- /dev/null +++ b/Oddity/Models/Capsules/CapsuleInfo.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Newtonsoft.Json; +using Oddity.Models.Launches; + +namespace Oddity.Models.Capsules +{ + public class CapsuleInfo : ModelBase, IIdentifiable + { + public string Id { get; set; } + public string Serial { get; set; } + + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] + public CapsuleStatus Status { get; set; } + + [JsonProperty("reuse_count")] + public uint? ReuseCount { get; set; } + + [JsonProperty("water_landings")] + public uint? WaterLandings { get; set; } + + [JsonProperty("land_landings")] + public uint? LandLandings { get; set; } + + [JsonProperty("last_update")] + public string LastUpdate { get; set; } + + [JsonProperty("launches")] + public List LaunchesId + { + get => _launchesId; + set + { + _launchesId = value; + Launches = _launchesId.Select(p => new Lazy(() => Context.LaunchesEndpoint.Get(p).Execute())).ToList(); + } + } + + public List> Launches { get; private set; } + + private List _launchesId; + + public override string ToString() + { + return Serial; + } + } +} diff --git a/Oddity/Models/Capsules/CapsuleStatus.cs b/Oddity/Models/Capsules/CapsuleStatus.cs new file mode 100644 index 0000000..0080c4e --- /dev/null +++ b/Oddity/Models/Capsules/CapsuleStatus.cs @@ -0,0 +1,10 @@ +namespace Oddity.Models.Capsules +{ + public enum CapsuleStatus + { + Unknown, + Active, + Retired, + Destroyed + } +} diff --git a/Oddity/Models/Common/IspInfo.cs b/Oddity/Models/Common/IspInfo.cs new file mode 100644 index 0000000..d157f4c --- /dev/null +++ b/Oddity/Models/Common/IspInfo.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; + +namespace Oddity.Models.Common +{ + public class IspInfo : ModelBase + { + public uint? Vacuum { get; set; } + + [JsonProperty("sea_level")] + public uint? SeaLevel { get; set; } + } +} diff --git a/Oddity/Models/Common/MassInfo.cs b/Oddity/Models/Common/MassInfo.cs new file mode 100644 index 0000000..37e0a42 --- /dev/null +++ b/Oddity/Models/Common/MassInfo.cs @@ -0,0 +1,18 @@ +using Newtonsoft.Json; + +namespace Oddity.Models.Common +{ + public class MassInfo : ModelBase + { + [JsonProperty("kg")] + public double? Kilograms { get; set; } + + [JsonProperty("lb")] + public double? Pounds { get; set; } + + public override string ToString() + { + return $"{Kilograms} kg ({Pounds} lb)"; + } + } +} diff --git a/Oddity/Models/Common/SizeInfo.cs b/Oddity/Models/Common/SizeInfo.cs new file mode 100644 index 0000000..0f1bb42 --- /dev/null +++ b/Oddity/Models/Common/SizeInfo.cs @@ -0,0 +1,13 @@ +namespace Oddity.Models.Common +{ + public class SizeInfo : ModelBase + { + public double? Meters { get; set; } + public double? Feet { get; set; } + + public override string ToString() + { + return $"{Meters} m ({Feet} ft)"; + } + } +} diff --git a/Oddity/Models/Common/SpaceTrackInfo.cs b/Oddity/Models/Common/SpaceTrackInfo.cs new file mode 100644 index 0000000..60e788e --- /dev/null +++ b/Oddity/Models/Common/SpaceTrackInfo.cs @@ -0,0 +1,131 @@ +using System; +using Newtonsoft.Json; + +namespace Oddity.Models.Common +{ + public class SpaceTrackInfo : ModelBase + { + [JsonProperty("CCSDS_OMM_VERS")] + public string CcsdsOmmVers { get; set; } + + [JsonProperty("COMMENT")] + public string Comment { get; set; } + + [JsonProperty("CREATION_DATE")] + public DateTime? CreationDate { get; set; } + + [JsonProperty("ORIGINATOR")] + public string Originator { get; set; } + + [JsonProperty("OBJECT_NAME")] + public string ObjectName { get; set; } + + [JsonProperty("OBJECT_ID")] + public string ObjectId { get; set; } + + [JsonProperty("CENTER_NAME")] + public string CenterName { get; set; } + + [JsonProperty("REF_FRAME")] + public string RefFrame { get; set; } + + [JsonProperty("TIME_SYSTEM")] + public string TimeSystem { get; set; } + + [JsonProperty("MEAN_ELEMENT_THEORY")] + public string MeanElementTheory { get; set; } + + [JsonProperty("EPOCH")] + public DateTime? Epoch { get; set; } + + [JsonProperty("MEAN_MOTION")] + public double? MeanMotion { get; set; } + + [JsonProperty("ECCENTRICITY")] + public double? Eccentricity { get; set; } + + [JsonProperty("INCLINATION")] + public double? Inclination { get; set; } + + [JsonProperty("RA_OF_ASC_NODE")] + public double? RaOfAscNode { get; set; } + + [JsonProperty("ARG_OF_PERICENTER")] + public double? ArgOfPericenter { get; set; } + + [JsonProperty("MEAN_ANOMALY")] + public double? MeanAnomaly { get; set; } + + [JsonProperty("EPHEMERIS_TYPE")] + public uint? EphemerisType { get; set; } + + [JsonProperty("CLASSIFICATION_TYPE")] + public string ClassificationType { get; set; } + + [JsonProperty("NORAD_CAT_ID")] + public uint? NoradCatId { get; set; } + + [JsonProperty("ELEMENT_SET_NO")] + public uint? NoradSetNo { get; set; } + + [JsonProperty("REV_AT_EPOCH")] + public uint? RevAtEpoch { get; set; } + + [JsonProperty("BSTAR")] + public double? Bstar { get; set; } + + [JsonProperty("MEAN_MOTION_DOT")] + public double? MeanMotionDot { get; set; } + + [JsonProperty("MEAN_MOTION_DDOT")] + public double? MeanMotionDdot { get; set; } + + [JsonProperty("SEMIMAJOR_AXIS")] + public double? SemimajorAxis { get; set; } + + [JsonProperty("PERIOD")] + public double? Period { get; set; } + + [JsonProperty("APOAPSIS")] + public double? Apoapsis { get; set; } + + [JsonProperty("PERIAPSIS")] + public double? Periapsis { get; set; } + + [JsonProperty("OBJECT_TYPE")] + public string ObjectType { get; set; } + + [JsonProperty("RCS_SIZE")] + public string RcsSize { get; set; } + + [JsonProperty("COUNTRY_CODE")] + public string CountryCode { get; set; } + + [JsonProperty("LAUNCH_DATE")] + public DateTime? LaunchDate { get; set; } + + [JsonProperty("SITE")] + public string Site { get; set; } + + [JsonProperty("DECAY_DATE")] + public DateTime? DecayDate { get; set; } + + [JsonProperty("DECAYED")] + public uint? Decayed { get; set; } + + [JsonProperty("FILE")] + public uint? File { get; set; } + + [JsonProperty("GP_ID")] + public uint? GpId { get; set; } + + [JsonProperty("TLE_LINE0")] + public string TleLine0 { get; set; } + + [JsonProperty("TLE_LINE1")] + public string TleLine1 { get; set; } + + [JsonProperty("TLE_LINE2")] + public string TleLine2 { get; set; } + } +} diff --git a/Oddity/Models/Common/ThrustInfo.cs b/Oddity/Models/Common/ThrustInfo.cs new file mode 100644 index 0000000..8b8d35f --- /dev/null +++ b/Oddity/Models/Common/ThrustInfo.cs @@ -0,0 +1,18 @@ +using Newtonsoft.Json; + +namespace Oddity.Models.Common +{ + public class ThrustInfo : ModelBase + { + [JsonProperty("kN")] + public double? Kilonewtons { get; set; } + + [JsonProperty("lbf")] + public double? PoundForce { get; set; } + + public override string ToString() + { + return $"{Kilonewtons} kn ({PoundForce} lbf)"; + } + } +} diff --git a/Oddity/API/Models/Common/VolumeInfo.cs b/Oddity/Models/Common/VolumeInfo.cs similarity index 52% rename from Oddity/API/Models/Common/VolumeInfo.cs rename to Oddity/Models/Common/VolumeInfo.cs index 4e2bfc2..09c050f 100644 --- a/Oddity/API/Models/Common/VolumeInfo.cs +++ b/Oddity/Models/Common/VolumeInfo.cs @@ -1,13 +1,18 @@ using Newtonsoft.Json; -namespace Oddity.API.Models.Common +namespace Oddity.Models.Common { - public class VolumeInfo + public class VolumeInfo : ModelBase { [JsonProperty("cubic_meters")] public double? CubicMeters { get; set; } [JsonProperty("cubic_feet")] public double? CubicFeet { get; set; } + + public override string ToString() + { + return $"{CubicFeet} m^3 ({CubicFeet} ft^3)"; + } } } diff --git a/Oddity/API/Models/Company/Headquarters.cs b/Oddity/Models/Company/CompanyHeadquartersInfo.cs similarity index 61% rename from Oddity/API/Models/Company/Headquarters.cs rename to Oddity/Models/Company/CompanyHeadquartersInfo.cs index f92aa73..36d79c2 100644 --- a/Oddity/API/Models/Company/Headquarters.cs +++ b/Oddity/Models/Company/CompanyHeadquartersInfo.cs @@ -1,6 +1,6 @@ -namespace Oddity.API.Models.Company +namespace Oddity.Models.Company { - public class Headquarters + public class CompanyHeadquartersInfo : ModelBase { public string Address { get; set; } public string City { get; set; } diff --git a/Oddity/API/Models/Company/CompanyInfo.cs b/Oddity/Models/Company/CompanyInfo.cs similarity index 69% rename from Oddity/API/Models/Company/CompanyInfo.cs rename to Oddity/Models/Company/CompanyInfo.cs index 02b91b6..dbb1a07 100644 --- a/Oddity/API/Models/Company/CompanyInfo.cs +++ b/Oddity/Models/Company/CompanyInfo.cs @@ -1,34 +1,38 @@ using Newtonsoft.Json; -namespace Oddity.API.Models.Company +namespace Oddity.Models.Company { - public class CompanyInfo + public class CompanyInfo : ModelBase, IIdentifiable { + public string Id { get; set; } public string Name { get; set; } public string Founder { get; set; } + public uint? Employees { get; set; } + public uint? Vehicles { get; set; } + public string Ceo { get; set; } + public string Cto { get; set; } + public string Coo { get; set; } + public ulong? Valuation { get; set; } + public string Summary { get; set; } + + public CompanyHeadquartersInfo Headquarters { get; set; } + public CompanyLinksInfo Links { get; set; } [JsonProperty("founded")] public uint? FoundedYear { get; set; } - public uint? Employees { get; set; } - public uint? Vehicles { get; set; } - [JsonProperty("launch_sites")] public uint? LaunchSites { get; set; } [JsonProperty("test_sites")] public uint? TestSites { get; set; } - public string Ceo { get; set; } - public string Cto { get; set; } - public string Coo { get; set; } - [JsonProperty("cto_propulsion")] public string CtoPropulsion { get; set; } - public ulong? Valuation { get; set; } - public Headquarters Headquarters { get; set; } - public CompanyLinks Links { get; set; } - public string Summary { get; set; } + public override string ToString() + { + return Name; + } } } diff --git a/Oddity/API/Models/Company/CompanyLinks.cs b/Oddity/Models/Company/CompanyLinksInfo.cs similarity index 77% rename from Oddity/API/Models/Company/CompanyLinks.cs rename to Oddity/Models/Company/CompanyLinksInfo.cs index 09360e1..0e8eda2 100644 --- a/Oddity/API/Models/Company/CompanyLinks.cs +++ b/Oddity/Models/Company/CompanyLinksInfo.cs @@ -1,8 +1,8 @@ using Newtonsoft.Json; -namespace Oddity.API.Models.Company +namespace Oddity.Models.Company { - public class CompanyLinks + public class CompanyLinksInfo : ModelBase { public string Website { get; set; } public string Flickr { get; set; } diff --git a/Oddity/Models/Cores/CoreInfo.cs b/Oddity/Models/Cores/CoreInfo.cs new file mode 100644 index 0000000..7ed80bd --- /dev/null +++ b/Oddity/Models/Cores/CoreInfo.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Newtonsoft.Json; +using Oddity.Models.Launches; + +namespace Oddity.Models.Cores +{ + public class CoreInfo : ModelBase, IIdentifiable + { + public string Id { get; set; } + public string Serial { get; set; } + public uint? Block { get; set; } + + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] + public CoreStatus Status { get; set; } + + [JsonProperty("reuse_count")] + public uint? ReuseCount { get; set; } + + [JsonProperty("rtls_attempts")] + public uint? RtlsAttempts { get; set; } + + [JsonProperty("rtls_landings")] + public uint? RtlsLandings { get; set; } + + [JsonProperty("asds_attempts")] + public uint? AsdsAttempts { get; set; } + + [JsonProperty("asds_landings")] + public uint? AsdsLandings { get; set; } + + [JsonProperty("last_update")] + public string LastUpdate { get; set; } + + [JsonProperty("launches")] + public List LaunchesId + { + get => _launchesId; + set + { + _launchesId = value; + Launches = _launchesId.Select(p => new Lazy(() => Context.LaunchesEndpoint.Get(p).Execute())).ToList(); + } + } + + public List> Launches { get; private set; } + + private List _launchesId; + + public override string ToString() + { + return Serial; + } + } +} diff --git a/Oddity/Models/Cores/CoreStatus.cs b/Oddity/Models/Cores/CoreStatus.cs new file mode 100644 index 0000000..e247211 --- /dev/null +++ b/Oddity/Models/Cores/CoreStatus.cs @@ -0,0 +1,12 @@ +namespace Oddity.Models.Cores +{ + public enum CoreStatus + { + Unknown, + Active, + Inactive, + Expended, + Retired, + Lost + } +} diff --git a/Oddity/Models/Crew/CrewInfo.cs b/Oddity/Models/Crew/CrewInfo.cs new file mode 100644 index 0000000..df38f1c --- /dev/null +++ b/Oddity/Models/Crew/CrewInfo.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Newtonsoft.Json; +using Oddity.Models.Launches; + +namespace Oddity.Models.Crew +{ + public class CrewInfo : ModelBase, IIdentifiable + { + public string Id { get; set; } + public string Name { get; set; } + public string Agency { get; set; } + public string Wikipedia { get; set; } + public string Image { get; set; } + + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] + public CrewStatus Status { get; set; } + + [JsonProperty("launches")] + public List LaunchesId + { + get => _launchesId; + set + { + _launchesId = value; + Launches = _launchesId.Select(p => new Lazy(() => Context.LaunchesEndpoint.Get(p).Execute())).ToList(); + } + } + + public List> Launches { get; private set; } + + private List _launchesId; + + public override string ToString() + { + return Name; + } + } +} diff --git a/Oddity/Models/Crew/CrewStatus.cs b/Oddity/Models/Crew/CrewStatus.cs new file mode 100644 index 0000000..43321bf --- /dev/null +++ b/Oddity/Models/Crew/CrewStatus.cs @@ -0,0 +1,10 @@ +namespace Oddity.Models.Crew +{ + public enum CrewStatus + { + Unknown, + Active, + Inactive, + Retired + } +} diff --git a/Oddity/API/Models/Dragon/Payload/CargoInfo.cs b/Oddity/Models/Dragon/DragonCargoInfo.cs similarity index 59% rename from Oddity/API/Models/Dragon/Payload/CargoInfo.cs rename to Oddity/Models/Dragon/DragonCargoInfo.cs index 8085075..d1d89f5 100644 --- a/Oddity/API/Models/Dragon/Payload/CargoInfo.cs +++ b/Oddity/Models/Dragon/DragonCargoInfo.cs @@ -1,11 +1,11 @@ using Newtonsoft.Json; -namespace Oddity.API.Models.Dragon.Payload +namespace Oddity.Models.Dragon { - public class CargoInfo + public class DragonCargoInfo : ModelBase { [JsonProperty("solar_array")] - public uint? SolarArraysCount { get; set; } + public uint? SolarArray { get; set; } [JsonProperty("unpressurized_cargo")] public bool? UnpressurizedCargo { get; set; } diff --git a/Oddity/API/Models/Dragon/Heatshield/HeatshieldInfo.cs b/Oddity/Models/Dragon/DragonHeatshieldInfo.cs similarity index 69% rename from Oddity/API/Models/Dragon/Heatshield/HeatshieldInfo.cs rename to Oddity/Models/Dragon/DragonHeatshieldInfo.cs index 220ec43..01e0738 100644 --- a/Oddity/API/Models/Dragon/Heatshield/HeatshieldInfo.cs +++ b/Oddity/Models/Dragon/DragonHeatshieldInfo.cs @@ -1,8 +1,8 @@ using Newtonsoft.Json; -namespace Oddity.API.Models.Dragon.Heatshield +namespace Oddity.Models.Dragon { - public class HeatshieldInfo + public class DragonHeatshieldInfo : ModelBase { public string Material { get; set; } @@ -10,7 +10,7 @@ public class HeatshieldInfo public double? SizeMeters { get; set; } [JsonProperty("temp_degrees")] - public uint? MaxTemperatureDegrees { get; set; } + public uint? TemperatureDegrees { get; set; } [JsonProperty("dev_partner")] public string DevPartner { get; set; } diff --git a/Oddity/API/Models/Dragon/DragonInfo.cs b/Oddity/Models/Dragon/DragonInfo.cs similarity index 64% rename from Oddity/API/Models/Dragon/DragonInfo.cs rename to Oddity/Models/Dragon/DragonInfo.cs index c1d0aa5..9f1defd 100644 --- a/Oddity/API/Models/Dragon/DragonInfo.cs +++ b/Oddity/Models/Dragon/DragonInfo.cs @@ -1,19 +1,22 @@ using System; using System.Collections.Generic; using Newtonsoft.Json; -using Oddity.API.Models.Common; -using Oddity.API.Models.Dragon.Heatshield; -using Oddity.API.Models.Dragon.Payload; -using Oddity.API.Models.Dragon.Thrusters; +using Oddity.Models.Common; -namespace Oddity.API.Models.Dragon +namespace Oddity.Models.Dragon { - public class DragonInfo + public class DragonInfo : ModelBase, IIdentifiable { - public DragonId? Id { get; set; } - + public string Id { get; set; } public string Name { get; set; } + public string Type { get; set; } public bool? Active { get; set; } + public string Wikipedia { get; set; } + public string Description { get; set; } + + public SizeInfo Diameter { get; set; } + public DragonTrunkInfo Trunk { get; set; } + public List Thrusters { get; set; } [JsonProperty("crew_capacity")] public uint? CrewCapacity { get; set; } @@ -25,18 +28,22 @@ public class DragonInfo public uint? OrbitDurationYears { get; set; } [JsonProperty("dry_mass_kg")] - public float? DryMassKilograms { get; set; } + public double? DryMassKilograms { get; set; } [JsonProperty("dry_mass_lb")] - public float? DryMassPounds { get; set; } + public double? DryMassPounds { get; set; } [JsonProperty("first_flight")] - public DateTime FirstFlight { get; set; } + public DateTime? FirstFlight { get; set; } - [JsonProperty("heat_shield")] - public HeatshieldInfo Heatshield { get; set; } + [JsonProperty("flickr_images")] + public List FlickrImages { get; set; } - public List Thrusters { get; set; } + [JsonProperty("height_w_trunk")] + public SizeInfo HeightWithTrunk { get; set; } + + [JsonProperty("heat_shield")] + public DragonHeatshieldInfo HeatShield { get; set; } [JsonProperty("launch_payload_mass")] public MassInfo LaunchPayloadMass { get; set; } @@ -51,19 +58,6 @@ public class DragonInfo public VolumeInfo ReturnPayloadVolume { get; set; } [JsonProperty("pressurized_capsule")] - public PressurizedCapsuleInfo PressurizedCapsule { get; set; } - - public TrunkInfo Trunk { get; set; } - - [JsonProperty("height_w_trunk")] - public SizeInfo HeightWithTrunk { get; set; } - - public SizeInfo Diameter { get; set; } - - [JsonProperty("wikipedia")] - public string Wikipedia { get; set; } - - [JsonProperty("description")] - public string Description { get; set; } + public DragonPressurizedCapsuleInfo PressurizedCapsule { get; set; } } } diff --git a/Oddity/API/Models/Dragon/Payload/PressurizedCapsuleInfo.cs b/Oddity/Models/Dragon/DragonPressurizedCapsuleInfo.cs similarity index 54% rename from Oddity/API/Models/Dragon/Payload/PressurizedCapsuleInfo.cs rename to Oddity/Models/Dragon/DragonPressurizedCapsuleInfo.cs index 152fc24..acdc03d 100644 --- a/Oddity/API/Models/Dragon/Payload/PressurizedCapsuleInfo.cs +++ b/Oddity/Models/Dragon/DragonPressurizedCapsuleInfo.cs @@ -1,9 +1,9 @@ using Newtonsoft.Json; -using Oddity.API.Models.Common; +using Oddity.Models.Common; -namespace Oddity.API.Models.Dragon.Payload +namespace Oddity.Models.Dragon { - public class PressurizedCapsuleInfo + public class DragonPressurizedCapsuleInfo : ModelBase { [JsonProperty("payload_volume")] public VolumeInfo PayloadVolume { get; set; } diff --git a/Oddity/Models/Dragon/DragonThrustersInfo.cs b/Oddity/Models/Dragon/DragonThrustersInfo.cs new file mode 100644 index 0000000..31c25e1 --- /dev/null +++ b/Oddity/Models/Dragon/DragonThrustersInfo.cs @@ -0,0 +1,21 @@ +using Newtonsoft.Json; +using Oddity.Models.Common; + +namespace Oddity.Models.Dragon +{ + public class DragonThrustersInfo : ModelBase + { + public string Type { get; set; } + public uint? Amount { get; set; } + public uint? Pods { get; set; } + public uint? Isp { get; set; } + + public ThrustInfo Thrust { get; set; } + + [JsonProperty("fuel_1")] + public string FirstFuel { get; set; } + + [JsonProperty("fuel_2")] + public string SecondFuel { get; set; } + } +} diff --git a/Oddity/Models/Dragon/DragonTrunkInfo.cs b/Oddity/Models/Dragon/DragonTrunkInfo.cs new file mode 100644 index 0000000..844992f --- /dev/null +++ b/Oddity/Models/Dragon/DragonTrunkInfo.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; +using Oddity.Models.Common; + +namespace Oddity.Models.Dragon +{ + public class DragonTrunkInfo : ModelBase + { + public DragonCargoInfo Cargo { get; set; } + + [JsonProperty("trunk_volume")] + public VolumeInfo TrunkVolume { get; set; } + } +} diff --git a/Oddity/Models/IIdentifiable.cs b/Oddity/Models/IIdentifiable.cs new file mode 100644 index 0000000..4510a87 --- /dev/null +++ b/Oddity/Models/IIdentifiable.cs @@ -0,0 +1,13 @@ +namespace Oddity.Models +{ + /// + /// Base interface for all models containing its own ID. + /// + public interface IIdentifiable + { + /// + /// Gets or sets the model ID. + /// + string Id { get; set; } + } +} diff --git a/Oddity/Models/Landpads/LandpadInfo.cs b/Oddity/Models/Landpads/LandpadInfo.cs new file mode 100644 index 0000000..c94e3d8 --- /dev/null +++ b/Oddity/Models/Landpads/LandpadInfo.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Newtonsoft.Json; +using Oddity.Models.Launches; + +namespace Oddity.Models.Landpads +{ + public class LandpadInfo : ModelBase, IIdentifiable + { + public string Id { get; set; } + public string Name { get; set; } + public string Type { get; set; } + public string Locality { get; set; } + public string Region { get; set; } + public double? Latitude { get; set; } + public double? Longitude { get; set; } + public string Wikipedia { get; set; } + public string Details { get; set; } + + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] + public LandpadStatus Status { get; set; } + + [JsonProperty("full_name")] + public string FullName { get; set; } + + [JsonProperty("landing_attempts")] + public uint? LandingAttempts { get; set; } + + [JsonProperty("landing_successes")] + public uint? LandingSuccesses { get; set; } + + [JsonProperty("launches")] + public List LaunchesId + { + get => _launchesId; + set + { + _launchesId = value; + Launches = _launchesId.Select(p => new Lazy(() => Context.LaunchesEndpoint.Get(p).Execute())).ToList(); + } + } + + public List> Launches { get; private set; } + + private List _launchesId; + + public override string ToString() + { + return Name; + } + } +} diff --git a/Oddity/Models/Landpads/LandpadStatus.cs b/Oddity/Models/Landpads/LandpadStatus.cs new file mode 100644 index 0000000..3c8c34d --- /dev/null +++ b/Oddity/Models/Landpads/LandpadStatus.cs @@ -0,0 +1,16 @@ +using System.Runtime.Serialization; + +namespace Oddity.Models.Landpads +{ + public enum LandpadStatus + { + Unknown, + Active, + Inactive, + Retired, + Lost, + + [EnumMember(Value = "under construction")] + UnderConstruction + } +} diff --git a/Oddity/Models/Launches/DatePrecision.cs b/Oddity/Models/Launches/DatePrecision.cs new file mode 100644 index 0000000..884837d --- /dev/null +++ b/Oddity/Models/Launches/DatePrecision.cs @@ -0,0 +1,13 @@ +namespace Oddity.Models.Launches +{ + public enum DatePrecision + { + Unknown, + Hour, + Day, + Month, + Quarter, + Half, + Year + } +} diff --git a/Oddity/Models/Launches/LaunchCoreInfo.cs b/Oddity/Models/Launches/LaunchCoreInfo.cs new file mode 100644 index 0000000..b7aa210 --- /dev/null +++ b/Oddity/Models/Launches/LaunchCoreInfo.cs @@ -0,0 +1,52 @@ +using System; +using Newtonsoft.Json; +using Oddity.Models.Cores; +using Oddity.Models.Landpads; + +namespace Oddity.Models.Launches +{ + public class LaunchCoreInfo : ModelBase + { + public uint? Flight { get; set; } + public bool? Gridfins { get; set; } + public bool? Legs { get; set; } + public bool? Reused { get; set; } + + [JsonProperty("landing_attempt")] + public bool? LandingAttempt { get; set; } + + [JsonProperty("landing_success")] + public bool? LandingSuccess { get; set; } + + [JsonProperty("landing_type")] + public string LandingType { get; set; } + + [JsonProperty("core")] + public string CoreId + { + get => _coreId; + set + { + _coreId = value; + Core = new Lazy(() => Context.CoresEndpoint.Get(_coreId).Execute()); + } + } + + [JsonProperty("landpad")] + public string LandpadId + { + get => _landpadId; + set + { + _landpadId = value; + Landpad = new Lazy(() => Context.LandpadsEndpoint.Get(_landpadId).Execute()); + } + } + + public Lazy Core { get; private set; } + public Lazy Landpad { get; private set; } + + private string _coreId; + private string _landpadId; + } +} diff --git a/Oddity/Models/Launches/LaunchFairingsInfo.cs b/Oddity/Models/Launches/LaunchFairingsInfo.cs new file mode 100644 index 0000000..b612271 --- /dev/null +++ b/Oddity/Models/Launches/LaunchFairingsInfo.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Newtonsoft.Json; +using Oddity.Models.Ships; + +namespace Oddity.Models.Launches +{ + public class LaunchFairingsInfo : ModelBase + { + public bool? Reused { get; set; } + public bool? Recovered { get; set; } + + [JsonProperty("recovery_attempt")] + public bool? RecoveryAttempt { get; set; } + + [JsonProperty("ships")] + public List ShipsId + { + get => _shipsId; + set + { + _shipsId = value; + Ships = _shipsId.Select(p => new Lazy(() => Context.ShipsEndpoint.Get(p).Execute())).ToList(); + } + } + + public List> Ships { get; private set; } + + private List _shipsId; + } +} diff --git a/Oddity/Models/Launches/LaunchFlickrInfo.cs b/Oddity/Models/Launches/LaunchFlickrInfo.cs new file mode 100644 index 0000000..1aa4890 --- /dev/null +++ b/Oddity/Models/Launches/LaunchFlickrInfo.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; + +namespace Oddity.Models.Launches +{ + public class LaunchFlickrInfo : ModelBase + { + public List Small { get; set; } + public List Original { get; set; } + } +} diff --git a/Oddity/Models/Launches/LaunchInfo.cs b/Oddity/Models/Launches/LaunchInfo.cs new file mode 100644 index 0000000..a2b509c --- /dev/null +++ b/Oddity/Models/Launches/LaunchInfo.cs @@ -0,0 +1,145 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Newtonsoft.Json; +using Oddity.Models.Capsules; +using Oddity.Models.Crew; +using Oddity.Models.Launchpads; +using Oddity.Models.Payloads; +using Oddity.Models.Rockets; +using Oddity.Models.Ships; + +namespace Oddity.Models.Launches +{ + public class LaunchInfo : ModelBase, IIdentifiable + { + public string Id { get; set; } + public string Name { get; set; } + public bool? Upcoming { get; set; } + public bool? Success { get; set; } + public string Details { get; set; } + + public List Cores { get; set; } + public LaunchLinks Links { get; set; } + public LaunchFairingsInfo Fairings { get; set; } + public List Failures { get; set; } + + [JsonProperty("flight_number")] + public uint? FlightNumber { get; set; } + + [JsonProperty("date_utc")] + public DateTime? DateUtc { get; set; } + + [JsonProperty("date_unix")] + public ulong? DateUnix { get; set; } + + [JsonProperty("date_local")] + public DateTime? DateLocal { get; set; } + + [JsonProperty("date_precision")] + public DatePrecision? DatePrecision { get; set; } + + [JsonProperty("static_fire_date_utc")] + public DateTime? StaticFireDateUtc { get; set; } + + [JsonProperty("static_fire_date_unix")] + public ulong? StaticFireDateUnix { get; set; } + + [JsonProperty("tbd")] + public bool? ToBeDated { get; set; } + + [JsonProperty("net")] + public bool? NotEarlierThan { get; set; } + + [JsonProperty("window")] + public ulong? Window { get; set; } + + [JsonProperty("auto_update")] + public bool? AutoUpdate { get; set; } + + [JsonProperty("rocket")] + public string RocketId + { + get => _rocketId; + set + { + _rocketId = value; + Rocket = new Lazy(() => Context.RocketsEndpoint.Get(_rocketId).Execute()); + } + } + + [JsonProperty("crew")] + public List CrewId + { + get => _crewId; + set + { + _crewId = value; + Crew = _crewId.Select(p => new Lazy(() => Context.CrewEndpoint.Get(p).Execute())).ToList(); + } + } + + [JsonProperty("ships")] + public List ShipsId + { + get => _shipsId; + set + { + _shipsId = value; + Ships = _shipsId.Select(p => new Lazy(() => Context.ShipsEndpoint.Get(p).Execute())).ToList(); + } + } + + [JsonProperty("capsules")] + public List CapsulesId + { + get => _capsulesId; + set + { + _capsulesId = value; + Capsules = _capsulesId.Select(p => new Lazy(() => Context.CapsulesEndpoint.Get(p).Execute())).ToList(); + } + } + + [JsonProperty("payloads")] + public List PayloadsId + { + get => _payloadsId; + set + { + _payloadsId = value; + Payloads = _payloadsId.Select(p => new Lazy(() => Context.PayloadsEndpoint.Get(p).Execute())).ToList(); + } + } + + [JsonProperty("launchpad")] + public string LaunchpadId + { + get => _launchpadId; + set + { + _launchpadId = value; + Launchpad = new Lazy(() => Context.LaunchpadsEndpoint.Get(_launchpadId).Execute()); + } + } + + public Lazy Rocket { get; private set; } + public List> Crew { get; private set; } + public List> Ships { get; private set; } + public List> Capsules { get; private set; } + public List> Payloads { get; private set; } + public Lazy Launchpad { get; private set; } + + private string _rocketId; + private List _crewId; + private List _shipsId; + private List _capsulesId; + private List _payloadsId; + private string _launchpadId; + + public override string ToString() + { + return Name; + } + } +} diff --git a/Oddity/Models/Launches/LaunchLinks.cs b/Oddity/Models/Launches/LaunchLinks.cs new file mode 100644 index 0000000..a3d92bf --- /dev/null +++ b/Oddity/Models/Launches/LaunchLinks.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; + +namespace Oddity.Models.Launches +{ + public class LaunchLinks : ModelBase + { + public string Presskit { get; set; } + public string Webcast { get; set; } + public string Article { get; set; } + public string Wikipedia { get; set; } + + public LaunchPatchInfo Patch { get; set; } + public LaunchRedditInfo Reddit { get; set; } + public LaunchFlickrInfo Flickr { get; set; } + + [JsonProperty("youtube_id")] + public string YouTubeId { get; set; } + } +} diff --git a/Oddity/Models/Launches/LaunchPatchInfo.cs b/Oddity/Models/Launches/LaunchPatchInfo.cs new file mode 100644 index 0000000..fec3351 --- /dev/null +++ b/Oddity/Models/Launches/LaunchPatchInfo.cs @@ -0,0 +1,8 @@ +namespace Oddity.Models.Launches +{ + public class LaunchPatchInfo : ModelBase + { + public string Small { get; set; } + public string Large { get; set; } + } +} diff --git a/Oddity/Models/Launches/LaunchRedditInfo.cs b/Oddity/Models/Launches/LaunchRedditInfo.cs new file mode 100644 index 0000000..e0de87d --- /dev/null +++ b/Oddity/Models/Launches/LaunchRedditInfo.cs @@ -0,0 +1,10 @@ +namespace Oddity.Models.Launches +{ + public class LaunchRedditInfo : ModelBase + { + public string Campaign { get; set; } + public string Launch { get; set; } + public string Media { get; set; } + public string Recovery { get; set; } + } +} diff --git a/Oddity/Models/Launchpads/LaunchpadInfo.cs b/Oddity/Models/Launchpads/LaunchpadInfo.cs new file mode 100644 index 0000000..22dd190 --- /dev/null +++ b/Oddity/Models/Launchpads/LaunchpadInfo.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Newtonsoft.Json; +using Oddity.Models.Launches; +using Oddity.Models.Rockets; + +namespace Oddity.Models.Launchpads +{ + public class LaunchpadInfo : ModelBase, IIdentifiable + { + public string Id { get; set; } + public string Name { get; set; } + public string Locality { get; set; } + public string Region { get; set; } + public string TimeZone { get; set; } + public double? Latitude { get; set; } + public double? Longitude { get; set; } + + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] + public LaunchpadStatus Status { get; set; } + + [JsonProperty("full_name")] + public string FullName { get; set; } + + [JsonProperty("launch_attempts")] + public uint? LaunchAttempts { get; set; } + + [JsonProperty("launch_successes")] + public uint? LaunchSuccesses { get; set; } + + [JsonProperty("rockets")] + public List RocketsId + { + get => _rocketsId; + set + { + _rocketsId = value; + Rockets = _rocketsId.Select(p => new Lazy(() => Context.RocketsEndpoint.Get(p).Execute())).ToList(); + } + } + + [JsonProperty("launches")] + public List LaunchesId + { + get => _launchesId; + set + { + _launchesId = value; + Launches = _launchesId.Select(p => new Lazy(() => Context.LaunchesEndpoint.Get(p).Execute())).ToList(); + } + } + + public List> Rockets { get; private set; } + public List> Launches { get; private set; } + + private List _rocketsId; + private List _launchesId; + + public override string ToString() + { + return Name; + } + } +} diff --git a/Oddity/API/Models/Launchpad/LaunchpadStatus.cs b/Oddity/Models/Launchpads/LaunchpadStatus.cs similarity index 70% rename from Oddity/API/Models/Launchpad/LaunchpadStatus.cs rename to Oddity/Models/Launchpads/LaunchpadStatus.cs index 812ef4a..013882e 100644 --- a/Oddity/API/Models/Launchpad/LaunchpadStatus.cs +++ b/Oddity/Models/Launchpads/LaunchpadStatus.cs @@ -1,11 +1,14 @@ using System.Runtime.Serialization; -namespace Oddity.API.Models.Launchpad +namespace Oddity.Models.Launchpads { public enum LaunchpadStatus { - Retired, + Unknown, Active, + Inactive, + Retired, + Lost, [EnumMember(Value = "under construction")] UnderConstruction diff --git a/Oddity/Models/ModelBase.cs b/Oddity/Models/ModelBase.cs new file mode 100644 index 0000000..06a6802 --- /dev/null +++ b/Oddity/Models/ModelBase.cs @@ -0,0 +1,54 @@ +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace Oddity.Models +{ + /// + /// Represents an abstract class for all models. + /// + public abstract class ModelBase + { + protected OddityCore Context { get; set; } + + /// + /// Sets the Oddity context used in lazy properties. + /// + /// Oddity context. + public void SetContext(OddityCore context) + { + Context = context; + SetContextInNestedObjects(context); + } + + /// + /// Makes a shallow copy of all properties into the target model (remember that it's filled, not instantiated again). + /// + /// Target model which will be filled. + public void CopyTo(ModelBase target) + { + foreach (var property in GetType().GetRuntimeProperties().Where(p => p.CanWrite)) + { + property.SetValue(target, property.GetValue(this, null), null); + } + } + + private void SetContextInNestedObjects(OddityCore context) + { + foreach (var property in GetType().GetRuntimeProperties()) + { + if (property.GetValue(this) is ModelBase underlyingInstance) + { + underlyingInstance.SetContext(context); + } + else if (property.GetValue(this) is IEnumerable collection) + { + foreach (var element in collection) + { + element.SetContext(context); + } + } + } + } + } +} diff --git a/Oddity/Models/PaginatedModel.cs b/Oddity/Models/PaginatedModel.cs new file mode 100644 index 0000000..fbbcdab --- /dev/null +++ b/Oddity/Models/PaginatedModel.cs @@ -0,0 +1,157 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Oddity.Builders; + +namespace Oddity.Models +{ + /// + /// Represents an wrapper for a model, providing methods to manage a pagination. + /// + /// Type of the data returned from API. + public class PaginatedModel where TData : ModelBase, IIdentifiable, new() + { + /// + /// Gets or sets the total number of elements in . + /// + public uint TotalDocs { get; set; } + + /// + /// Gets or sets the offset applied to the query. + /// + public uint Offset { get; set; } + + /// + /// Gets or sets the limit applied to the query. + /// + public uint Limit { get; set; } + + /// + /// Gets or sets the total number of pages. + /// + public uint TotalPages { get; set; } + + /// + /// Gets or sets the current page. + /// + public uint Page { get; set; } + + /// + /// Gets or sets the starting serial number of first document. + /// + public uint PagingCounter { get; set; } + + /// + /// Gets or sets the flag indicating if there is a previous page available to switch. + /// + public bool HasPrevPage { get; set; } + + /// + /// Gets or sets the flag indicating if there is a next page available to switch. + /// + public bool HasNextPage { get; set; } + + /// + /// Gets or sets the previous page number (only if is set to true, otherwise null). + /// + public uint? PrevPage { get; set; } + + /// + /// Gets or sets the next page number (only if is set to true, otherwise null). + /// + public uint? NextPage { get; set; } + + /// + /// Gets or sets the collection of items returned from API for the query filters and parameters. + /// + [JsonProperty("docs")] + public List Data { get; set; } + + private QueryBuilder _builder; + + /// + /// Sets the builder which will be used to change pages. + /// + /// Query builder used for page changes. + public void SetBuilder(QueryBuilder builder) + { + _builder = builder; + } + + /// + /// Changes the page to the specified in the and makes an request to API. + /// + /// True if the page number was valid and has been changed with success, otherwise false. + public async Task GoToNextPage() + { + if (NextPage == null) + { + return false; + } + + Data.Clear(); + _builder.WithPage(NextPage.Value); + + return await _builder.ExecuteAsync(this); + } + + /// + /// Changes the page to the specified in the and makes an request to API. + /// + /// True if the page number was valid and has been changed with success, otherwise false. + public async Task GoToPrevPage() + { + if (PrevPage == null) + { + return false; + } + + Data.Clear(); + _builder.WithPage(PrevPage.Value); + + return await _builder.ExecuteAsync(this); + } + + /// + /// Changes the page to the first and makes an request to API. + /// + /// True if the page number was valid and has been changed with success, otherwise false. + public async Task GoToFirstPage() + { + Data.Clear(); + _builder.WithPage(1); + + return await _builder.ExecuteAsync(this); + } + + /// + /// Changes the page to the specified in the and makes an request to API. + /// + /// True if the page number was valid and has been changed with success, otherwise false. + public async Task GoToLastPage() + { + Data.Clear(); + _builder.WithPage(TotalPages); + + return await _builder.ExecuteAsync(this); + } + + /// + /// Changes the page to the specified in the parameter and makes an request to API. + /// + /// Page number to be set. + /// True if the page number was valid and has been changed with success, otherwise false. + public async Task GoToPage(uint page) + { + if (page > TotalPages) + { + return false; + } + + Data.Clear(); + _builder.WithPage(page); + + return await _builder.ExecuteAsync(this); + } + } +} diff --git a/Oddity/Models/Payloads/PayloadDragonInfo.cs b/Oddity/Models/Payloads/PayloadDragonInfo.cs new file mode 100644 index 0000000..d45c6dd --- /dev/null +++ b/Oddity/Models/Payloads/PayloadDragonInfo.cs @@ -0,0 +1,41 @@ +using System; +using Newtonsoft.Json; +using Oddity.Models.Capsules; + +namespace Oddity.Models.Payloads +{ + public class PayloadDragonInfo : ModelBase + { + public string Manifest { get; set; } + + [JsonProperty("mass_returned_kg")] + public double? MassReturnedKilograms { get; set; } + + [JsonProperty("mass_returned_lbs")] + public double? MassReturnedPounds { get; set; } + + [JsonProperty("flight_time_sec")] + public uint? FlightTimeSeconds { get; set; } + + [JsonProperty("water_landing")] + public bool? WaterLanding { get; set; } + + [JsonProperty("land_landing")] + public bool? LandLanding { get; set; } + + [JsonProperty("capsule")] + public string CapsuleId + { + get => _capsuleId; + set + { + _capsuleId = value; + Capsule = new Lazy(() => Context.CapsulesEndpoint.Get(_capsuleId).Execute()); + } + } + + public Lazy Capsule { get; private set; } + + private string _capsuleId; + } +} diff --git a/Oddity/Models/Payloads/PayloadInfo.cs b/Oddity/Models/Payloads/PayloadInfo.cs new file mode 100644 index 0000000..f44f0a3 --- /dev/null +++ b/Oddity/Models/Payloads/PayloadInfo.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using Newtonsoft.Json; +using Oddity.Models.Launches; + +namespace Oddity.Models.Payloads +{ + public class PayloadInfo : ModelBase, IIdentifiable + { + public string Id { get; set; } + public string Name { get; set; } + public string Type { get; set; } + public bool? Reused { get; set; } + public string Orbit { get; set; } + public string Regime { get; set; } + public double? Longitude { get; set; } + public double? Eccentricity { get; set; } + public DateTime? Epoch { get; set; } + public double? Raan { get; set; } + + public List Customers { get; set; } + public List Nationalities { get; set; } + public List Manufacturers { get; set; } + public PayloadDragonInfo Dragon { get; set; } + + [JsonProperty("norad_ids")] + public List NoradIds { get; set; } + + [JsonProperty("mass_kg")] + public double? MassKilograms { get; set; } + + [JsonProperty("mass_lbs")] + public double? MassPounds { get; set; } + + [JsonProperty("reference_system")] + public string ReferenceSystem { get; set; } + + [JsonProperty("semi_major_axis_km")] + public double? SemiMajorAxisKilometers { get; set; } + + [JsonProperty("periapsis_km")] + public double? PeriapsisKilometers { get; set; } + + [JsonProperty("apoapsis_km")] + public double? ApoapsisKilometers { get; set; } + + [JsonProperty("inclination_deg")] + public double? InclinationDegrees { get; set; } + + [JsonProperty("period_min")] + public double? PeriodMinutes { get; set; } + + [JsonProperty("lifespan_years")] + public uint? LifespanYears { get; set; } + + [JsonProperty("mean_motion")] + public double? MeanMotion { get; set; } + + [JsonProperty("arg_of_pericenter")] + public double? ArgOfPericenter { get; set; } + + [JsonProperty("mean_anomaly")] + public double? MeanAnomaly { get; set; } + + [JsonProperty("launch")] + public string LaunchId + { + get => _launchId; + set + { + _launchId = value; + Launch = new Lazy(() => Context.LaunchesEndpoint.Get(_launchId).Execute()); + } + } + + public Lazy Launch { get; private set; } + + private string _launchId; + + public override string ToString() + { + return Name; + } + } +} diff --git a/Oddity/Models/Query/Filters/BetweenFilter.cs b/Oddity/Models/Query/Filters/BetweenFilter.cs new file mode 100644 index 0000000..44817b5 --- /dev/null +++ b/Oddity/Models/Query/Filters/BetweenFilter.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; + +namespace Oddity.Models.Query.Filters +{ + public class BetweenFilter + { + [JsonProperty("$gt")] + public TData From { get; set; } + + [JsonProperty("$lt")] + public TData To { get; set; } + + public BetweenFilter(TData from, TData to) + { + From = from; + To = to; + } + } +} diff --git a/Oddity/Models/Query/Filters/GreaterThanFilter.cs b/Oddity/Models/Query/Filters/GreaterThanFilter.cs new file mode 100644 index 0000000..ae228c2 --- /dev/null +++ b/Oddity/Models/Query/Filters/GreaterThanFilter.cs @@ -0,0 +1,15 @@ +using Newtonsoft.Json; + +namespace Oddity.Models.Query.Filters +{ + public class GreaterThanFilter + { + [JsonProperty("$gt")] + public TData GreaterThanValue { get; set; } + + public GreaterThanFilter(TData greaterThanValue) + { + GreaterThanValue = greaterThanValue; + } + } +} \ No newline at end of file diff --git a/Oddity/Models/Query/Filters/InFilter.cs b/Oddity/Models/Query/Filters/InFilter.cs new file mode 100644 index 0000000..8a46343 --- /dev/null +++ b/Oddity/Models/Query/Filters/InFilter.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using System.Linq; +using Newtonsoft.Json; + +namespace Oddity.Models.Query.Filters +{ + public class InFilter + { + [JsonProperty("$in")] + public List Values { get; set; } + + public InFilter(params TData[] values) + { + Values = values.ToList(); + } + } +} \ No newline at end of file diff --git a/Oddity/Models/Query/Filters/LessThanFilter.cs b/Oddity/Models/Query/Filters/LessThanFilter.cs new file mode 100644 index 0000000..75d9b57 --- /dev/null +++ b/Oddity/Models/Query/Filters/LessThanFilter.cs @@ -0,0 +1,15 @@ +using Newtonsoft.Json; + +namespace Oddity.Models.Query.Filters +{ + public class LessThanFilter + { + [JsonProperty("$lt")] + public TData LessThanValue { get; set; } + + public LessThanFilter(TData lessThanValue) + { + LessThanValue = lessThanValue; + } + } +} \ No newline at end of file diff --git a/Oddity/Models/Query/QueryModel.cs b/Oddity/Models/Query/QueryModel.cs new file mode 100644 index 0000000..a5a8e68 --- /dev/null +++ b/Oddity/Models/Query/QueryModel.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Oddity.Models.Query +{ + public class QueryModel + { + [JsonProperty("query")] + public Dictionary Filters { get; set; } + + [JsonProperty("options")] + public QueryOptions Options { get; set; } + + public QueryModel() + { + Filters = new Dictionary(); + Options = new QueryOptions(); + } + } +} diff --git a/Oddity/Models/Query/QueryOptions.cs b/Oddity/Models/Query/QueryOptions.cs new file mode 100644 index 0000000..10bd9e8 --- /dev/null +++ b/Oddity/Models/Query/QueryOptions.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Oddity.Models.Query +{ + public class QueryOptions + { + [JsonProperty("sort", DefaultValueHandling = DefaultValueHandling.Ignore)] + public Dictionary Sort { get; set; } + + [JsonProperty("offset", DefaultValueHandling = DefaultValueHandling.Ignore)] + public uint? Offset { get; set; } + + [JsonProperty("page", DefaultValueHandling = DefaultValueHandling.Ignore)] + public uint? Page { get; set; } + + [JsonProperty("limit", DefaultValueHandling = DefaultValueHandling.Ignore)] + public uint? Limit { get; set; } + } +} diff --git a/Oddity/Models/Query/SortMode.cs b/Oddity/Models/Query/SortMode.cs new file mode 100644 index 0000000..c74d862 --- /dev/null +++ b/Oddity/Models/Query/SortMode.cs @@ -0,0 +1,15 @@ +using System.Runtime.Serialization; + +namespace Oddity.Models.Query +{ + public enum SortMode + { + Undefined = 0, + + [EnumMember(Value = "asc")] + Ascending = 1, + + [EnumMember(Value = "desc")] + Descending = -1 + } +} \ No newline at end of file diff --git a/Oddity/API/Models/Roadster/RoadsterInfo.cs b/Oddity/Models/Roadster/RoadsterInfo.cs similarity index 78% rename from Oddity/API/Models/Roadster/RoadsterInfo.cs rename to Oddity/Models/Roadster/RoadsterInfo.cs index f6ce1bc..b6fa45d 100644 --- a/Oddity/API/Models/Roadster/RoadsterInfo.cs +++ b/Oddity/Models/Roadster/RoadsterInfo.cs @@ -1,11 +1,19 @@ using System; +using System.Collections.Generic; using Newtonsoft.Json; -namespace Oddity.API.Models.Roadster +namespace Oddity.Models.Roadster { - public class RoadsterInfo + public class RoadsterInfo : ModelBase, IIdentifiable { + public string Id { get; set; } public string Name { get; set; } + public double? Eccentricity { get; set; } + public double? Inclination { get; set; } + public double? Longitude { get; set; } + public string Wikipedia { get; set; } + public string Video { get; set; } + public string Details { get; set; } [JsonProperty("launch_date_utc")] public DateTime? DateTimeUtc { get; set; } @@ -14,10 +22,10 @@ public class RoadsterInfo public ulong? DateTimeUnix { get; set; } [JsonProperty("launch_mass_kg")] - public uint? LaunchMassKilograms { get; set; } + public double? LaunchMassKilograms { get; set; } [JsonProperty("launch_mass_lbs")] - public uint? LaunchMassPounds { get; set; } + public double? LaunchMassPounds { get; set; } [JsonProperty("norad_id")] public uint? NoradId { get; set; } @@ -37,10 +45,6 @@ public class RoadsterInfo [JsonProperty("semi_major_axis_au")] public double? SemiMajorAxisAu { get; set; } - public double? Eccentricity { get; set; } - public double? Inclination { get; set; } - public double? Longitude { get; set; } - [JsonProperty("periapsis_arg")] public double? PeriapsisArg { get; set; } @@ -65,7 +69,12 @@ public class RoadsterInfo [JsonProperty("mars_distance_mi")] public double? MarsDistanceMiles { get; set; } - public string Wikipedia { get; set; } - public string Details { get; set; } + [JsonProperty("flickr_images")] + public List FlickrImages { get; set; } + + public override string ToString() + { + return Name; + } } -} \ No newline at end of file +} diff --git a/Oddity/API/Models/Rocket/Engines/EnginesInfo.cs b/Oddity/Models/Rockets/RocketEnginesInfo.cs similarity index 79% rename from Oddity/API/Models/Rocket/Engines/EnginesInfo.cs rename to Oddity/Models/Rockets/RocketEnginesInfo.cs index b51e37c..a4ecb75 100644 --- a/Oddity/API/Models/Rocket/Engines/EnginesInfo.cs +++ b/Oddity/Models/Rockets/RocketEnginesInfo.cs @@ -1,15 +1,23 @@ using Newtonsoft.Json; -using Oddity.API.Models.Common; +using Oddity.Models.Common; -namespace Oddity.API.Models.Rocket.Engines +namespace Oddity.Models.Rockets { - public class EnginesInfo + public class RocketEnginesInfo : ModelBase { public uint? Number { get; set; } - public EngineType? Type { get; set; } + public string Type { get; set; } public string Version { get; set; } public string Layout { get; set; } + public IspInfo Isp { get; set; } + + [JsonProperty("thrust_sea_level")] + public ThrustInfo ThrustSeaLevel { get; set; } + + [JsonProperty("thrust_vacuum")] + public ThrustInfo ThrustVacuum { get; set; } + [JsonProperty("engine_loss_max")] public uint? EngineLossMax { get; set; } @@ -19,12 +27,6 @@ public class EnginesInfo [JsonProperty("propellant_2")] public string SecondPropellant { get; set; } - [JsonProperty("thrust_sea_level")] - public ThrustInfo ThrustSeaLevel { get; set; } - - [JsonProperty("thrust_vacuum")] - public ThrustInfo ThrustVacuum { get; set; } - [JsonProperty("thrust_to_weight")] public double? ThrustToWeight { get; set; } } diff --git a/Oddity/Models/Rockets/RocketFairingInfo.cs b/Oddity/Models/Rockets/RocketFairingInfo.cs new file mode 100644 index 0000000..c52db07 --- /dev/null +++ b/Oddity/Models/Rockets/RocketFairingInfo.cs @@ -0,0 +1,10 @@ +using Oddity.Models.Common; + +namespace Oddity.Models.Rockets +{ + public class RocketFairingInfo : ModelBase + { + public SizeInfo Height { get; set; } + public SizeInfo Diameter { get; set; } + } +} diff --git a/Oddity/API/Models/Rocket/Stages/FirstStageInfo.cs b/Oddity/Models/Rockets/RocketFirstStageInfo.cs similarity index 58% rename from Oddity/API/Models/Rocket/Stages/FirstStageInfo.cs rename to Oddity/Models/Rockets/RocketFirstStageInfo.cs index d8f0876..e685075 100644 --- a/Oddity/API/Models/Rocket/Stages/FirstStageInfo.cs +++ b/Oddity/Models/Rockets/RocketFirstStageInfo.cs @@ -1,23 +1,23 @@ using Newtonsoft.Json; -using Oddity.API.Models.Common; +using Oddity.Models.Common; -namespace Oddity.API.Models.Rocket.Stages +namespace Oddity.Models.Rockets { - public class FirstStageInfo + public class RocketFirstStageInfo : ModelBase { public bool? Reusable { get; set; } - public int? Engines { get; set; } - - [JsonProperty("fuel_amount_tons")] - public double? FuelAmountTons { get; set; } - - [JsonProperty("burn_time_sec")] - public int? BurnTimeSeconds { get; set; } + public uint? Engines { get; set; } [JsonProperty("thrust_sea_level")] public ThrustInfo ThrustSeaLevel { get; set; } [JsonProperty("thrust_vacuum")] public ThrustInfo ThrustVacuum { get; set; } + + [JsonProperty("fuel_amount_tons")] + public uint? FuelAmountTons { get; set; } + + [JsonProperty("burn_time_sec")] + public uint? BurnTimeSeconds { get; set; } } } diff --git a/Oddity/API/Models/Rocket/RocketInfo.cs b/Oddity/Models/Rockets/RocketInfo.cs similarity index 59% rename from Oddity/API/Models/Rocket/RocketInfo.cs rename to Oddity/Models/Rockets/RocketInfo.cs index a2f8152..272f79f 100644 --- a/Oddity/API/Models/Rocket/RocketInfo.cs +++ b/Oddity/Models/Rockets/RocketInfo.cs @@ -1,23 +1,27 @@ using System; using System.Collections.Generic; using Newtonsoft.Json; -using Oddity.API.Models.Common; -using Oddity.API.Models.Rocket.Engines; -using Oddity.API.Models.Rocket.LandingLegs; -using Oddity.API.Models.Rocket.PayloadWeights; -using Oddity.API.Models.Rocket.Stages; +using Oddity.Models.Common; -namespace Oddity.API.Models.Rocket +namespace Oddity.Models.Rockets { - public class RocketInfo + public class RocketInfo : ModelBase, IIdentifiable { - public RocketId? Id { get; set; } - + public string Id { get; set; } public string Name { get; set; } + public string Type { get; set; } public bool? Active { get; set; } - public uint? Stages { get; set; } public uint? Boosters { get; set; } + public string Country { get; set; } + public string Company { get; set; } + public string Wikipedia { get; set; } + public string Description { get; set; } + + public SizeInfo Height { get; set; } + public SizeInfo Diameter { get; set; } + public MassInfo Mass { get; set; } + public RocketEnginesInfo Engines { get; set; } [JsonProperty("cost_per_launch")] public uint? CostPerLaunch { get; set; } @@ -28,26 +32,24 @@ public class RocketInfo [JsonProperty("first_flight")] public DateTime? FirstFlight { get; set; } - public string Country { get; set; } - public string Company { get; set; } - public SizeInfo Height { get; set; } - public SizeInfo Diameter { get; set; } - public MassInfo Mass { get; set; } - - [JsonProperty("payload_weights")] - public List PayloadWeights { get; set; } - [JsonProperty("first_stage")] - public FirstStageInfo FirstStage { get; set; } + public RocketFirstStageInfo FirstStage { get; set; } [JsonProperty("second_stage")] public SecondStageInfo SecondStage { get; set; } - public EnginesInfo Engines { get; set; } - [JsonProperty("landing_legs")] - public LandingLegsInfo LandingLegs { get; set; } + public RocketLandingLegsInfo LandingLegs { get; set; } - public string Description { get; set; } + [JsonProperty("payload_weights")] + public List PayloadWeights { get; set; } + + [JsonProperty("flickr_images")] + public List FlickrImages { get; set; } + + public override string ToString() + { + return Name; + } } } diff --git a/Oddity/Models/Rockets/RocketLandingLegsInfo.cs b/Oddity/Models/Rockets/RocketLandingLegsInfo.cs new file mode 100644 index 0000000..8dd9a83 --- /dev/null +++ b/Oddity/Models/Rockets/RocketLandingLegsInfo.cs @@ -0,0 +1,8 @@ +namespace Oddity.Models.Rockets +{ + public class RocketLandingLegsInfo : ModelBase + { + public uint? Number { get; set; } + public string Material { get; set; } + } +} diff --git a/Oddity/Models/Rockets/RocketPotentialPayloadInfo.cs b/Oddity/Models/Rockets/RocketPotentialPayloadInfo.cs new file mode 100644 index 0000000..5cac7b1 --- /dev/null +++ b/Oddity/Models/Rockets/RocketPotentialPayloadInfo.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; + +namespace Oddity.Models.Rockets +{ + public class RocketPotentialPayloadInfo : ModelBase + { + [JsonProperty("composite_fairing")] + public RocketFairingInfo Fairing { get; set; } + + [JsonProperty("option_1")] + public string Option { get; set; } + } +} diff --git a/Oddity/API/Models/Common/MassInfo.cs b/Oddity/Models/Rockets/RocketPotentialPayloadWeightInfo.cs similarity index 52% rename from Oddity/API/Models/Common/MassInfo.cs rename to Oddity/Models/Rockets/RocketPotentialPayloadWeightInfo.cs index e69b9d9..05448ef 100644 --- a/Oddity/API/Models/Common/MassInfo.cs +++ b/Oddity/Models/Rockets/RocketPotentialPayloadWeightInfo.cs @@ -1,9 +1,12 @@ using Newtonsoft.Json; -namespace Oddity.API.Models.Common +namespace Oddity.Models.Rockets { - public class MassInfo + public class RocketPotentialPayloadWeightInfo : ModelBase { + public string Id { get; set; } + public string Name { get; set; } + [JsonProperty("kg")] public double? Kilograms { get; set; } diff --git a/Oddity/API/Models/Rocket/Stages/SecondStageInfo.cs b/Oddity/Models/Rockets/SecondStageInfo.cs similarity index 59% rename from Oddity/API/Models/Rocket/Stages/SecondStageInfo.cs rename to Oddity/Models/Rockets/SecondStageInfo.cs index 8c23421..2956950 100644 --- a/Oddity/API/Models/Rocket/Stages/SecondStageInfo.cs +++ b/Oddity/Models/Rockets/SecondStageInfo.cs @@ -1,20 +1,20 @@ using Newtonsoft.Json; -using Oddity.API.Models.Common; -using Oddity.API.Models.Rocket.Stages.Payloads; +using Oddity.Models.Common; -namespace Oddity.API.Models.Rocket.Stages +namespace Oddity.Models.Rockets { - public class SecondStageInfo + public class SecondStageInfo : ModelBase { + public bool? Reusable { get; set; } public uint? Engines { get; set; } + public ThrustInfo Thrust { get; set; } + public RocketPotentialPayloadInfo Payloads { get; set; } + [JsonProperty("fuel_amount_tons")] public uint? FuelAmountTons { get; set; } [JsonProperty("burn_time_sec")] public uint? BurnTimeSeconds { get; set; } - - public ThrustInfo Thrust { get; set; } - public PayloadInfo Payloads { get; set; } } } diff --git a/Oddity/Models/Ships/ShipInfo.cs b/Oddity/Models/Ships/ShipInfo.cs new file mode 100644 index 0000000..60382cc --- /dev/null +++ b/Oddity/Models/Ships/ShipInfo.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Newtonsoft.Json; +using Oddity.Models.Launches; + +namespace Oddity.Models.Ships +{ + public class ShipInfo : ModelBase, IIdentifiable + { + public string Id { get; set; } + public string Name { get; set; } + public bool? Active { get; set; } + public string Model { get; set; } + public string Type { get; set; } + public uint? Imo { get; set; } + public uint? Mmsi { get; set; } + public uint? Abs { get; set; } + public uint? Class { get; set; } + public string Status { get; set; } + public double? Latitude { get; set; } + public double? Longitude { get; set; } + public string Link { get; set; } + public string Image { get; set; } + + public List Roles { get; set; } + + [JsonProperty("legacy_id")] + public string LegacyId { get; set; } + + [JsonProperty("mass_kg")] + public double? MassKilograms { get; set; } + + [JsonProperty("mass_lbs")] + public double? MassPounds { get; set; } + + [JsonProperty("year_built")] + public uint? YearBuilt { get; set; } + + [JsonProperty("home_port")] + public string HomePort { get; set; } + + [JsonProperty("speed_kn")] + public double? SpeedKnots { get; set; } + + [JsonProperty("course_deg")] + public double? CourseDegrees { get; set; } + + [JsonProperty("last_ais_update")] + public DateTime? LastAisUpdate { get; set; } + + [JsonProperty("launches")] + public List LaunchesId + { + get => _launchesId; + set + { + _launchesId = value; + Launches = _launchesId.Select(p => new Lazy(() => Context.LaunchesEndpoint.Get(p).Execute())).ToList(); + } + } + + public List> Launches { get; private set; } + + private List _launchesId; + + public override string ToString() + { + return Name; + } + } +} diff --git a/Oddity/Models/Starlink/StarlinkInfo.cs b/Oddity/Models/Starlink/StarlinkInfo.cs new file mode 100644 index 0000000..a4c18c5 --- /dev/null +++ b/Oddity/Models/Starlink/StarlinkInfo.cs @@ -0,0 +1,48 @@ +using System; +using Newtonsoft.Json; +using Oddity.Models.Common; +using Oddity.Models.Launches; + +namespace Oddity.Models.Starlink +{ + public class StarlinkInfo : ModelBase, IIdentifiable + { + public string Id { get; set; } + public string Version { get; set; } + + [JsonProperty("spaceTrack")] + public SpaceTrackInfo SpaceTrack { get; set; } + + [JsonProperty("latitude")] + public double? Latitude { get; set; } + + [JsonProperty("longitude")] + public double? Longitude { get; set; } + + [JsonProperty("height_km")] + public double? HeightKilometers { get; set; } + + [JsonProperty("velocity_kms")] + public double? VelocityKilometersPerSecond { get; set; } + + [JsonProperty("launch")] + public string LaunchId + { + get => _launchId; + set + { + _launchId = value; + Launch = new Lazy(() => Context.LaunchesEndpoint.Get(_launchId).Execute()); + } + } + + public Lazy Launch { get; private set; } + + private string _launchId; + + public override string ToString() + { + return SpaceTrack.ObjectName; + } + } +} diff --git a/Oddity/Oddity.csproj b/Oddity/Oddity.csproj index 5ed63fc..c75ac2f 100644 --- a/Oddity/Oddity.csproj +++ b/Oddity/Oddity.csproj @@ -3,41 +3,49 @@ netstandard1.1 Tearth - https://github.com/Tearth/Oddity/blob/master/LICENSE https://github.com/Tearth/Oddity https://github.com/Tearth/Oddity oddity spacex api wrapper dotnet .net csharp dotnetstandard .netstandard standard core framework - * 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 - SpaceX API wrapper for .NET based on the https://github.com/r-spacex/SpaceX-API project. + * 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 + .NET wrapper for unofficial SpaceX API v4 (with full support for all endpoints and query subsystem), providing information about everyting related to the company. Tearth 2020 true - false + true - 1.0.13.0 - 1.0.13.0 - 1.0.13 + 2.0.0.0 + 2.0.0.0 + 2.0.0 - https://raw.githubusercontent.com/Tearth/Oddity/develop/icon.png git + MIT + icon.png bin\Debug\netstandard1.1\Oddity.xml 1701;1702;1705;1591 + 7.3 bin\Release\netstandard1.1\Oddity.xml 1701;1702;1705;1591 + 7.3 + + + True + + + + diff --git a/Oddity/OddityCore.cs b/Oddity/OddityCore.cs index 983a5d0..75a4a6b 100644 --- a/Oddity/OddityCore.cs +++ b/Oddity/OddityCore.cs @@ -2,65 +2,117 @@ using System.Net.Http; using System.Reflection; using Newtonsoft.Json.Serialization; -using Oddity.API; -using Oddity.API.Builders; +using Oddity.Configuration; +using Oddity.Endpoints; +using Oddity.Events; +using Oddity.Models.Capsules; +using Oddity.Models.Company; +using Oddity.Models.Cores; +using Oddity.Models.Crew; +using Oddity.Models.Dragon; +using Oddity.Models.Landpads; +using Oddity.Models.Launches; +using Oddity.Models.Launchpads; +using Oddity.Models.Payloads; +using Oddity.Models.Roadster; +using Oddity.Models.Rockets; +using Oddity.Models.Ships; +using Oddity.Models.Starlink; namespace Oddity { /// - /// Represents an core of the library. Use it to retrieve data from the SpaceX API. + /// Represents an core of the library. Use it to retrieve data from the unofficial SpaceX API. /// public class OddityCore : IDisposable { + public bool CacheEnabled { get; set; } + + /// + /// Gets the entry point of the /capsules endpoint. + /// + public CapsulesEndpoint CapsulesEndpoint { get; } + + /// + /// Gets the entry point of the /company endpoint. + /// + public CompanyEndpoint CompanyEndpoint { get; } + + /// + /// Gets the entry point of the /cores endpoint. + /// + public CoresEndpoint CoresEndpoint { get; } + + /// + /// Gets the entry point of the /crew endpoint. + /// + public CrewEndpoint CrewEndpoint { get; } + + /// + /// Gets the entry point of the /dragons endpoint. + /// + public DragonsEndpoint DragonsEndpoint { get; } + /// - /// Gets the API information. + /// Gets the entry point of the /landpads endpoint. /// - public Api Api { get; } + public LandpadsEndpoint LandpadsEndpoint { get; } /// - /// Gets the company information. + /// Gets the entry point of the /launches endpoint. /// - public Company Company { get; } + public LaunchesEndpoint LaunchesEndpoint { get; } /// - /// Gets the company history. + /// Gets the entry point of the /launchpads endpoint. /// - public History History { get; } + public LaunchpadsEndpoint LaunchpadsEndpoint { get; } /// - /// Gets the rockets information. + /// Gets the entry point of the /payloads endpoint. /// - public Rockets Rockets { get; } + public PayloadsEndpoint PayloadsEndpoint { get; } /// - /// Gets the capsules information. + /// Gets the entry point of the /roadster endpoint. /// - public Dragons Dragons { get; } + public RoadsterEndpoint RoadsterEndpoint { get; } /// - /// Gets the capsules information. + /// Gets the entry point of the /rockets endpoint. /// - public Capsules Capsules { get; } + public RocketsEndpoint RocketsEndpoint { get; } /// - /// Gets the core information. + /// Gets the entry point of the /ships endpoint. /// - public Cores Cores { get; } + public ShipsEndpoint ShipsEndpoint { get; } /// - /// Gets the launchpads information. + /// Gets the entry point of the /starlink endpoint. /// - public Launchpads Launchpads { get; } + public StarlinkEndpoint StarlinkEndpoint { get; } /// - /// Gets the launches information. + /// Gets or sets the HTTP timeout when making requests to API. /// - public Launches Launches { get; } + public TimeSpan Timeout + { + get => HttpClient.Timeout; + set => HttpClient.Timeout = value; + } + + /// + /// Gets the user agent used when making requests to API. + /// + public string UserAgent => $"{LibraryConfiguration.LibraryName}/{Version} ({LibraryConfiguration.GitHubLink})"; /// - /// Gets the Tesla Roadster information. + /// Gets the library version used in user agent when making requests to API. /// - public Roadster Roadster { get; } + public string Version => GetType().GetTypeInfo().Assembly + .GetCustomAttribute() + .InformationalVersion; /// /// Event triggered when an error occurred during JSON deserialization. @@ -77,60 +129,48 @@ public class OddityCore : IDisposable /// public event EventHandler OnResponseReceive; - private readonly HttpClient _httpClient; + protected internal readonly HttpClient HttpClient; + protected internal readonly BuilderDelegates BuilderDelegates; /// /// Initializes a new instance of the class. /// - public OddityCore() + public OddityCore(bool cacheEnabled = true) { - _httpClient = new HttpClient(); - _httpClient.BaseAddress = new Uri(ApiConfiguration.ApiEndpoint); - _httpClient.DefaultRequestHeaders.UserAgent.ParseAdd($"{ApiConfiguration.LibraryName}/{GetLibraryVersion()} ({ApiConfiguration.GitHubLink})"); + CacheEnabled = cacheEnabled; + + HttpClient = new HttpClient(); + HttpClient.BaseAddress = new Uri(ApiConfiguration.ApiEndpoint); + HttpClient.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent); - SetTimeout(ApiConfiguration.DefaultTimeoutSeconds); + Timeout = new TimeSpan(0, 0, ApiConfiguration.DefaultTimeoutSeconds); - var builderDelegatesContainer = new BuilderDelegatesContainer + BuilderDelegates = new BuilderDelegates { DeserializationError = DeserializationError, RequestSend = RequestSend, ResponseReceived = ResponseReceived }; - Api = new Api(_httpClient, builderDelegatesContainer); - Company = new Company(_httpClient, builderDelegatesContainer); - History = new History(_httpClient, builderDelegatesContainer); - Rockets = new Rockets(_httpClient, builderDelegatesContainer); - Dragons = new Dragons(_httpClient, builderDelegatesContainer); - Capsules = new Capsules(_httpClient, builderDelegatesContainer); - Cores = new Cores(_httpClient, builderDelegatesContainer); - Launchpads = new Launchpads(_httpClient, builderDelegatesContainer); - Launches = new Launches(_httpClient, builderDelegatesContainer); - Roadster = new Roadster(_httpClient, builderDelegatesContainer); - } - - /// - /// Sets the timeout for all API requests. - /// - /// Timeout in seconds. - public void SetTimeout(int timeoutSeconds) - { - _httpClient.Timeout = new TimeSpan(0, 0, 0, timeoutSeconds); - } - - /// - /// Gets the current version of library. - /// - /// The library version. - public string GetLibraryVersion() - { - return GetType().GetTypeInfo().Assembly.GetCustomAttribute().InformationalVersion; + CapsulesEndpoint = new CapsulesEndpoint(this); + CompanyEndpoint = new CompanyEndpoint(this); + CoresEndpoint = new CoresEndpoint(this); + CrewEndpoint = new CrewEndpoint(this); + DragonsEndpoint = new DragonsEndpoint(this); + LandpadsEndpoint = new LandpadsEndpoint(this); + LaunchesEndpoint = new LaunchesEndpoint(this); + LaunchpadsEndpoint = new LaunchpadsEndpoint(this); + PayloadsEndpoint = new PayloadsEndpoint(this); + RoadsterEndpoint = new RoadsterEndpoint(this); + RocketsEndpoint = new RocketsEndpoint(this); + ShipsEndpoint = new ShipsEndpoint(this); + StarlinkEndpoint = new StarlinkEndpoint(this); } /// public void Dispose() { - _httpClient?.Dispose(); + HttpClient?.Dispose(); } private void DeserializationError(ErrorEventArgs args) diff --git a/README.md b/README.md index 0f4ba34..fc58b48 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -# Oddity +[![Oddity logo](./logo.png)](https://github.com/Tearth/Oddity) + [![GitHub release](https://img.shields.io/github/release/Tearth/Oddity.svg)](https://github.com/Tearth/Oddity/releases) [![Build](https://api.travis-ci.org/Tearth/Oddity.svg?branch=master)](https://travis-ci.org/Tearth/Oddity) [![NuGet downloads](https://img.shields.io/nuget/dt/Oddity.svg)](https://www.nuget.org/packages/Oddity/) @@ -7,21 +8,34 @@ [![GitHub license](https://img.shields.io/github/license/Tearth/Oddity.svg)](https://github.com/Tearth/Oddity/blob/master/LICENSE) [![Doxygen](https://img.shields.io/badge/Doxygen-gh--pages-blue)](https://tearth.github.io/Oddity/) -.NET SpaceX API wrapper for https://github.com/r-spacex/SpaceX-API project, providing information about company, rockets and launches. To learn more, you can use [Doxygen](https://tearth.github.io/Oddity/) or directly documentation of the API (method names are very familiar with endpoints): +.NET wrapper for **[unofficial SpaceX API v4](https://github.com/r-spacex/SpaceX-API)** (with full support for all endpoints and query subsystem), providing information about everyting related to the company. Thanks to this library, you can easily get any data without messing with HTTP requests, JSON deserializators or constructing query bodies. You can use the following endpoints: + + - **Capsules** - detailed information about Dragon capsules. + - **Company** - detailed information about SpaceX as a company. + - **Cores** - detalied information about first stage cores. + - **Crew** - detailed information about Dragon crew members. + - **Dragons** - detailed information about Dragon capsule versions. + - **Landpads** - detailed information about landing pads and ships. + - **Launches** - detailed information about launches. + - **Launchpads** - detailed information about launchpads. + - **Payloads** - detailed information about launch payloads. + - **Roadster** - detailed information about Elon's Tesla Roadster. + - **Rockets** - detailed information about rocket versions. + - **Ships** - detailed information about ships in the SpaceX fleet. + - **Starlink** - detailed information about Starlink satellites and orbits. -https://docs.spacexdata.com/ +To learn how to use this library, look at this set of examples: -**WARNING: v1.0.13 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** + - **[OverviewApp](/Examples/OverviewApp)** - a test of all endpoints, lazy properties and cache. It's not a real app that does anything useful but allows us to introduce into library architecture. + - **[UpcomingLaunchesApp](/Examples/UpcomingLaunchesApp)** - displays upcoming launches and the most important information about the next launch. + - **[StarlinkApp](/Examples/StarlinkApp)** - displays sample Starlink statistics: the lowest perigee, the highest apogee, the lowest velocity, the highest velocity. -**Available data overview:** - * company data, history with most important events - * detailed information about rockets (Falcon 1, Falcon 9, Falcon Heavy, BFR) and capsules (Dragon 1, Dragon 2, crew Dragon) - * launchpads data - * launches: latest, next, all past, all upcoming - * information about the specified cores and capsules - * Elon's Roadster data +Feel free to make issues or pull request to improve library - Oddity v2 has been rewritten from scratch and it can potentially contain some bugs. -Most of the endpoints contains a lot of filters which are applied on the API side to save bandwidth. Look at the example and [wiki](https://github.com/Tearth/Oddity/wiki) for more information. +# Features + - **smart models** which allow us to retrieve linked models from API using lazy properties. No more manual picking objects using their IDs. + - **support for query subsystem** - v4 API has introduced **[the new query system](https://github.com/r-spacex/SpaceX-API/blob/master/docs/v4/queries.md)** (using **[mongoose-paginate](https://github.com/aravindnc/mongoose-paginate-v2)**) which allows user for more flexible queries. Oddity wraps it with the easy to use classes and provides the most important filters. + - **internal cache** - this is the nice addition to the smart models and their lazy properties - it allows to reduce the time needed for making and processing API requests by caching deserialized objects for a period specified **[in the API docs](https://github.com/r-spacex/SpaceX-API/blob/master/docs/v4/README.md#caching)**. # Minimal requirements Library is built on [.NET Standard 1.1](https://docs.microsoft.com/en-us/dotnet/standard/net-standard) which contains support for: @@ -57,9 +71,7 @@ using System; using System.Threading.Tasks; using Newtonsoft.Json.Serialization; using Oddity; -using Oddity.API.Builders; -using Oddity.API.Models.Launch.Rocket.SecondStage.Orbit; -using Oddity.API.Models.Rocket; +using Oddity.Events; namespace OverviewApp { @@ -74,54 +86,132 @@ namespace OverviewApp oddity.OnRequestSend += Oddity_OnRequestSend; oddity.OnResponseReceive += OddityOnResponseReceive; - // Get company information - var company = await oddity.Company.GetInfo().ExecuteAsync(); - - // Get all history - var history = await oddity.Company.GetHistory().ExecuteAsync(); - - // Get history from the last two years and ordered descending - var historyWithFilter = await oddity.Company.GetHistory() - .WithRange(DateTime.Now.AddYears(-2), DateTime.Now) - .Descending() - .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 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 capsule which has been launched 2015-04-14 at 20:10 - var capsuleWithFilters = await oddity.DetailedCapsules.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.DetailedCores.GetAll().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; @@ -130,6 +220,11 @@ namespace OverviewApp 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) @@ -143,4 +238,7 @@ namespace OverviewApp ``` # Why Oddity? -https://www.youtube.com/watch?v=iYYRH4apXDo \ No newline at end of file +https://www.youtube.com/watch?v=iYYRH4apXDo + +# Credits +
Icon made by Freepik from www.flaticon.com
\ No newline at end of file diff --git a/icon.png b/icon.png index 3cdd770..d4b021b 100644 Binary files a/icon.png and b/icon.png differ diff --git a/logo.png b/logo.png new file mode 100644 index 0000000..7d486d7 Binary files /dev/null and b/logo.png differ