Skip to content

Commit 6fe1bcf

Browse files
committed
#6: + get cookies per room or host
1 parent 4fb5705 commit 6fe1bcf

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

src/main/java/org/sobotics/chatexchange/chat/ChatHost.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,17 @@ public String getName() {
3131
public String getBaseUrl() {
3232
return baseUrl;
3333
}
34+
35+
/**
36+
* Compares the host to another object
37+
* @param otherHost other object
38+
* @return true, if the name is the same
39+
*/
40+
public boolean equals(ChatHost otherHost) {
41+
if (otherHost == null)
42+
return false;
43+
44+
return this.name.equals(otherHost.name);
45+
}
3446

3547
}

src/main/java/org/sobotics/chatexchange/chat/Room.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,14 @@ public RoomThumbs getThumbs() {
618618
public ChatHost getHost() {
619619
return host;
620620
}
621+
622+
/**
623+
* Returns the cookies used to post in this room
624+
* @return cookies as Map
625+
*/
626+
public Map<String, String> getCookies() {
627+
return this.cookies;
628+
}
621629

622630
void close() {
623631
executor.shutdown();

src/main/java/org/sobotics/chatexchange/chat/StackExchangeClient.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,22 @@ public void setAutoCreateAccount(boolean autoCreateAccount) {
247247
this.autoCreateAccount = autoCreateAccount;
248248
}
249249

250+
250251
/**
251-
* Returns the cookies the library uses
252-
* @return Cookies
252+
* Returns the cookies for the first room with the given host
253+
* @param host {@link ChatHost} to search for
254+
* @return null, if no room with the given {@link ChatHost} was found
253255
*/
254-
public Map<String, String> getCookies() {
255-
return this.cookies;
256+
public Map<String, String> getCookies(ChatHost host) {
257+
for (Room room : this.rooms) {
258+
ChatHost roomHost = room.getHost();
259+
260+
if (host.equals(roomHost)) {
261+
return room.getCookies();
262+
}
263+
}
264+
265+
return null;
256266
}
257267

258268
/**

0 commit comments

Comments
 (0)