119

Stacky - A .NET Client Library

The same great library now supports the 2.0 API!

https://bitbucket.org/lfoust/stacky

Sample Code

IUrlClient urlClient = new UrlClient();
IProtocol protocol = new JsonProtocol();

var client = new StackyClient(version, apiKey, Sites.StackOverflow, urlClient, protocol);
var questions = client.GetQuestions();
foreach (var question in questions)
{
    Console.WriteLine(question.Title);
}

Silverlight and Windows Phone

IUrlClient urlClient = new UrlClient();
IProtocol protocol = new JsonProtocol();

var client = new StackyClient(version, apiKey, Sites.StackOverflow, urlClient, protocol);
client.GetQuestions(questions =>
{
    foreach (var question in questions)
    {
        Console.WriteLine(question.Title);
    }
});

You can view more detailed documentation in Getting Started.

About

Stacky is a .NET client library for the Stack Apps API. It is a simple library and to supports a variety of platforms such as Silverlight and Windows Phone 7, .NET 4 and .NET 3.5.

License

MSPL

Download

http://stacky.codeplex.com

Source

https://bitbucket.org/lfoust/stacky

Platform

.NET (Windows, Windows Phone 7). Not tested on Mono.

Contact

Luke Foust - Feel free to contact through CodePlex site

Code

.NET 4, .NET 3.5, C#, Silverlight 4, Windows Phone 7

12
  • How would one retrieve a tags FAQs? e.g: stackoverflow.com/tags/forms/faq
    – user5408
    Feb 22, 2011 at 21:57
  • @eth0 - I am not aware of an easy way to get tag FAQs in the current API. You can get questions by tag and you can get linked questions but I don't know of a way to link them together and sort them.
    – lfoust
    Feb 23, 2011 at 1:08
  • 2
    Is there any way to get a user's badges (the /user/badges route)? See this SO question: stackoverflow.com/questions/5091513/… Feb 23, 2011 at 13:37
  • I didn't see a nuget package for version 2, and I built the 2.0 branch from source, it complains about "Sites.Stackoverflow doesn't contain a definition for "APiEndpoint" or "Description". Jun 15, 2012 at 0:16
  • @GeorgeStocker - Sorry, I need to do some branch merging back into main. If you build the V2 branch it should build fine. And you are right, I haven't updated the nuget package to v2 yet.
    – lfoust
    Jun 15, 2012 at 5:41
  • 1
    Any consideration of porting this over to the WinRT or as a Portable Class Library? Oct 10, 2012 at 5:42
  • @KronoS I have considered porting to WinRT but just don't have the time. If you are interested in tackling it let me know ;)
    – lfoust
    Oct 16, 2012 at 20:45
  • @lfoust lemme get through my first build of my app and then I'll see if I can dedicate some time to port this over. If I decide to do so, I'll let you know. Oct 16, 2012 at 22:25
  • Your bitbucket source code isn't complete. Missing some sites in sites.cs. Can I suggest that you either use the bitbucket or the codeplex as it's quite confusing which is the most up to date. Feb 7, 2013 at 4:32
  • Also I'm working on a WinRT derivative of this. When I'm done, I'll let you know so you can approve ;) Feb 7, 2013 at 5:03
  • now that 4.5 not supported any longer, is there an update for 4.6 target
    – user38649
    Mar 16, 2016 at 15:49
  • 1
    @FedRAMP There hasn't been any active development on this library for several years. You are welcome to contribute any changes you are interested in seeing: bitbucket.org/lfoust/stacky
    – lfoust
    Mar 19, 2016 at 5:31

6 Answers 6

13

Just wanted to let everybody know that I just made a new release of the library here. This release includes tons of bug fixes as well as some breaking changes which shouldn't be a problem if you have been running off the trunk.

Also, by popular demand, I added a .Net 3.5 version of the library to this release. The hope here is to eventually have a mono version and possibly an Silverlight 3 version if there is any interest.

Please feel free to leave any feedback on the codeplex site or submit any bugs here.

Thanks for helping me make this great release!

2
  • 5
    Awesome library! I'm hoping to release an "alpha" of my first app based off your library in a few days :-)
    – codeka
    Jun 2, 2010 at 23:17
  • May I suggest that you update the links in this post at least to reflect the libraries new CodePlex site stacky.codeplex.com as this might confuse new users (and defeats SEO btw. ;) Jul 28, 2010 at 9:18
4

With the way the API is currently set up (lots of caching the info page says) is it possible to update the information on a question you've already looked at? I have a list of questions but, as time goes on, the information changes (# of answers, votes, etc) and I would like to be able to update the questions with the new info.

2
  • I am not sure I understand what you mean. If you do: Question q = client.GetQuestion(12324); ...Then some time passes... and you do q = client.GetQuestion(12324); wouldn't that do the trick? Are you asking if there is a way to bypass the cache?
    – lfoust
    Aug 4, 2011 at 4:26
  • 2
    @lfoust Yeah, but I need it to work when not very much time passes. So yeah, is there a way to bypass the cache basically. Aug 4, 2011 at 4:39
3

Thanks for this super library!

I've used it for my Overflow 7 app. (See also the Overflow 7 video.)

I've put a few detailed comments on your Stacky codeplex discussion site. I hope they help.

Thanks again,
Stuart

2

In the StackyClient.GetQuestions function, for the tags parameter, will you get questions with any of the tags in the array, or questions that have all of the tags in the array?

Also I don't see really any documentation except for the page with a few examples, which don't explain what exactly the parameters do and stuff. If anyone could link me to a thorough documentation or tell me where to find one it would be much appreciated.

Also, this is an excellent library, and very reliable. Good job OP.

1
  • 1
    Since the methods and parameters pretty much exactly mirror that of the actual stack exchange API, I decided to not repeat that work. You can view their awesome documentation here: api.stackoverflow.com/1.1/usage. Let me know if you think there would be some value in making a comprehensive documentation for Stacky which is kept in sync with the official stack exchange API documentation.
    – lfoust
    May 25, 2011 at 17:24
1

Feature Request

If you look at my other question over here, I figured out that by specifying min&max I can get a basic "exact match" feature working for user name searches. The main problem is that StackOverflow.Net doesn't support string min and max parameters. I've added the following overloads to my own copy of UserMethods.cs:

public virtual IPagedList<User> GetUsers(string min, string max, UserSort sortBy = UserSort.Reputation, SortDirection sortDirection = SortDirection.Descending, int? page = null, int? pageSize = null, string filter = null, DateTime? fromDate = null, DateTime? toDate = null)
{
    var response = MakeRequest<UserResponse>("users", null, new
    {
        key = apiKey,
        page = page ?? null,
        pagesize = pageSize ?? null,
        filter = filter,
        sort = sortBy.ToString().ToLower(),
        order = GetSortDirection(sortDirection),
        fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
        todate = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null,
        min = min ?? null,
        max = max ?? null
    });
    return new PagedList<User>(response.Users, response);
}

public virtual IPagedList<User> GetUsers(IEnumerable<int> userIds, string min, string max, UserSort sortBy = UserSort.Reputation, SortDirection sortDirection = SortDirection.Descending, int? page = null, int? pageSize = null, string filter = null, DateTime? fromDate = null, DateTime? toDate = null)
{
    var response = MakeRequest<UserResponse>("users", new string[] { userIds.Vectorize() }, new
    {
        key = apiKey,
        page = page ?? null,
        pagesize = pageSize ?? null,
        filter = filter,
        sort = sortBy.ToString().ToLower(),
        order = GetSortDirection(sortDirection),
        fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
        todate = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null,
        min = min ?? null,
        max = max ?? null
    });
    return new PagedList<User>(response.Users, response);
}

Note in this overload, I had to make min and max not take default values (otherwise the overload resolution got confused if you didn't specify either of them). Not sure if that's the best way, but it works for me :)

3
  • I'll have to give some thought to this. I think I would prefer to just add a boolean matchExact (like you originally suggested in your question) to the method and then in the implementation I could translate that to using the min and max parameters. Exposing this min and max wierdness directly to the API consumers seems confusing to me.
    – lfoust
    Jun 7, 2010 at 15:37
  • @lfoust: Fair enough. I'd prefer the exactMatch=true way as well...
    – codeka
    Jun 7, 2010 at 20:55
  • 1
    @lfoust and codeka - the min/max parameters are still incorrectly documented as dates when in fact they should be treated as a variant string that is contextually bound to sort. see stackapps.com/questions/671 Jun 27, 2010 at 17:34
1

Feature Request

The active questions queue shows posts that have been edited. I like to watch that. But I can't get a List of Answers sorted by activity, only Questions. I am looking for something like this

var o = new PostOptions();
o.SortBy = Sort.Activity;                
o.SortDirection = SortDirection.Descending;                
o.FromDate = DateTime.UtcNow.AddMinutes(-10);
var list = client.GetPosts(o);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .