/**
* Module: ResolveApi.cs
* Description: Represents a collection of functions to interact with the API endpoints
* Author: Moralis Web3 Technology AB, 559307-5988 - David B. Goodrich
*
* NOTE: THIS FILE HAS BEEN AUTOMATICALLY GENERATED. ANY CHANGES MADE TO THIS
* FILE WILL BE LOST
*
* MIT License
*
* Copyright (c) 2022 Moralis Web3 Technology AB, 559307-5988
*
* 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.
*/
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Net;
using Cysharp.Threading.Tasks;
using MoralisUnity.Web3Api.Client;
using MoralisUnity.Web3Api.Core;
using MoralisUnity.Web3Api.Core.Models;
using MoralisUnity.Web3Api.Interfaces;
using MoralisUnity.Web3Api.Models;
namespace MoralisUnity.Web3Api.Api
{
///
/// Represents a collection of functions to interact with the API endpoints
///
public class ResolveApi : IResolveApi
{
///
/// Initializes a new instance of the class.
///
/// an instance of ApiClient (optional)
///
public ResolveApi(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 ResolveApi(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;}
///
/// Resolves an Unstoppable domain and returns the address
///
///
/// Domain to be resolved
/// The currency to query
/// Returns an address
public async UniTask ResolveDomain (string domain, string currency=null)
{
// Verify the required parameter 'domain' is set
if (domain == null) throw new ApiException(400, "Missing required parameter 'domain' when calling ResolveDomain");
var postBody = new Dictionary();
var queryParams = new Dictionary();
var headerParams = new Dictionary();
var formParams = new Dictionary();
var fileParams = new Dictionary();
var path = "/resolve/{domain}";
path = path.Replace("{format}", "json");
path = path.Replace("{" + "domain" + "}", ApiClient.ParameterToString(domain));
if(currency != null) queryParams.Add("currency", ApiClient.ParameterToString(currency));
// 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.GET, queryParams, bodyData, headerParams, formParams, fileParams, authSettings);
if (((int)response.Item1) >= 400)
throw new ApiException((int)response.Item1, "Error calling ResolveDomain: " + response.Item3, response.Item3);
else if (((int)response.Item1) == 0)
throw new ApiException((int)response.Item1, "Error calling ResolveDomain: " + response.Item3, response.Item3);
return (Resolve)ApiClient.Deserialize(response.Item3, typeof(Resolve), response.Item2);
}
///
/// Resolves an ETH address and find the ENS name
///
///
/// The address to be resolved
/// Returns an ENS
public async UniTask ResolveAddress (string address)
{
// Verify the required parameter 'address' is set
if (address == null) throw new ApiException(400, "Missing required parameter 'address' when calling ResolveAddress");
var postBody = new Dictionary();
var queryParams = new Dictionary();
var headerParams = new Dictionary();
var formParams = new Dictionary();
var fileParams = new Dictionary();
var path = "/resolve/{address}/reverse";
path = path.Replace("{format}", "json");
path = path.Replace("{" + "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.GET, queryParams, bodyData, headerParams, formParams, fileParams, authSettings);
if (((int)response.Item1) >= 400)
throw new ApiException((int)response.Item1, "Error calling ResolveAddress: " + response.Item3, response.Item3);
else if (((int)response.Item1) == 0)
throw new ApiException((int)response.Item1, "Error calling ResolveAddress: " + response.Item3, response.Item3);
return (Ens)ApiClient.Deserialize(response.Item3, typeof(Ens), response.Item2);
}
}
}