Skip to main content
4 of 9
edited title
nabeelmukhtar
  • 2.4k
  • 13
  • 7

stackoverflow-java-sdk: Java wrapper for StackExchange API

I have released a beta snapshot version of a Java wrapper for StackOverflow API at http://code.google.com/p/stackoverflow-java-sdk/. Please try it and provide your feedback.

##Screenshot / Code Snippet There are two different interfaces to the API. One is the query API which has a Builder like syntax.

    StackOverflowApiQueryFactory queryFactory = StackOverflowApiQueryFactory.newInstance("applicationKey");
    QuestionApiQuery query = queryFactory.newQuestionApiQuery();
    List<Question> questions = query.withSort(Question.SortOrder.HOT).withPaging(new Paging(1, 20)).withTimePeriod(new TimePeriod(new Date(), new Date())).withFetchOptions(EnumSet.of(FilterOption.INCLUDE_BODY, FilterOption.INCLUDE_COMMENTS)).list();

The other is a simple facade which exposes all the methods of the API.

    StackOverflowApiClientFactory factory = StackOverflowApiClientFactory.newInstance("applicationKey");
    StackOverflowApiClient client = factory.createStackOverflowApiClient();
    List<Question> questions = client.getQuestions(Question.SortOrder.HOT, new Paging(1, 20), new TimePeriod(new Date(), new Date()), EnumSet.of(FilterOption.INCLUDE_BODY, FilterOption.INCLUDE_COMMENTS));

The lists returned by both the methods are instances of PagedList which provide methods to aid in pagination of the result.

Note that by default the library uses StackOverflow as the API provider. You can change that to use anyother by.

    query.setApiProvider(new SuperUserApiProvider());
    client.setApiProvider(new SuperUserApiProvider());
    

The method/class names somewhat map with the names in the API. In case of confusion look in the examples directory of the distribution for more examples. I will be updating the javadoc soon.

##About

stackoverflow-java-sdk is an open source library hosted at Google code. I created this library to be used in an internal project. But its comprehensive enough to be used by anyone looking to integrate with the API of StackOverflow or partner sites.

###License

stackoverflow-java-sdk is open source with an Apache License 2.0.

###Download

You can download the library from Google Code http://code.google.com/p/stackoverflow-java-sdk/.

###Platform

Its supported for any platform on which Java is supported which include Google AppEngine and Android.

##Contact

Any issues can be filed on the Google Code Issue tracking system. http://code.google.com/p/stackoverflow-java-sdk/issues/list

##Code

The library is hosted at Google Code as a mercurial repository. You can create a clone and get the code and make changes to it. To contribute to the main repository you will have to create an issue with a pull request with details of your changes. The library has one dependency on json simple which can be downloaded from here http://code.google.com/p/json-simple/.

nabeelmukhtar
  • 2.4k
  • 13
  • 7