Coder Social home page Coder Social logo

dnsimple / dnsimple-csharp Goto Github PK

View Code? Open in Web Editor NEW
12.0 10.0 7.0 647 KB

The DNSimple API client for C#.

Home Page: https://developer.dnsimple.com/

License: MIT License

C# 100.00%
api csharp api-client dnsimple dnsimple-api dnsimple-policy-group-apiclient dnsimple-policy-eng dnsimple-policy-triage-application

dnsimple-csharp's Introduction

DNSimple C# Client

A C# client for the DNSimple API v2.

Build Status NuGet version

Installation

Where <version> denotes the version of the client you want to install.

Package Manager

PM> Install-Package DNSimple -Version <version>

Usage

This library is a C# client you can use to interact with the DNSimple API v2. Here are some examples.

using dnsimple;

var client = new Client();
var credentials = new OAuth2Credentials("...");
client.AddCredentials(credentials);

// Fetch your details
var response = client.Identity.Whoami();   // execute the call
var account = response.Data.Account;       // extract the relevant data from the response or
client.Identity.Whoami().Data.Account;     // execute the call and get the data in one line

// You can also fetch it from the whoami response
// as long as you authenticate with an Account access token
var whoami = client.Identity.Whoami().Data;
var accountId = whoami.Account.Id;

List your domains

using dnsimple;

var client = new Client();
client.AddCredentials(new OAuth2Credentials("..."));

var accountId = client.Identity.Whoami().Data.Account.Id;
var domains = client.Domains.ListDomains(accountId).Data;

Create a domain

using dnsimple;

var client = new Client();
client.AddCredentials(new OAuth2Credentials("..."));

var accountId = client.Identity.Whoami().Data.Account.Id;
var domain = client.Domains.CreateDomain(accountId, new Domain{ Name = "example.com" }).Data;

Retrieve a domain

using dnsimple;

var client = new Client();
client.AddCredentials(new OAuth2Credentials("..."));

var accountId = client.Identity.Whoami().Data.Account.Id;
var domainId = client.Domains.ListDomains(accountId).Data.First().Id;
var domain = client.Domains.GetDomain(accountId, domainId).Data;

Sandbox Environment

We highly recommend testing against our sandbox environment before using our production environment. This will allow you to avoid real purchases, live charges on your credit card, and reduce the chance of your running up against rate limits.

The client supports both the production and sandbox environment. To switch to sandbox pass the sandbox API host using the ChangeBaseUrlTo(...) method when you construct the client:

var client = new Client();
client.ChangeBaseUrlTo("https://api.sandbox.dnsimple.com");

var credentials = new OAuth2Credentials("...");
client.AddCredentials(credentials);

You will need to ensure that you are using an access token created in the sandbox environment. Production tokens will not work in the sandbox environment.

Setting a custom User-Agent header

You can customize the User-Agent header for the calls made to the DNSimple API:

var client = new Client();
client.SetUserAgent("my-app/1.0");

The value you provide will be prepended to the default User-Agent the client uses. For example, if you use my-app/1.0, the final header value will be my-app/1.0 dnsimple-csharp/0.14.0 (note that it will vary depending on the client version).

We recommend to customize the user agent. If you are building a library or integration on top of the official client, customizing the client will help us to understand what is this client used for, and allow to contribute back or get in touch.

License

Copyright (c) 2022 DNSimple Corporation. This is Free Software distributed under the MIT license.

dnsimple-csharp's People

Contributors

aeden avatar ags4no avatar dependabot-preview[bot] avatar dependabot[bot] avatar duduribeiro avatar dxtimer avatar ecomba avatar ggalmazor avatar jacegu avatar nestorsalceda avatar olemchls avatar san983 avatar vanhuychemg avatar weppos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dnsimple-csharp's Issues

Json Payload Not Serializing Correctly For IList<string>

There is an issue when calling Registrar.ChangeDomainDelegation(long accountId, string domain, IList delegation), The Payload is not being serialized correctly when passing in an IList resulting in a BadRequest Response with the message:
"Parameter servers: must be an array"

I'm currently seeing this issue as well, using your described example, passing in a list causes the Payload to fail with the reason above:
image

Here is the request object serialized:
image

Responses' Request Body:
image

Hi @VanHuychemG, sorry for the delay.

We went thru this and we haven't found a reason about why sending an unserialized body. May I ask if are sending the list of nameservers as in the example below?

var delegation = new List<string>
{
    "ns1.dnsimple.com", "ns2.dnsimple.com", "ns3.dnsimple.com","ns4.dnsimple.com"
};

var newDelegation = client.Registrar.ChangeDomainDelegation(accountId, domainName, delegation);

Originally posted by @SProfession in #35 (comment)

Feature Request: Allow User to Moq Client Class Inner Service Classes and Their Methods

I just started using this DnSimple library and while trying to write unit tests, was having issues creating a Moq of the inner service class' and their methods. Is there a way to doing this, or would it be possible to get this created as a feature? The reason being, I would like to test my application in isolation and not have to rely on calls outwards to your sandbox API for every unit test.

ChangeBaseUrlTo does not respect SetUserAgent

I was looking through the code and saw this:

https://github.com/dnsimple/dnsimple-csharp/blob/master/src/dnsimple/DNSimple.cs#L332-L337

It seems this bit resets the user agent back to the default: RestClientWrapper.RestClient.UserAgent = DefaultUserAgent;

Which means this order will fail:

var r = new RestClientWrapper();
var client = new Client(r);

client.SetUserAgent("exira/1.0");
Console.WriteLine(r.RestClient.UserAgent);
client.ChangeBaseUrlTo("https://api.sandbox.dnsimple.com");
Console.WriteLine(r.RestClient.UserAgent);

While this will be ok:

var r = new RestClientWrapper();
var client = new Client(r);

client.ChangeBaseUrlTo("https://api.sandbox.dnsimple.com");
Console.WriteLine(r.RestClient.UserAgent);
client.SetUserAgent("exira/1.0");
Console.WriteLine(r.RestClient.UserAgent);

I am passing in the RestClientWrapper to check the UserAgent being used. Because the UserAgent property on Client will not show it

Upgrade to RestSharp v108

This change requires some code changes as the following interfaces have been deprecated:

  • IRestClient
  • IRestRequest
  • IRestResponse
  • IHttp

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤ī¸ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.