Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Commit

Permalink
TFJ-120 include rate limit status in TwitterResponse
Browse files Browse the repository at this point in the history
git-svn-id: http://yusuke.homeip.net/svn/twitter4j/trunk@268 117b7e0d-5933-0410-9d29-ab41bb01d86b
  • Loading branch information
yusuke committed May 6, 2009
1 parent 45af2f0 commit edce0e1
Show file tree
Hide file tree
Showing 14 changed files with 240 additions and 346 deletions.
53 changes: 15 additions & 38 deletions src/main/java/twitter4j/DirectMessage.java
Expand Up @@ -29,6 +29,7 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import twitter4j.http.Response;

import java.util.ArrayList;
import java.util.Date;
Expand All @@ -48,12 +49,19 @@ public class DirectMessage extends TwitterResponse implements java.io.Serializab
private String recipient_screen_name;
private static final long serialVersionUID = -3253021825891789737L;

/*package*/DirectMessage(Element elem, Twitter twitter) throws TwitterException {
super();
/*package*/DirectMessage(Response res, Twitter twitter) throws TwitterException {
super(res);
init(res, res.asDocument().getDocumentElement(), twitter);
}
/*package*/DirectMessage(Response res, Element elem, Twitter twitter) throws TwitterException {
super(res);
init(res, elem, twitter);
}
private void init(Response res, Element elem, Twitter twitter) throws TwitterException{
ensureRootNodeNameIs("direct_message", elem);
sender = new User((Element) elem.getElementsByTagName("sender").item(0),
sender = new User(res, (Element) elem.getElementsByTagName("sender").item(0),
twitter);
recipient = new User((Element) elem.getElementsByTagName("recipient").item(0),
recipient = new User(res, (Element) elem.getElementsByTagName("recipient").item(0),
twitter);
id = getChildInt("id", elem);
text = getChildText("text", elem);
Expand Down Expand Up @@ -109,8 +117,9 @@ public User getRecipient() {
}

/*package*/
static List<DirectMessage> constructDirectMessages(Document doc,
static List<DirectMessage> constructDirectMessages(Response res,
Twitter twitter) throws TwitterException {
Document doc = res.asDocument();
if (isRootNodeNilClasses(doc)) {
return new ArrayList<DirectMessage>(0);
} else {
Expand All @@ -122,7 +131,7 @@ static List<DirectMessage> constructDirectMessages(Document doc,
List<DirectMessage> messages = new ArrayList<DirectMessage>(size);
for (int i = 0; i < size; i++) {
Element status = (Element) list.item(i);
messages.add(new DirectMessage(status, twitter));
messages.add(new DirectMessage(res, status, twitter));
}
return messages;
} catch (TwitterException te) {
Expand All @@ -135,38 +144,6 @@ static List<DirectMessage> constructDirectMessages(Document doc,
}
}

/*
<?xml version="1.0" encoding="UTF-8"?>
<direct_message>
<id>3611242</id>
<text>test</text>
<sender_id>4933401</sender_id>
<recipient_id>6459452</recipient_id>
<created_at>Thu Jun 07 06:36:21 +0000 2007</created_at>
<sender_screen_name>yusukey</sender_screen_name>
<recipient_screen_name>fast_ts</recipient_screen_name>
<sender>
<id>4933401</id>
<name>Yusuke Yamamoto</name>
<screen_name>yusukey</screen_name>
<location>Tokyo</location>
<description>http://yusuke.homeip.net/diary/</description>
<profile_image_url>http://assets3.twitter.com/system/user/profile_image/4933401/normal/1023824_2048059614.jpg?1176769649</profile_image_url>
<url>http://yusuke.homeip.net/diary/</url>
<protected>false</protected>
</sender>
<recipient>
<id>6459452</id>
<name>fast_ts</name>
<screen_name>fast_ts</screen_name>
<location></location>
<description></description>
<profile_image_url>http://assets1.twitter.com/system/user/profile_image/6459452/normal/_____-1.gif?1180974738</profile_image_url>
<url></url>
<protected>true</protected>
</recipient>
</direct_message>
*/
@Override
public int hashCode() {
return id;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/twitter4j/ExtendedUser.java
Expand Up @@ -27,6 +27,7 @@
package twitter4j;

import org.w3c.dom.Element;
import twitter4j.http.Response;

import java.util.Date;

Expand Down Expand Up @@ -81,8 +82,9 @@ public class ExtendedUser extends UserWithStatus {
private int statusesCount;
private static final long serialVersionUID = -8486230870587454252L;

public ExtendedUser(Element elem, Twitter twitter) throws TwitterException {
super(elem, twitter);
public ExtendedUser(Response res, Twitter twitter) throws TwitterException {
super(res, twitter);
Element elem = res.asDocument().getDocumentElement();
profileBackgroundColor = getChildText("profile_background_color", elem);
profileTextColor = getChildText("profile_text_color", elem);
profileLinkColor = getChildText("profile_link_color", elem);
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/twitter4j/IDs.java
Expand Up @@ -26,8 +26,9 @@
*/
package twitter4j;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.w3c.dom.Element;
import twitter4j.http.Response;

import java.util.Arrays;

Expand All @@ -40,8 +41,9 @@ public class IDs extends TwitterResponse {
private int[] ids;
private static final long serialVersionUID = -6585026560164704953L;

/*package*/ IDs(Element elem) throws TwitterException {
super();
/*package*/ IDs(Response res) throws TwitterException {
super(res);
Element elem = res.asDocument().getDocumentElement();
ensureRootNodeNameIs("ids", elem);
NodeList idlist = elem.getElementsByTagName("id");
ids = new int[idlist.getLength()];
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/twitter4j/RateLimitStatus.java
Expand Up @@ -27,6 +27,7 @@
package twitter4j;

import org.w3c.dom.Element;
import twitter4j.http.Response;

import java.util.Date;

Expand All @@ -41,8 +42,9 @@ public class RateLimitStatus extends TwitterResponse {
private Date dateTime;
private static final long serialVersionUID = -2326597301406666858L;

/* package */ RateLimitStatus(Element elem) throws TwitterException {
super();
/* package */ RateLimitStatus(Response res) throws TwitterException {
super(res);
Element elem = res.asDocument().getDocumentElement();
remainingHits = getChildInt("remaining-hits", elem);
hourlyLimit = getChildInt("hourly-limit", elem);
resetTimeInSeconds = getChildInt("reset-time-in-seconds", elem);
Expand Down
26 changes: 20 additions & 6 deletions src/main/java/twitter4j/Status.java
Expand Up @@ -29,6 +29,7 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import twitter4j.http.Response;

import java.util.ArrayList;
import java.util.Date;
Expand Down Expand Up @@ -71,11 +72,23 @@ public class Status extends TwitterResponse implements java.io.Serializable {
private boolean isFavorited;
private static final long serialVersionUID = 1608000492860584608L;

/*package*/Status(Element elem, Twitter twitter) throws TwitterException {
super();
/*package*/Status(Response res, Twitter twitter) throws TwitterException {
super(res);
Element elem = res.asDocument().getDocumentElement();
init(res, elem, twitter);
}

/*package*/Status(Response res, Element elem, Twitter twitter) throws
TwitterException {
super(res);
init(res, elem, twitter);
}

private void init(Response res, Element elem, Twitter twitter) throws
TwitterException {
ensureRootNodeNameIs("status", elem);
user = new User((Element) elem.getElementsByTagName("user").item(0),
twitter);
user = new User(res, (Element) elem.getElementsByTagName("user").item(0)
, twitter);
id = getChildLong("id", elem);
text = getChildText("text", elem);
source = getChildText("source", elem);
Expand Down Expand Up @@ -179,8 +192,9 @@ public User getUser() {
}

/*package*/
static List<Status> constructStatuses(Document doc,
static List<Status> constructStatuses(Response res,
Twitter twitter) throws TwitterException {
Document doc = res.asDocument();
if (isRootNodeNilClasses(doc)) {
return new ArrayList<Status>(0);
} else {
Expand All @@ -192,7 +206,7 @@ static List<Status> constructStatuses(Document doc,
List<Status> statuses = new ArrayList<Status>(size);
for (int i = 0; i < size; i++) {
Element status = (Element) list.item(i);
statuses.add(new Status(status, twitter));
statuses.add(new Status(res, status, twitter));
}
return statuses;
} catch (TwitterException te) {
Expand Down

0 comments on commit edce0e1

Please sign in to comment.