Skip to content

Commit ecab282

Browse files
committed
Add support for add subreddit to multireddit api method
1 parent 4cbb047 commit ecab282

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/main/java/org/quantumbadger/redreader/reddit/RedditAPI.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import androidx.annotation.Nullable;
2626
import androidx.appcompat.app.AppCompatActivity;
2727

28+
import org.json.JSONObject;
2829
import org.quantumbadger.redreader.account.RedditAccount;
2930
import org.quantumbadger.redreader.activities.BugReportActivity;
3031
import org.quantumbadger.redreader.cache.CacheManager;
@@ -65,6 +66,7 @@
6566
import java.util.ArrayList;
6667
import java.util.Collection;
6768
import java.util.Collections;
69+
import java.util.HashMap;
6870
import java.util.LinkedList;
6971
import java.util.List;
7072
import java.util.Map;
@@ -959,6 +961,35 @@ public void onFailure(@NonNull final RRError error) {
959961
));
960962
}
961963

964+
public static void addSubredditToMultireddit(
965+
final CacheManager cm,
966+
final APIResponseHandler.ActionResponseHandler handler,
967+
final RedditAccount user,
968+
final String multiredditName,
969+
final String subredditName,
970+
final Context context) {
971+
972+
final Uri.Builder builder = Constants.Reddit.getUriBuilder(
973+
Constants.Reddit.PATH_MULTIREDDIT)
974+
.appendPath("user")
975+
.appendPath(user.username)
976+
.appendPath("m")
977+
.appendPath(multiredditName)
978+
.appendPath("r")
979+
.appendPath(subredditName);
980+
981+
final Map<String, String> jsonData = new HashMap<>();
982+
jsonData.put("name", subredditName);
983+
984+
cm.makeRequest(createPutRequest(
985+
UriString.from(builder.build()),
986+
user,
987+
new ArrayList<>(Collections.singleton(
988+
new PostField("model", new JSONObject(jsonData).toString()))),
989+
context,
990+
new GenericResponseHandler(handler)));
991+
}
992+
962993
@Nullable
963994
private static APIResponseHandler.APIFailureType findFailureType(final JsonValue response) {
964995

0 commit comments

Comments
 (0)