Base16.LoopiaApi 1.1.0

dotnet add package Base16.LoopiaApi --version 1.1.0
NuGet\Install-Package Base16.LoopiaApi -Version 1.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Base16.LoopiaApi" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Base16.LoopiaApi --version 1.1.0
#r "nuget: Base16.LoopiaApi, 1.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Base16.LoopiaApi as a Cake Addin
#addin nuget:?package=Base16.LoopiaApi&version=1.1.0

// Install Base16.LoopiaApi as a Cake Tool
#tool nuget:?package=Base16.LoopiaApi&version=1.1.0

Base16.LoopiaApi

Introduction

Base16.LoopiaApi is a simple .NET XML-RPC wrapper for Loopias API. The wrapper makes it easy to use the public customer-facing API described in the official documentation. This library can for example very simply be used to update a DNS record to point to a specific IP.

Prerequisites

In order to use the functionality exposed by this library (and the Loopia API in general) you'll need to have at least a DNS account registered with Loopia. You'll also need to create an API-user ("API-användare") under your account and ensure that the user has the appropriate access rights.

Limitations & Known Issues

  • Loopias official limitations apply
  • Most partner API's have not been implemented sine they cannot be fully verified without being a partner
  • Encoding for IDN-domains seems to be wrong on invoice_item_obj - This is only an issue when viewing these domains on invoice-lines

Simple usage example

Note this example only serves to illustrate the usage of the API.

using System;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Base16.LoopiaApi;
using Base16.LoopiaApi.Models;

class Program
{
	private static readonly HttpClient HttpClient = new HttpClient();

	public async Task Main()
	{
		var externalIP = await GetExternalIPAsync();

		var result = await UpdateZoneRecordAsync(
			apiUsername: "--ENTER-YOUR-API-USERNAME-HERE--",
			apiPassword: "--ENTER-YOUR-API-PASSWORD-HERE--",
			domain: "--ENTER-YOUR-DOMAIN-NAME-HERE--(ex: google.se)--",
			subdomain: "@",
			externalIP: externalIP
		);

		Console.WriteLine($"{nameof(UpdateZoneRecordAsync)} returned {result}");
	}

	private async Task<ResponseStatus> UpdateZoneRecordAsync(
		String apiUsername,
		String apiPassword,
		String domain,
		String subdomain,
		String externalIP
	)
	{
		// Initialize LoopiaApiClient given a username and password.
		// 'customerNumber' is only valid for retailers and should otherwise be omitted.
		var loopiaApi = new LoopiaApiClient(
			username: apiUsername,
			password: apiPassword,
			customerNumber: null
		);

		// Get all zone-records for the given domain and subdomain
		var zoneRecords = await loopiaApi.GetZoneRecordsAsync(domain, subdomain);

		// Locate the record that we want to update
		var ipRecord = zoneRecords.Single(x => x.Type == "A");

		// Check if the record is already up-to-date
		if(ipRecord.RData == externalIP)
		{
			// IP already up-to-date, no action required
			return ResponseStatus.Ok;
		}

		// Update record with new IP
		ipRecord.RData = externalIP;

		// Send update-request to Loopia
		return await loopiaApi.UpdateZoneRecordAsync(domain, subdomain, ipRecord);
	}

	private async Task<String> GetExternalIPAsync()
	{
		var getResponse = await HttpClient.GetAsync("https://api.ipify.org/?format=txt");
		return await getResponse.Content.ReadAsStringAsync();
	}
}

Version history

1.0.0

  • Initial release

1.1.0

  • Fixed wrapper for breaking change introduced by Loopia.
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.
  • net5.0

    • No dependencies.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 389 8/11/2022
1.0.0 739 9/12/2019