Created
September 12, 2011 22:19
-
-
Save panchicore/1212634 to your computer and use it in GitHub Desktop.
Try to use Java Reslet Framework with json served by python/django
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.Serializable; | |
public class Comment implements Serializable{ | |
private static final long serialVersionUID = 1L; | |
private String comment; | |
private String date; | |
private String date_since; | |
private int id; | |
private String resource_uri; | |
private User user; | |
public Comment(String comment, String date, String date_since, int id, | |
String resource_uri, User user) { | |
super(); | |
this.comment = comment; | |
this.date = date; | |
this.date_since = date_since; | |
this.id = id; | |
this.resource_uri = resource_uri; | |
this.user = user; | |
} | |
public String getComment() { | |
return comment; | |
} | |
public void setComment(String comment) { | |
this.comment = comment; | |
} | |
public String getDate() { | |
return date; | |
} | |
public void setDate(String date) { | |
this.date = date; | |
} | |
public String getDate_since() { | |
return date_since; | |
} | |
public void setDate_since(String date_since) { | |
this.date_since = date_since; | |
} | |
public int getId() { | |
return id; | |
} | |
public void setId(int id) { | |
this.id = id; | |
} | |
public String getResource_uri() { | |
return resource_uri; | |
} | |
public void setResource_uri(String resource_uri) { | |
this.resource_uri = resource_uri; | |
} | |
public User getUser() { | |
return user; | |
} | |
public void setUser(User user) { | |
this.user = user; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.Serializable; | |
import java.util.ArrayList; | |
public class CommentDTO implements Serializable{ | |
private static final long serialVersionUID = 1L; | |
private Meta meta; | |
private ArrayList<Comment> objects; | |
public CommentDTO(Meta meta, ArrayList<Comment> objects) { | |
super(); | |
this.meta = meta; | |
this.objects = objects; | |
} | |
public Meta getMeta() { | |
return meta; | |
} | |
public void setMeta(Meta meta) { | |
this.meta = meta; | |
} | |
public ArrayList<Comment> getObjects() { | |
return objects; | |
} | |
public void setObjects(ArrayList<Comment> objects) { | |
this.objects = objects; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.restlet.resource.Delete; | |
import org.restlet.resource.Get; | |
import org.restlet.resource.Put; | |
public interface CommentResource { | |
@Get | |
public CommentDTO retrieve(); | |
@Put | |
public void store(CommentDTO comment); | |
@Delete | |
public void remove(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import javax.swing.JOptionPane; | |
import org.restlet.resource.ClientResource; | |
public class Main { | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
ClientResource cr = new ClientResource("http://x.oule.co/api/v1/comment/?format=json&limit=1"); | |
try { | |
cr.get().write(System.out); | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
CommentResource resource = cr.wrap(CommentResource.class); | |
CommentDTO comments = resource.retrieve(); | |
System.out.println("\n---->"+ comments); | |
if(comments!=null){ | |
System.out.println("---->"+ comments); | |
} | |
System.out.println("END"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.Serializable; | |
public class Meta implements Serializable{ | |
private static final long serialVersionUID = 1L; | |
private int limit; | |
private String next = null; | |
private int offset = 0; | |
private String previous = null; | |
private int total_count; | |
public Meta(int limit, String next, int offset, String previous, | |
int total_count) { | |
super(); | |
this.limit = limit; | |
this.next = next; | |
this.offset = offset; | |
this.previous = previous; | |
this.total_count = total_count; | |
} | |
public int getLimit() { | |
return limit; | |
} | |
public void setLimit(int limit) { | |
this.limit = limit; | |
} | |
public String getNext() { | |
return next; | |
} | |
public void setNext(String next) { | |
this.next = next; | |
} | |
public int getOffset() { | |
return offset; | |
} | |
public void setOffset(int offset) { | |
this.offset = offset; | |
} | |
public String getPrevious() { | |
return previous; | |
} | |
public void setPrevious(String previous) { | |
this.previous = previous; | |
} | |
public int getTotal_count() { | |
return total_count; | |
} | |
public void setTotal_count(int total_count) { | |
this.total_count = total_count; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"meta": {"limit": 20, "next": null, "offset": 0, "previous": null, "total_count": 8}, "objects": [{"comment": "Muy bacano el lugar!", "date": "2011-09-07T11:07:01", "date_since": "5 days, 6 hours", "id": "1", "resource_uri": "/api/v1/comment/1/", "user": {"date_joined": "2011-08-17T20:18:43.298648", "first_name": "", "id": "1", "last_login": "2011-09-08T16:49:42.055120", "last_name": "", "resource_uri": "/api/v1/user/1/", "username": "admin"}}, {"comment": "Prueba de comment count (2)", "date": "2011-09-07T11:08:53", "date_since": "5 days, 6 hours", "id": "2", "resource_uri": "/api/v1/comment/2/", "user": {"date_joined": "2011-08-17T20:18:43.298648", "first_name": "", "id": "1", "last_login": "2011-09-08T16:49:42.055120", "last_name": "", "resource_uri": "/api/v1/user/1/", "username": "admin"}}, {"comment": "Yo vivo aqui.", "date": "2011-09-07T11:12:31", "date_since": "5 days, 6 hours", "id": "3", "resource_uri": "/api/v1/comment/3/", "user": {"date_joined": "2011-08-17T20:18:43.298648", "first_name": "", "id": "1", "last_login": "2011-09-08T16:49:42.055120", "last_name": "", "resource_uri": "/api/v1/user/1/", "username": "admin"}}, {"comment": "Luis Pallares vive aqui", "date": "2011-09-09T11:05:23.898224", "date_since": "3 days, 6 hours", "id": "4", "resource_uri": "/api/v1/comment/4/", "user": {"date_joined": "2011-08-17T20:18:43.298648", "first_name": "", "id": "1", "last_login": "2011-09-08T16:49:42.055120", "last_name": "", "resource_uri": "/api/v1/user/1/", "username": "admin"}}, {"comment": "Gracias a todos por sus comentarios la verdad me gusta mucho participar en esta app.", "date": "2011-09-09T11:05:23.899687", "date_since": "3 days, 6 hours", "id": "5", "resource_uri": "/api/v1/comment/5/", "user": {"date_joined": "2011-08-17T20:18:43.298648", "first_name": "", "id": "1", "last_login": "2011-09-08T16:49:42.055120", "last_name": "", "resource_uri": "/api/v1/user/1/", "username": "admin"}}, {"comment": "Hola mundo", "date": "2011-09-09T11:06:15.551706", "date_since": "3 days, 6 hours", "id": "6", "resource_uri": "/api/v1/comment/6/", "user": {"date_joined": "2011-08-17T20:18:43.298648", "first_name": "", "id": "1", "last_login": "2011-09-08T16:49:42.055120", "last_name": "", "resource_uri": "/api/v1/user/1/", "username": "admin"}}, {"comment": "I have been slowing learning and building my first android app. I'm VERY new to java but have already done a couple of projects in C#, VB.NET (back in the day), Objective-C (have 6 apps in the store) and Fortran (waaaaaaaaaaaaaaaaaaaay back in the day ;)", "date": "2011-09-09T11:08:58.489134", "date_since": "3 days, 6 hours", "id": "7", "resource_uri": "/api/v1/comment/7/", "user": {"date_joined": "2011-08-17T20:18:43.298648", "first_name": "", "id": "1", "last_login": "2011-09-08T16:49:42.055120", "last_name": "", "resource_uri": "/api/v1/user/1/", "username": "admin"}}, {"comment": "Oops! it was my fault all along, somehow I had TWO layouts (one for different resolutions), the one being used on my device did not have the proper ListView and Spinner ID. That alternative layout was collapse into a folder and I just forgot about it (I had paused development of the app for about 2 month until I actually got a device to test on).", "date": "2011-09-09T11:09:41.935901", "date_since": "3 days, 6 hours", "id": "8", "resource_uri": "/api/v1/comment/8/", "user": {"date_joined": "2011-08-17T20:18:43.298648", "first_name": "", "id": "1", "last_login": "2011-09-08T16:49:42.055120", "last_name": "", "resource_uri": "/api/v1/user/1/", "username": "admin"}}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.Serializable; | |
public class User implements Serializable{ | |
private static final long serialVersionUID = 1L; | |
private String date_joined; | |
private String first_name; | |
private int id; | |
private String last_login; | |
private String last_name; | |
private String resource_uri; | |
private String username; | |
public User(String date_joined, String first_name, String last_name, | |
String last_login, int id, String resource_uri, String username) { | |
super(); | |
this.date_joined = date_joined; | |
this.first_name = first_name; | |
this.last_name = last_name; | |
this.last_login = last_login; | |
this.id = id; | |
this.resource_uri = resource_uri; | |
this.username = username; | |
} | |
public String getDate_joined() { | |
return date_joined; | |
} | |
public void setDate_joined(String date_joined) { | |
this.date_joined = date_joined; | |
} | |
public String getFirst_name() { | |
return first_name; | |
} | |
public void setFirst_name(String first_name) { | |
this.first_name = first_name; | |
} | |
public String getLast_name() { | |
return last_name; | |
} | |
public void setLast_name(String last_name) { | |
this.last_name = last_name; | |
} | |
public String getLast_login() { | |
return last_login; | |
} | |
public void setLast_login(String last_login) { | |
this.last_login = last_login; | |
} | |
public int getId() { | |
return id; | |
} | |
public void setId(int id) { | |
this.id = id; | |
} | |
public String getResource_uri() { | |
return resource_uri; | |
} | |
public void setResource_uri(String resource_uri) { | |
this.resource_uri = resource_uri; | |
} | |
public String getUsername() { | |
return username; | |
} | |
public void setUsername(String username) { | |
this.username = username; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment