OK, applied quick fix so now members with spaces can now be found as well. Thank you to ddanbe for giving me ideas on how to implement it.
OK, applied quick fix so now members with spaces can now be found as well. Thank you to ddanbe for giving me ideas on how to implement it.
Edited by riahc3
Here is the code. Ill post this in the snippet section as well::"); } } }
Like I mentioned, very dirty and just to work. Can be done way better. 4.0
Also the /**/ Are used to make it "copy/paste" ready...
Edited by riahc3
I am begging you Dani, and anyone else, please tell me what is wrong with this post?
Cheers Riahc3 :)
OK Ive been able to post it but without the text that I put after. What is wrong with it?
Cross posting your question makes it more likely that you'll miss the answer. Please see your other thread on the subject for my response.
I just replied to your PM. Glad you got it working.
I've been working on a Java API that tries to simplify accessing the Daniweb API from Java based applications.
It isn't finished yet and still has bugs. I attached to my post what's basically an export of my Eclipse project.
I release it because at the moment I lack the time to finish the implementation and because there doesn't seem to be alot of Java activity around the Daniweb API.
I hope the release of this source will encourage the Java people to experiment with Java and the Daniweb API.
Later when I will have time to finish it I'll clean it up and post it down as a code snippet.
Any suggestions, fixes and constructive critique are always welcomed and highly appreciated. ;)
Edited by mvmalderen
Quick example:
// Fetch member entity of Dani Member dani = RequestBuilder.memberRequest().username("dani").build().fetchSingle(); // Fetch Java code snippets by Dani and order them last post first FetchRequest<Article> request = RequestBuilder.articleRequest() .members(dani.getUserId()) .forums(9) .orderBy(LASTPOST) .filter(CODE) .build(); List<Article> articles = request.fetchMultiple(); // Fetch Forum data of the C/C++/Java forums List<Forum> forums = RequestBuilder.forumRequest().ids(118, 8, 9).build().fetchMultiple();
Edited by mvmalderen
I know you people are going to kill me, but I've made another change that will affect everyone.
All results are now within an array key called [items] ... so instead of it being $results['username'] it's going to be $results['items']['username']. This leaves room for other things such as meta data to be sent in the resultset in the future.
I don't see why we would kill you... we would only support you.
In that case, I'm changing lots of other things as well :)
I've been speaking with a friend with a lot of API experience, and he's suggesting some major revamps to the actual output. Right now, it's all just pretty much a dump of the way everything is represented in the database. He's suggesting some things to make it more human friendly and encapsulate related objects.
Everything is done except for when pulling forums. The data is all now much more organized and human-friendly!!
OK DONE!!
Theres the downloads for the library.
And here it is:
package DaniWebClient; import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.ws.rs.core.MultivaluedMap; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.WebResource; import com.sun.jersey.core.util.MultivaluedMapImpl; public class DaniWebClient { public static void main(String[] args) { /*I prepare the API*/ Client client = Client.create(); WebResource webResource = client.resource(""); /*User introduces name*/ System.out.println("Enter the member who's post you want to see: "); String user; Scanner scanIn = new Scanner(System.in); user = scanIn.nextLine(); StringBuilder username=new StringBuilder(user); /*I remove whitespaces except actual spaces*/ for (int i=0;i<username.length();i++) { if ((Character.isWhitespace(username.charAt(i))) && (username.charAt(i)!=' ')) { username.deleteCharAt(i); } } user = username.toString(); /*For some stupid reason, Java is stupid (no surprise there) and doesnt consider ALT+0160 a whitespace. I have to remove it manually*/ user = user.replace("\u00A0",""); /*I make sure that the user name isnt empty */ if (user.length()==0) { System.out.println("Please insert a valid member"); } else { /*I call the members method of the API and pass parameters by GET. POST not tested in Java*/ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); queryParams.add("username", user); /*Send it and wait for reply*/ String output = webResource.queryParams(queryParams).get(String.class); int first=0; int next=0; /*Finding where it says the post number in the response...*/ first=output.indexOf("\"posts\":\""); if (first==-1) /*-1 means it could not find it therefore no member exists*/ { System.out.println("Member not found!"); } else { do { /*I find the next quote that actually begins the post number*/ next = output.indexOf("\"",Integer.valueOf(first)); /*Not neccesary but in case Dani changes the array to something else....*/ if (next==-1) { break; } }while(next==0); /*VERY Ugly hack to get posts numbers. Tried with largest post numbers I could find (Dani's AFAIK)*/ String str2 = output.substring(first, next +15); Pattern replace = Pattern.compile("[^.0-9]"); Matcher matcher2 = replace.matcher(str2); String stringne=matcher2.replaceAll(""); if (output.length()==0) { System.out.println("Please insert a valid member"); } else { System.out.println("The total amounts of posts this member has is " + stringne ); } } } } }
Hehe. No changes yet!
I couldn't help myself...
Tried the jsonp:
function getJSON(){ var url = ''; $.getJSON(url + '?callback=?').done(function(json){ document.write(JSON.stringify(json)); }); } getJSON();
But kept getting this:
{"data":{"error":"Cachebuster detected: Please pass in an access token to retrieve non-cached results."}}
I noticed this happened with the 'nested' parameter for forums too (just straight url into browser bar) - is this expected?
A bit odd, as I got data from the direct url into browser:?
Edited by diafol ...