Skip to content

Commit

Permalink
Agregar archivos de proyecto.
Browse files Browse the repository at this point in the history
  • Loading branch information
Biitez committed Apr 29, 2021
1 parent 1ec35f4 commit 5d1cbfd
Show file tree
Hide file tree
Showing 18 changed files with 552 additions and 0 deletions.
25 changes: 25 additions & 0 deletions CryptAPI/CryptAPI.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31129.286
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CryptAPI", "CryptAPI\CryptAPI.csproj", "{69DBF6C4-4331-457E-83FC-975345D12AE3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{69DBF6C4-4331-457E-83FC-975345D12AE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{69DBF6C4-4331-457E-83FC-975345D12AE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{69DBF6C4-4331-457E-83FC-975345D12AE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{69DBF6C4-4331-457E-83FC-975345D12AE3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {708671DE-C3C2-4223-B3F1-69A552161EE4}
EndGlobalSection
EndGlobal
74 changes: 74 additions & 0 deletions CryptAPI/CryptAPI/CryptAPI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using CryptAPI.Enums;
using CryptAPI.Extensions;
using CryptAPI.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web;

namespace CryptAPI
{
public class CryptAPI
{

internal CryptAPISettings CryptAPISettings { get; set; }
internal HttpClient HttpClient { get; set; }

public CryptAPI(CryptAPISettings CryptAPISettings, HttpClient HttpClient = null)
{
this.HttpClient = HttpClient ?? new HttpClient();
this.CryptAPISettings = CryptAPISettings;
}

public string Get_Address()
{

string callback_url = CryptAPISettings.Callback;

if (CryptAPISettings.Parameters != null && CryptAPISettings.Parameters.Count > 0)
callback_url = $"{CryptAPISettings.Callback}{CryptAPISettings.Parameters.HttpBuildQuery()}";

var callback_params = new NameValueCollection()
{
{ "callback", callback_url },
{ "address", CryptAPISettings.Address }
};

if (CryptAPISettings.callback_params != null && CryptAPISettings.callback_params.Count > 0)
callback_params.Add(CryptAPISettings.callback_params);

var responseString = Request(callback_params).Result;

dynamic dyn = JsonConvert.DeserializeObject(responseString);

return dyn.status == "success" ? dyn.address_in : null;

}

private async Task<string> Request(NameValueCollection Params = null)
{

string data = null;

if (Params != null)
data = Params.HttpBuildQuery();

try
{
var ResponseString = await HttpClient.GetStringAsync($"{Globals.BaseURL}/{CryptAPISettings.Coin}/{CryptAPISettings.EndPoint}/{data ?? string.Empty}");

return ResponseString;
}
catch
{
return null;
}
}
}
}
12 changes: 12 additions & 0 deletions CryptAPI/CryptAPI/CryptAPI.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions CryptAPI/CryptAPI/Enums/Coins.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace CryptAPI.Enums
{
public enum Coins
{
btc,
bch,
eth,
ltc,
xmr,
iota
}
}
13 changes: 13 additions & 0 deletions CryptAPI/CryptAPI/Enums/EndPoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace CryptAPI.Enums
{
public enum EndPoint
{
create,
info,
logs
}
}
21 changes: 21 additions & 0 deletions CryptAPI/CryptAPI/Enums/Tokens.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace CryptAPI.Enums
{
public enum Tokens
{
becaz,
bnb,
busd,
cro,
link,
mkr,
nexo,
pax,
tusd,
usdc,
usdt
}
}
23 changes: 23 additions & 0 deletions CryptAPI/CryptAPI/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Web;

namespace CryptAPI.Extensions
{
internal static class StringExtensions
{
internal static string HttpBuildQuery(this NameValueCollection nameValueCollection)
{
var StringArray = (from key in nameValueCollection.AllKeys
from value in nameValueCollection.GetValues(key)
select string.Format(CultureInfo.InvariantCulture, "{0}={1}", HttpUtility.UrlEncode(key), HttpUtility.UrlEncode(value)))
.ToArray();

return "?" + string.Join("&", StringArray);
}
}
}
13 changes: 13 additions & 0 deletions CryptAPI/CryptAPI/Globals.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace CryptAPI
{
public class Globals
{

public const string BaseURL = "https://api.cryptapi.io";

}
}
79 changes: 79 additions & 0 deletions CryptAPI/CryptAPI/Models/CryptAPISettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using CryptAPI.Enums;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;

namespace CryptAPI.Models
{
public class CryptAPISettings
{
private string _Address;
private string _Callback;
private NameValueCollection _Parameters;
private NameValueCollection _callback_params;

public Coins Coin { get; set; }
public EndPoint EndPoint { get; set; }

public string Address
{
get
{
return _Address;
}
set
{
if (string.IsNullOrEmpty(value))
throw new ArgumentNullException();

_Address = value;
}
}

public string Callback
{
get
{
return _Callback;
}
set
{
if (string.IsNullOrEmpty(value))
throw new ArgumentNullException();

_Callback = value;
}
}

public NameValueCollection Parameters
{
get
{
return _Parameters;
}
set
{
if (value == null || value.Count < 1)
throw new ArgumentException();

_Parameters = value;
}
}

public NameValueCollection callback_params
{
get
{
return _callback_params;
}
set
{
if (value == null || value.Count < 1)
throw new ArgumentException();

_callback_params = value;
}
}
}
}
25 changes: 25 additions & 0 deletions back/CryptAPI.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31129.286
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CryptAPI", "CryptAPI\CryptAPI.csproj", "{69DBF6C4-4331-457E-83FC-975345D12AE3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{69DBF6C4-4331-457E-83FC-975345D12AE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{69DBF6C4-4331-457E-83FC-975345D12AE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{69DBF6C4-4331-457E-83FC-975345D12AE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{69DBF6C4-4331-457E-83FC-975345D12AE3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {708671DE-C3C2-4223-B3F1-69A552161EE4}
EndGlobalSection
EndGlobal
74 changes: 74 additions & 0 deletions back/CryptAPI/CryptAPI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using CryptAPI.Enums;
using CryptAPI.Extensions;
using CryptAPI.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web;

namespace CryptAPI
{
public class CryptAPI
{

internal CryptAPISettings CryptAPISettings { get; set; }
internal HttpClient HttpClient { get; set; }

public CryptAPI(CryptAPISettings CryptAPISettings, HttpClient HttpClient = null)
{
this.HttpClient = HttpClient ?? new HttpClient();
this.CryptAPISettings = CryptAPISettings;
}

public string Get_Address()
{

string callback_url = CryptAPISettings.Callback;

if (CryptAPISettings.Parameters != null && CryptAPISettings.Parameters.Count > 0)
callback_url = $"{CryptAPISettings.Callback}{CryptAPISettings.Parameters.HttpBuildQuery()}";

var callback_params = new NameValueCollection()
{
{ "callback", callback_url },
{ "address", CryptAPISettings.Address }
};

if (CryptAPISettings.callback_params != null && CryptAPISettings.callback_params.Count > 0)
callback_params.Add(CryptAPISettings.callback_params);

var responseString = Request(callback_params).Result;

dynamic dyn = JsonConvert.DeserializeObject(responseString);

return dyn.status == "success" ? dyn.address_in : null;

}

private async Task<string> Request(NameValueCollection Params = null)
{

string data = null;

if (Params != null)
data = Params.HttpBuildQuery();

try
{
var ResponseString = await HttpClient.GetStringAsync($"{Globals.BaseURL}/{CryptAPISettings.Coin}/{CryptAPISettings.EndPoint}/{data ?? string.Empty}");

return ResponseString;
}
catch
{
return null;
}
}
}
}
12 changes: 12 additions & 0 deletions back/CryptAPI/CryptAPI.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

</Project>
Loading

0 comments on commit 5d1cbfd

Please sign in to comment.