dillenmeister/Trello.NET

Passing optional parameters

Closed this issue · 4 comments

More of a question than an issue.

It is possible through Trello.Net to pass through the optional parameters?

For example Trello.Lists.WithId() calls /lists/[id] - but I will like to also pass the optional "cards" parameter to retrieve all the cards at the same time.

My requirement would not be restricted to just the lists method, I would like to know if it is possible to do this for all methods?

Thanks

Paul

Sorry for the late answer. No, it's not possible.

If you have any ideas on how this could be designed I'm definately willing to listen.

I just pushed a new feature: Trello.Advanced.

It has four methods, Get, Post, Put and Delete. They all accept a uri and an object with additional arguments. The return type is either dynamic or a type of your choosing.

This is how you could make that request:

dynamic myList = trello.Advanced.Get("/lists/1234567890abcdefghijklmn", 
    new { cards = "all" });

Console.WriteLine(myList.name);

foreach (var card in myList.cards)
    Console.WriteLine(card.name);

You can also create your own type if you don't want to deal with dynamic:

public class MyList
{
    public string Name { get; set; }
    public IEnumerable<MyCard> Cards { get; set; }
}

public class MyCard
{
    public string Name { get; set; }
}

MyList myList = trello.Advanced.Get<MyList>("/lists/1234567890abcdefghijklmn", 
    new { cards = "all" });

Console.WriteLine(myList.Name);

foreach (var card in myList.Cards)
    Console.WriteLine(card.Name);

The trello api is documented here: https://trello.com/docs/index.html.

Excellent, this is just what I needed. I really like the way you have implemented this. Good work!

From: Oskar Dillén [mailto:notifications@github.com]
Sent: 01 May 2014 15:33
To: dillenmeister/Trello.NET
Cc: pauldbentley
Subject: Re: [Trello.NET] Passing optional parameters (#50)

I just pushed a new feature: Trello.Advanced.

It has four methods, Get, Post, Put and Delete. They all accept a uri and an object with additional arguments. The return type is either dynamic or a type of your choosing.

This is how you could make that request:

dynamic myList = trello.Advanced.Get("/lists/1234567890abcdefghijklmn",
new { cards = "all" });

Console.WriteLine(myList.name);

foreach (var card in myList.cards)
Console.WriteLine(card.name);

You can also create your own type if you don't want to deal with dynamic:

public class MyList
{
public string Name { get; set; }
public IEnumerable Cards { get; set; }
}

public class MyCard
{
public string Name { get; set; }
}

MyList myList = trello.Advanced.Get("/lists/1234567890abcdefghijklmn",
new { cards = "all" });

Console.WriteLine(myList.Name);

foreach (var card in myList.Cards)
Console.WriteLine(card.Name);

The trello api is documented here: https://trello.com/docs/index.html.


Reply to this email directly or view it on GitHub #50 (comment) . https://github.com/notifications/beacon/5243982__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcxNDU3Mzk1MiwiZGF0YSI6eyJpZCI6MjM2MDcxODB9fQ==--df6092f041ab19f8b56d336a1d9ba7ab43fdc9dd.gif

Great! Let me know if you have any issues with it.