From e120879362ee5ee4bb8c63dd976cd4f3eb3c0916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20B=C4=B1y=C4=B1k?= Date: Sun, 17 Nov 2024 22:18:03 +0300 Subject: [PATCH] Refactoring Dto Class. Added gitignore file --- .gitignore | 245 ++++++++++++++++++++ src/Dto/CreatePaymentDto.cs | 11 + src/Dto/Credentials.cs | 14 ++ src/Dto/IncompleteServerPayments.cs | 12 + src/Dto/Metadata.cs | 16 ++ src/Dto/PaymentArgs.cs | 17 ++ src/Dto/PaymentDto.cs | 47 ++++ src/Dto/PiAuthDto.cs | 14 ++ src/Dto/PiNetworkError.cs | 17 ++ src/Dto/PiUser.cs | 17 ++ src/Dto/PiValidTime.cs | 14 ++ src/Dto/Status.cs | 23 ++ src/Dto/TransactionData.cs | 13 ++ src/Dto/TransactionStatus.cs | 17 ++ src/Dto/Tx.cs | 12 + src/Helpers/Exception/PiNetworkException.cs | 9 + src/PiNetworkClient.cs | 2 + src/PiNetworkData.cs | 192 --------------- 18 files changed, 500 insertions(+), 192 deletions(-) create mode 100644 .gitignore create mode 100644 src/Dto/CreatePaymentDto.cs create mode 100644 src/Dto/Credentials.cs create mode 100644 src/Dto/IncompleteServerPayments.cs create mode 100644 src/Dto/Metadata.cs create mode 100644 src/Dto/PaymentArgs.cs create mode 100644 src/Dto/PaymentDto.cs create mode 100644 src/Dto/PiAuthDto.cs create mode 100644 src/Dto/PiNetworkError.cs create mode 100644 src/Dto/PiUser.cs create mode 100644 src/Dto/PiValidTime.cs create mode 100644 src/Dto/Status.cs create mode 100644 src/Dto/TransactionData.cs create mode 100644 src/Dto/TransactionStatus.cs create mode 100644 src/Dto/Tx.cs create mode 100644 src/Helpers/Exception/PiNetworkException.cs delete mode 100644 src/PiNetworkData.cs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..71cfb1d --- /dev/null +++ b/.gitignore @@ -0,0 +1,245 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +**TrainingData + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +[Xx]64/ +[Xx]86/ +[Bb]uild/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml + +# TODO: Un-comment the next line if you do not want to checkin +# your web deploy settings because they may include unencrypted +# passwords +#*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directory +AppPackages/ +BundleArtifacts/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# LightSwitch generated files +GeneratedArtifacts/ +ModelManifest.xml + +# Paket dependency manager +.paket/paket.exe + +# FAKE - F# Make +.fake/ +/NextVersion/NextVersion.jfm diff --git a/src/Dto/CreatePaymentDto.cs b/src/Dto/CreatePaymentDto.cs new file mode 100644 index 0000000..31ab7cc --- /dev/null +++ b/src/Dto/CreatePaymentDto.cs @@ -0,0 +1,11 @@ +using Newtonsoft.Json; + +namespace PiNetworkNet.src.Dto +{ + [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] + public sealed class CreatePaymentDto + { + [JsonProperty("payment")] + public PaymentArgs Payment; + } +} diff --git a/src/Dto/Credentials.cs b/src/Dto/Credentials.cs new file mode 100644 index 0000000..92e27c0 --- /dev/null +++ b/src/Dto/Credentials.cs @@ -0,0 +1,14 @@ +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace PiNetworkNet.src.Dto +{ + [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] + public sealed class Credentials + { + [JsonProperty("scopes")] + public List Scopes { get; set; } + [JsonProperty("valid_until")] + public PiValidTime ValidTime { get; set; } + }; +} diff --git a/src/Dto/IncompleteServerPayments.cs b/src/Dto/IncompleteServerPayments.cs new file mode 100644 index 0000000..b9431f8 --- /dev/null +++ b/src/Dto/IncompleteServerPayments.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace PiNetworkNet.src.Dto +{ + [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] + public sealed class IncompleteServerPayments + { + [JsonProperty("incomplete_server_payments")] + public List IncompletePayments { get; set; } + } +} diff --git a/src/Dto/Metadata.cs b/src/Dto/Metadata.cs new file mode 100644 index 0000000..08e59d3 --- /dev/null +++ b/src/Dto/Metadata.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; +using System; + +namespace PiNetworkNet.src.Dto +{ + [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] + public sealed class Metadata + { + [JsonProperty("id")] + public Guid? Id { get; set; } + [JsonProperty("cat")] + public string Category { get; set; } + [JsonProperty("data")] + public object Data { get; set; } + } +} diff --git a/src/Dto/PaymentArgs.cs b/src/Dto/PaymentArgs.cs new file mode 100644 index 0000000..68268b0 --- /dev/null +++ b/src/Dto/PaymentArgs.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; + +namespace PiNetworkNet.src.Dto +{ + [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] + public sealed class PaymentArgs + { + [JsonProperty("amount")] + public double Amount; + [JsonProperty("memo")] + public string Memo; + [JsonProperty("metadata")] + public object Metadata; + [JsonProperty("uid")] + public string Uid; + } +} diff --git a/src/Dto/PaymentDto.cs b/src/Dto/PaymentDto.cs new file mode 100644 index 0000000..8b34d76 --- /dev/null +++ b/src/Dto/PaymentDto.cs @@ -0,0 +1,47 @@ +using Newtonsoft.Json; +using System; + +namespace PiNetworkNet.src.Dto +{ + + [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] + public sealed class PaymentDto + { + [JsonProperty("identifier")] + public string Identifier { get; set; } + + [JsonProperty("user_uid")] + public string Useruid { get; set; } + + [JsonProperty("amount")] + public double Amount { get; set; } + + [JsonProperty("memo")] + public string Memo { get; set; } + + [JsonProperty("metadata")] + public Metadata Metadata { get; set; } + + [JsonProperty("from_address")] + public string FromAddress { get; set; } + + [JsonProperty("to_address")] + public string ToAddress { get; set; } + + [JsonProperty("created_at")] + //public string created_at { get; set; } + public DateTimeOffset CreatedAt { get; set; } + + [JsonProperty("direction")] + public string Direction { get; set; } + + [JsonProperty("network")] + public string Network { get; set; } + + [JsonProperty("status")] + public Status Status { get; set; } + + [JsonProperty("transaction")] + public TransactionStatus Transaction { get; set; } + } +} diff --git a/src/Dto/PiAuthDto.cs b/src/Dto/PiAuthDto.cs new file mode 100644 index 0000000..fec55ee --- /dev/null +++ b/src/Dto/PiAuthDto.cs @@ -0,0 +1,14 @@ +using Newtonsoft.Json; + +namespace PiNetworkNet.src.Dto +{ + [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] + public sealed class PiAuthDto + { + [JsonProperty("accessToken")] + public string AccessToken { get; set; } + + [JsonProperty("user")] + public PiUser User { get; set; } + } +} diff --git a/src/Dto/PiNetworkError.cs b/src/Dto/PiNetworkError.cs new file mode 100644 index 0000000..526baff --- /dev/null +++ b/src/Dto/PiNetworkError.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; + +namespace PiNetworkNet.src.Dto +{ + [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] + public sealed class PiNetworkError + { + [JsonProperty("error")] + public string ErrorName { get; set; } + + [JsonProperty("error_message")] + public string ErrorMessage { get; set; } + + [JsonProperty("payment")] + public PaymentDto Payment { get; set; } + } +} diff --git a/src/Dto/PiUser.cs b/src/Dto/PiUser.cs new file mode 100644 index 0000000..e0d3bf6 --- /dev/null +++ b/src/Dto/PiUser.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; + +namespace PiNetworkNet.src.Dto +{ + [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] + public sealed class PiUser + { + [JsonProperty("uid")] + public string Uid { get; set; } + + [JsonProperty("credentials")] + public Credentials Credentials { get; set; } + + [JsonProperty("username")] + public string Username { get; set; } + } +} diff --git a/src/Dto/PiValidTime.cs b/src/Dto/PiValidTime.cs new file mode 100644 index 0000000..e993dd5 --- /dev/null +++ b/src/Dto/PiValidTime.cs @@ -0,0 +1,14 @@ +using Newtonsoft.Json; +using System; + +namespace PiNetworkNet.src.Dto +{ + [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] + public sealed class PiValidTime + { + [JsonProperty("timestamp")] + public long TimeStamp { get; set; } + [JsonProperty("iso8601")] + public DateTimeOffset Iso8601 { get; set; } + } +} diff --git a/src/Dto/Status.cs b/src/Dto/Status.cs new file mode 100644 index 0000000..6dff899 --- /dev/null +++ b/src/Dto/Status.cs @@ -0,0 +1,23 @@ +using Newtonsoft.Json; + +namespace PiNetworkNet.src.Dto +{ + [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] + public sealed class Status + { + [JsonProperty("developer_approved")] + public bool DeveloperApproved { get; set; } + + [JsonProperty("transaction_verified")] + public bool TransactionVerified { get; set; } + + [JsonProperty("developer_completed")] + public bool DeveloperCompleted { get; set; } + + [JsonProperty("cancelled")] + public bool Cancelled { get; set; } + + [JsonProperty("user_cancelled")] + public bool UserCancelled { get; set; } + } +} diff --git a/src/Dto/TransactionData.cs b/src/Dto/TransactionData.cs new file mode 100644 index 0000000..94256d7 --- /dev/null +++ b/src/Dto/TransactionData.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; + +namespace PiNetworkNet.src.Dto +{ + [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] + public sealed class TransactionData + { + public double Amount; + public string Identifier; + public string FromAddress; + public string ToAddress; + } +} diff --git a/src/Dto/TransactionStatus.cs b/src/Dto/TransactionStatus.cs new file mode 100644 index 0000000..c8609c5 --- /dev/null +++ b/src/Dto/TransactionStatus.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; + +namespace PiNetworkNet.src.Dto +{ + [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] + public sealed class TransactionStatus + { + [JsonProperty("txid")] + public string TxId { get; set; } + + [JsonProperty("verified")] + public bool Verified { get; set; } + + [JsonProperty("_link")] + public string Link { get; set; } + } +} diff --git a/src/Dto/Tx.cs b/src/Dto/Tx.cs new file mode 100644 index 0000000..2f8c9b8 --- /dev/null +++ b/src/Dto/Tx.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; + +namespace PiNetworkNet.src.Dto +{ + + [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] + public sealed class Tx + { + [JsonProperty("txid")] + public string TxId { get; set; } + } +} diff --git a/src/Helpers/Exception/PiNetworkException.cs b/src/Helpers/Exception/PiNetworkException.cs new file mode 100644 index 0000000..4511798 --- /dev/null +++ b/src/Helpers/Exception/PiNetworkException.cs @@ -0,0 +1,9 @@ +using PiNetworkNet.src.Dto; + +namespace PiNetworkNet.src.Helpers.Exception +{ + public class PiNetworkException : System.Exception + { + public PiNetworkError PiError { get; set; } + } +} diff --git a/src/PiNetworkClient.cs b/src/PiNetworkClient.cs index 2033d12..cf216eb 100644 --- a/src/PiNetworkClient.cs +++ b/src/PiNetworkClient.cs @@ -6,6 +6,8 @@ using RestSharp; using stellar_dotnet_sdk.responses; using stellar_dotnet_sdk; +using PiNetworkNet.src.Dto; +using PiNetworkNet.src.Helpers.Exception; namespace PiNetworkNet { diff --git a/src/PiNetworkData.cs b/src/PiNetworkData.cs deleted file mode 100644 index 3b95ef1..0000000 --- a/src/PiNetworkData.cs +++ /dev/null @@ -1,192 +0,0 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; - -namespace PiNetworkNet -{ - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class PiAuthDto - { - [JsonProperty("accessToken")] - public string AccessToken { get; set; } - - [JsonProperty("user")] - public PiUser User { get; set; } - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class PiUser - { - [JsonProperty("uid")] - public string Uid { get; set; } - - [JsonProperty("credentials")] - public Credentials Credentials { get; set; } - - [JsonProperty("username")] - public string Username { get; set; } - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class PiValidTime - { - [JsonProperty("timestamp")] - public long TimeStamp { get; set; } - [JsonProperty("iso8601")] - public DateTimeOffset Iso8601 { get; set; } - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class Credentials - { - [JsonProperty("scopes")] - public List Scopes { get; set; } - [JsonProperty("valid_until")] - public PiValidTime ValidTime { get; set; } - }; - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class PaymentDto - { - [JsonProperty("identifier")] - public string Identifier { get; set; } - - [JsonProperty("user_uid")] - public string Useruid { get; set; } - - [JsonProperty("amount")] - public double Amount { get; set; } - - [JsonProperty("memo")] - public string Memo { get; set; } - - [JsonProperty("metadata")] - public Metadata Metadata { get; set; } - - [JsonProperty("from_address")] - public string FromAddress { get; set; } - - [JsonProperty("to_address")] - public string ToAddress { get; set; } - - [JsonProperty("created_at")] - //public string created_at { get; set; } - public DateTimeOffset CreatedAt { get; set; } - - [JsonProperty("direction")] - public string Direction { get; set; } - - [JsonProperty("network")] - public string Network { get; set; } - - [JsonProperty("status")] - public Status Status { get; set; } - - [JsonProperty("transaction")] - public TransactionStatus Transaction { get; set; } - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class Metadata - { - [JsonProperty("id")] - public Guid? Id { get; set; } - [JsonProperty("cat")] - public string Category { get; set; } - [JsonProperty("data")] - public object Data { get; set; } - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class Status - { - [JsonProperty("developer_approved")] - public bool DeveloperApproved { get; set; } - - [JsonProperty("transaction_verified")] - public bool TransactionVerified { get; set; } - - [JsonProperty("developer_completed")] - public bool DeveloperCompleted { get; set; } - - [JsonProperty("cancelled")] - public bool Cancelled { get; set; } - - [JsonProperty("user_cancelled")] - public bool UserCancelled { get; set; } - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class TransactionStatus - { - [JsonProperty("txid")] - public string TxId { get; set; } - - [JsonProperty("verified")] - public bool Verified { get; set; } - - [JsonProperty("_link")] - public string Link { get; set; } - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class Tx - { - [JsonProperty("txid")] - public string TxId { get; set; } - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class IncompleteServerPayments - { - [JsonProperty("incomplete_server_payments")] - public List IncompletePayments { get; set; } - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class PaymentArgs - { - [JsonProperty("amount")] - public double Amount; - [JsonProperty("memo")] - public string Memo; - [JsonProperty("metadata")] - public object Metadata; - [JsonProperty("uid")] - public string Uid; - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class CreatePaymentDto - { - [JsonProperty("payment")] - public PaymentArgs Payment; - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class TransactionData - { - public double Amount; - public string Identifier; - public string FromAddress; - public string ToAddress; - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class PiNetworkError - { - [JsonProperty("error")] - public string ErrorName { get; set; } - - [JsonProperty("error_message")] - public string ErrorMessage { get; set; } - - [JsonProperty("payment")] - public PaymentDto Payment { get; set; } - } - - public class PiNetworkException: Exception - { - public PiNetworkError PiError { get; set; } - } -}