Hot answers tagged library
10
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 ...
7
You can get around the json/simplejson easily in your wrapper. Just change your import line from
import urllib2, json, httplib, datetime, operator
to
import urllib2, httplib, datetime, operator
try:
import json
except ImportError:
import simplejson as json
That way you can just use json in the rest of your code, but client pythons will load ...
5
I am using Py-StackExchange in our Stack2Blog application.
How do I retrieve a list of answers of a specific user using this wrapper?
After retrieving a user object, the .answers member variable returns an empty list while I know the user does have posts.
5
Usage Example: Stack Exchange Site Monitor
JavaScript Site Monitor in 20 lines of code or less....
Demonstrates the use of Soapi.js to query stackauth.com to get an up-to-date list of Stack Exchange sites and then polling /stats for each one on a revolving timer.
$(document).ready(function siteMonitor() {
var apiKey = '';
new ...
4
Search Examples
Questions
You can search for questions with StackWrap4J by instantiating a StackWrapper then calling the search method. Before calling search, you have to create a SearchQuery, which is a simple parameter object.
StackWrapper so = new StackOverflow();
SearchQuery query = new SearchQuery();
query.setTags("swing");
...
4
Quite impressive - am looking forward for more!
I'm afraid you'll need to change the library name soon though, as LINQToStackOverflow is at odds with the recently published Trademark Guidance, which explicitly asks for only one of the terms, "Stack" or "Exchange" or "Overflow" in your product name.
So may I suggest the obvious: LINQ to Stack ;)
Sounds ...
3
Edit:
My problem below has been "solved", and it's a problem with the fact that I'm getting back gzip-compressed data from stackapps. See the SO Answer. I'm still unsure why this happens only on my computer (possible reason: routers in my network adding content-headers), but I'm guessing this should be fixed in the wrapper itself.
Come to think of it, the ...
3
Soapi.CS Fluent Configuration
var ctx = new ApiContext(ApiKey).Options
// obviates a call to stackauth
.SerializedSites("{ 'api_sites': [ {'name': 'Stack....")
// can also be accomplished by seeding the cache
.SeedCache(new RequestCacheItem
{
Uri = new Uri("http://stackauth.com/1.0/sites"),
ResponseText = "{ ...
3
This is a nice implementation, but it doesn't work on Java ME nor Android though. You seem to be experienced Java developer, because you are using the adapter pattern design and some introspection stuff.
The main problem here is that Java ME and Android don't provide the java.beans package which is needed in order to use introspection as you are using it... ...
3
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.
3
Asynchronous Requests
Async requests can be made using the Site's RouteFactory.
A salient use case for this functionality is using Soapi in Silverlight.
[TestMethod, Asynchronous]
public void AnswersByIdTestValid()
{
// The thing to be aware of is that the IEnumerable, lazyloading
// model is synchronous, and since we are on the UI thread here
...
3
Mkay, I've only used the part of the code that relates to StackAuth:
You forgot to update the version number for SitesMethod and UsersByIdAssociatedMethod
SitesMethod and UsersByIdAssociatedMethod both take $key as a parameter, but seeing as we've already inited the stackPHP object with the key, seems a bit redundant. I changed my SitesMethod function to ...
2
OK, I'm probably missing the obvious, but how do I get the body of an answer?
For example, in your code snippet:
>>> so = stackexchange.Site('api.stackoverflow.com')
>>> me = so.user(41981)
>>> me.answers.fetch()
>>> me.answers[0].body
Traceback (most recent call last):
File "<pyshell#45>", line 1, in ...
2
Possible bug in the latest build? Found this (excellent) library via a Bryce Boe post and dropped in Py-Stackoverflow via easy_install.
Running the script triggered the following, however:
sog@bishop:~/Dropbox/Code/StackOverflow$ ./minestack.py
Traceback (most recent call last):
File "./minestack.py", line 3, in <module>
from stackexchange ...
2
Soapi.CS Full API Coverage
// instantiate a context
ApiContext ctx = new ApiContext("qgAq_KfDu0KYzlNG-qaTuw");
ctx.Initialize().AsyncWaitHandle.WaitOne();
// get a site
Site sofu = ctx.Official.StackOverflow;
// or
Site stackapps = ctx.Sites.First(s=>s.ApiEndpoint == "http://api.stackapps.com");
---
// StackAuth Routes
// /sites ...
2
Soapi Caching and Throttling
Throttle
All API requests made by Soapi are routed first through Soapi.Net.RequestCache and failing a cache hit, they are then routed through Soapi.Net.RequestThrottle.
The throttle, which is described in detail here, works on a sliding window, allowing maximum request rate up to the prescribed limits, currently 30 per 5 ...
2
Soapi.CS Paged Results
Pay particular attention to the third example; thats all 2800+ stack apps users in less than 5 seconds without breaking any rules. not too shabby.
// Soapi elegantly handles multi-page requests.
// Multi-paged requests are issued in parallel making data retrieval quick
// get the default, 1 page of 30 using default sort
var ...
2
have you thought of adding User Association from StackAuth? I added it to my copy as a class method to SKSite, not sure if it follows the design pattern but it works. Also it doesn't return complete SKUser objects, because stackauth itself doesn't and fetch the complete user object from each site isn't feasible.
2
Bulk Data Import
This is a simple example of using Soapi.CS for bulk data importation.
This sample creates/updates a SQLite database with the the complete profile of all Stack Exchange users with reputation >= 100 and assigns a rank according to order of appearance.
Soapi processes the ~1000 requests required in less than 5 minutes.
You may run this ...
2
Soapi.CS - Full Parameter Parity
Soapi provides full API coverage including parameters.
[Test]
public void info_param()
{
// /questions
SO.Questions
// answers (optional) When "true", the answers to a question will be returned
.WithAnswers(true)
// body (optional) When "true", a post's body will be included in the ...
2
MakerOfThings7:
Why is SOAPICS GPL? That really limits it's usage. Can you change it to LGPL?
http://soapics.codeplex.com/license
My application is proprietary, and the GPL license requires that I distribute source of my app if I simply link to this library. That's a no-go for me.
code poet:
There are many reasons that this, and other libraries, are ...
2
Visual Studio JavaScript Intellisense and Code Completion Support
Overview
Included in the .zip is soapi-vsdoc.js. This file contains JavaScript code documented following the Visual Studio JavaScript Intellisense Documentation format.
This file, while of special interest to users of Visual Studio, contains complete documentation of the API, including all ...
2
soapi.js vs soapi-vsdoc.js
While the -vsdoc.js is quite large, it is never served. It is, if you are using Visual Studio, used to provide intellisense services, otherwise you may either delete it or keep it around as reference.
The file that actually defines the domain types at runtime, soapi.js, is quite small, 9.5k packed, in that it only contains meta ...
2
Request Caching
In the interest of application performance and to prevent inadvertent api 'abuse', Soapi.js includes an integrated request cache that stores the results of each unique request url for a default (and minimum) period of 60 seconds.
The caching duration may be increased for individual routes as per your application's needs.
e.g. perhaps your ...
2
Throttled Request Queue
To provide transparent compliance with the throttle limite, Soapi.js includes an integrated throttled request queue.
The queue is integrated into the library and is transparent, requiring no additional coding or consideration.
The current default queue interval is 170ms.
This means that, with the request queue and request cache, ...
2
Paging Operations
The majority of operation against the API involve paging operations.
Most of the work and complexity of dealing with paged results have been encapsulated by the Route.GetPagedResponse() method.
Soapi.RouteFactory("api.stackoverflow.com", apiKey)
.Tags({ pagesize: 1 }) // contrived page size
.getPagedResponse(function ...
2
Timeout Example
If you find that a response is taking too long for your app, you can set a timeout on the request.
If a timeout occurs, a java.net.SocketTimeoutException is thrown. The default timeout is 0 which means infinite, so you don't have to worry about the exception if you never set a timeout.
StackWrapper sw = new StackOverflow();
// Set the ...
2
Version Updates:
Version 1.0.1 [download]
Added serialization to StackWrapper, all entities, and all queries
Url encoded user entered String parameters (i.e. " " => "%20")
Set followRedirect on each connection instance instead of JVM-wide. (This was causing problems with Google App Engine)
2
Not sure if this is the right place for it, but I'm having some issues when I try and deploy this wrapper on a server as opposed to my local environment.
First of all, I don't have SQLite3 on my server and do not have the ability to install it so I've set the caching to 0.
Second, I have got it working perfectly on my local dev server that has internet ...
2
Api Coverage
Every path in the API has a reciprocal query rooted on the Soapi.Domain.Site object.
The query syntax has been constructed to be as intuitive as possible.
A complete map of Soapi.JS2 query path to API rest path follows.
Api Routes
/answers/{id}
site.Answers().ById(704).invoke(/*handlers here*/);
...
Only top voted, non community-wiki answers of a minimum length are eligible