forked from Manny27nyc/CryptAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Biitez
committed
Apr 29, 2021
1 parent
1ec35f4
commit 5d1cbfd
Showing
18 changed files
with
552 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.