using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using System.Net;
using MoralisUnity.SolanaApi.Client;
using MoralisUnity.SolanaApi.Interfaces;
using MoralisUnity.SolanaApi.Models;
namespace MoralisUnity.SolanaApi.CloudApi
{
public class AccountApi : IAccountApi
{
///
/// Initializes a new instance of the class.
///
/// an instance of ApiClient (optional)
///
public AccountApi(ApiClient apiClient = null)
{
if (apiClient == null) // use the default one in Configuration
this.ApiClient = Configuration.DefaultApiClient;
else
this.ApiClient = apiClient;
}
///
/// Initializes a new instance of the class.
///
///
public AccountApi(String basePath)
{
this.ApiClient = new ApiClient(basePath);
}
///
/// Sets the base path of the API client.
///
/// The base path
/// The base path
public void SetBasePath(String basePath)
{
this.ApiClient.BasePath = basePath;
}
///
/// Gets the base path of the API client.
///
/// The base path
/// The base path
public String GetBasePath(String basePath)
{
return this.ApiClient.BasePath;
}
///
/// Gets or sets the API client.
///
/// An instance of the ApiClient
public ApiClient ApiClient { get; set; }
public async UniTask Balance(NetworkTypes network, string address)
{
// Verify the required parameter 'pairAddress' is set
if (address == null) throw new ApiException(400, "Missing required parameter 'address' when calling GetNFTMetadata");
var postBody = new Dictionary();
var headerParams = new Dictionary();
var path = "/functions/sol-balance";
postBody.Add("network", ApiClient.ParameterToString(network.ToString()));
if (address != null) postBody.Add("address", ApiClient.ParameterToString(address));
// Authentication setting, if any
String[] authSettings = new String[] { "ApiKeyAuth" };
string bodyData = postBody.Count > 0 ? JsonConvert.SerializeObject(postBody) : null;
Tuple, string> response = await ApiClient.CallApi(path, Method.POST, null, bodyData, headerParams, null, null, authSettings);
if (((int)response.Item1) >= 400)
throw new ApiException((int)response.Item1, "Error calling Balance: " + response.Item3, response.Item3);
else if (((int)response.Item1) == 0)
throw new ApiException((int)response.Item1, "Error calling Balance: " + response.Item3, response.Item3);
return ((CloudFunctionResult)ApiClient.Deserialize(response.Item3, typeof(CloudFunctionResult), response.Item2)).Result;
}
public async UniTask> GetSplTokens(NetworkTypes network, string address)
{
// Verify the required parameter 'pairAddress' is set
if (address == null) throw new ApiException(400, "Missing required parameter 'address' when calling GetNFTMetadata");
var postBody = new Dictionary();
var headerParams = new Dictionary();
var path = "/functions/sol-getSPL";
postBody.Add("network", ApiClient.ParameterToString(network.ToString()));
if (address != null) postBody.Add("address", ApiClient.ParameterToString(address));
// Authentication setting, if any
String[] authSettings = new String[] { "ApiKeyAuth" };
string bodyData = postBody.Count > 0 ? JsonConvert.SerializeObject(postBody) : null;
Tuple, string> response = await ApiClient.CallApi(path, Method.POST, null, bodyData, headerParams, null, null, authSettings);
if (((int)response.Item1) >= 400)
throw new ApiException((int)response.Item1, "Error calling GetSplTokens: " + response.Item3, response.Item3);
else if (((int)response.Item1) == 0)
throw new ApiException((int)response.Item1, "Error calling GetSplTokens: " + response.Item3, response.Item3);
return ((CloudFunctionResult>)ApiClient.Deserialize(response.Item3, typeof(CloudFunctionResult>), response.Item2)).Result;
}
public async UniTask> GetNFTs(NetworkTypes network, string address)
{
// Verify the required parameter 'pairAddress' is set
if (address == null) throw new ApiException(400, "Missing required parameter 'address' when calling GetNFTMetadata");
var postBody = new Dictionary();
var headerParams = new Dictionary();
var path = "/functions/sol-getNFTs";
postBody.Add("network", ApiClient.ParameterToString(network.ToString()));
if (address != null) postBody.Add("address", ApiClient.ParameterToString(address));
// Authentication setting, if any
String[] authSettings = new String[] { "ApiKeyAuth" };
string bodyData = postBody.Count > 0 ? JsonConvert.SerializeObject(postBody) : null;
Tuple, string> response = await ApiClient.CallApi(path, Method.POST, null, bodyData, headerParams, null, null, authSettings);
if (((int)response.Item1) >= 400)
throw new ApiException((int)response.Item1, "Error calling GetNFTs: " + response.Item3, response.Item3);
else if (((int)response.Item1) == 0)
throw new ApiException((int)response.Item1, "Error calling GetNFTs: " + response.Item3, response.Item3);
return ((CloudFunctionResult< List < SplNft >>)ApiClient.Deserialize(response.Item3, typeof(CloudFunctionResult>), response.Item2)).Result;
}
public async UniTask GetPortfolio(NetworkTypes network, string address)
{
// Verify the required parameter 'pairAddress' is set
if (address == null) throw new ApiException(400, "Missing required parameter 'address' when calling GetNFTMetadata");
var postBody = new Dictionary();
var headerParams = new Dictionary();
var path = "/functions/sol-getPortfolio";
postBody.Add("network", ApiClient.ParameterToString(network.ToString()));
if (address != null) postBody.Add("address", ApiClient.ParameterToString(address));
// Authentication setting, if any
String[] authSettings = new String[] { "ApiKeyAuth" };
string bodyData = postBody.Count > 0 ? JsonConvert.SerializeObject(postBody) : null;
Tuple, string> response = await ApiClient.CallApi(path, Method.POST, null, bodyData, headerParams, null, null, authSettings);
if (((int)response.Item1) >= 400)
throw new ApiException((int)response.Item1, "Error calling GetPortfolio: " + response.Item3, response.Item3);
else if (((int)response.Item1) == 0)
throw new ApiException((int)response.Item1, "Error calling GetPortfolio: " + response.Item3, response.Item3);
return ((CloudFunctionResult)ApiClient.Deserialize(response.Item3, typeof(CloudFunctionResult), response.Item2)).Result;
}
}
}