anderly / dnsimple-csharp

A C# wrapper for the DNSimple REST API
Apache License 2.0
17 stars 10 forks source link

Adding capability to return/list records based on record_type #9

Closed drewid closed 9 years ago

drewid commented 9 years ago

It would be useful to have a get list of records based on the record_type. Are you open to having a method created to handle that? Would be really nice.

If so, how would you like to move forward with making/proposing changes? You do it yourself or have it submitted via a pull request?

Thanks

anderly commented 9 years ago

Well, a pull request for a new feature is certainly welcome. However, since the API doesn't actually support retrieving records based on type, you might want to just tackle this with an extension method that wraps ListRecords() like this:

    public static class DnsimpleExtensions
    {
        public static IEnumerable<dynamic> ListRecords(this DNSimpleRestClient dns, string domain, string recordType)
        {
            IEnumerable<dynamic> results = dns.ListRecords(domain);
            return results.Where(r => r.record.record_type == recordType);
        }
    }

Plus, the newer version that is coming will have some of this built-in and will also remove the dynamics so that you get a better development experience with strongly-typed return objects.

For instance, instead of:

// this returns dynamic
var records = dns.ListRecords("example.com")

you'd do

// this will return an IEnumerable List<DnsRecord>
var records = await dns.Domains.Records.ListAsync("example.com")

That will allow for LINQ-style queries, projections and filtering plus it will shield you from the sort of odd return types that the API returns.

Thoughts?

anderly commented 9 years ago

Depending on your needs, you might also want to check out my other project: https://github.com/anderly/dnsimple-cli

This allows you to use the dnsimple api from the command line.

With it, you can do exactly what you are asking for above:

dns domain record list -t CNAME example.com

info:    Executing command domain record list
+ Getting records for domain example.com
CNAME
info:    Custom Records:
data:    Id       Type   Name          TTL   Content
data:    -------  -----  ------------  ----  ----------------------------------
data:    311541   CNAME  cname1        3600  cname.example1.com
data:    1046005  CNAME  cname2        3600  cname.example2.com
data:    3311604  CNAME  cname3        3600  cname.example3.com
info:

or

dns domain domain list *.com

info:    Executing command domain list
+ Getting domains
data:    Name             Records  Expires     Auto-Renew  Whois-Protected
data:    ---------------  -------  ----------  ----------  ---------------
data:    domain1.com      5        2015-01-20  Yes         No
data:    domain2.com      5        2015-01-20  Yes         No
data:    domain3.com      5        2015-01-20  Yes         No
data:    domain4.com      5        2015-01-20  Yes         No
info:    domain list command OK
drewid commented 9 years ago

Is for a .net web project. After further thought, never mind. Would be great to have but can be done after getting all results.

anderly commented 9 years ago

Ok. Thoughts on the extension method approach?