Skip to content

Commit

Permalink
Merge pull request #222 from praw-dev/mobile_banner
Browse files Browse the repository at this point in the history
Added support for Mobile Banner uploads. (#1902)
  • Loading branch information
LilSpazJoekp committed Dec 9, 2022
2 parents fc84a89 + 79d9351 commit db8c96d
Show file tree
Hide file tree
Showing 6 changed files with 1,092 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Async PRAW follows `semantic versioning <http://semver.org/>`_.
Unreleased
----------

**Added**

- :meth:`.delete_mobile_banner` to delete mobile banners.
- :meth:`.upload_mobile_banner` to upload mobile banners.

**Fixed**

- An issue with with iterating :class:`.ModNote` when a user has more than a hundred
Expand Down
44 changes: 44 additions & 0 deletions asyncpraw/models/reddit/subreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4096,6 +4096,22 @@ async def delete_image(self, name: str):
url = API_PATH["delete_sr_image"].format(subreddit=self.subreddit)
await self.subreddit._reddit.post(url, data={"img_name": name})

async def delete_mobile_banner(self):
"""Remove the current :class:`.Subreddit` (redesign) mobile banner.
Succeeds even if there is no mobile banner.
For example:
.. code-block:: python
subreddit = await reddit.subreddit("test")
await subreddit.stylesheet.delete_banner_hover_image()
"""
data = {"mobileBannerImage": ""}
await self._update_structured_styles(data)

async def delete_mobile_header(self):
"""Remove the current :class:`.Subreddit` mobile header.
Expand Down Expand Up @@ -4307,6 +4323,34 @@ async def upload_header(self, image_path: str) -> Dict[str, str]:
data={"upload_type": "header"}, image_path=image_path
)

async def upload_mobile_banner(self, image_path: str):
"""Upload an image for the :class:`.Subreddit`'s (redesign) mobile banner.
:param image_path: A path to a JPEG or PNG image.
For example:
.. code-block:: python
subreddit = await reddit.subreddit("test")
await subreddit.stylesheet.upload_mobile_banner("banner.png")
Fails if the :class:`.Subreddit` does not have an additional image defined.
:raises: ``prawcore.TooLarge`` if the overall request body is too large.
:raises: :class:`.RedditAPIException` if there are other issues with the
uploaded image. Unfortunately the exception info might not be very specific,
so try through the website with the same image to see what the problem
actually might be.
"""
image_type = "mobileBannerImage"
image_url = await self._upload_style_asset(
image_path=image_path, image_type=image_type
)
await self._update_structured_styles({image_type: image_url})

async def upload_mobile_header(self, image_path: str) -> Dict[str, str]:
"""Upload an image to be used as the :class:`.Subreddit`'s mobile header.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
{
"interactions": [
{
"request": {
"body": [
[
"grant_type",
"refresh_token"
],
[
"refresh_token",
"<REFRESH_TOKEN>"
]
],
"headers": {
"AUTHORIZATION": [
"Basic <BASIC_AUTH>"
],
"Accept-Encoding": [
"identity"
],
"Connection": [
"close"
],
"User-Agent": [
"<USER_AGENT> Async PRAW/7.6.2.dev0 asyncprawcore/2.3.0"
]
},
"method": "POST",
"uri": "https://www.reddit.com/api/v1/access_token"
},
"response": {
"body": {
"string": "{\"access_token\": \"<ACCESS_TOKEN>\", \"token_type\": \"bearer\", \"expires_in\": 86400, \"refresh_token\": \"<REFRESH_TOKEN>\", \"scope\": \"creddits modnote modcontributors modmail modconfig subscribe structuredstyles vote wikiedit mysubreddits submit modlog modposts modflair save modothers adsconversions read privatemessages report identity livemanage account modtraffic wikiread edit modwiki modself flair history\"}"
},
"headers": {
"Accept-Ranges": [
"bytes"
],
"Cache-Control": [
"private, max-age=3600"
],
"Connection": [
"close"
],
"Content-Length": [
"454"
],
"Content-Type": [
"application/json; charset=UTF-8"
],
"Date": [
"Fri, 09 Dec 2022 00:34:19 GMT"
],
"NEL": [
"{\"report_to\": \"w3-reporting-nel\", \"max_age\": 14400, \"include_subdomains\": false, \"success_fraction\": 0.2, \"failure_fraction\": 0.2}"
],
"Report-To": [
"{\"group\": \"w3-reporting-nel\", \"max_age\": 14400, \"include_subdomains\": true, \"endpoints\": [{ \"url\": \"https://w3-reporting-nel.reddit.com/reports\" }]}, {\"group\": \"w3-reporting\", \"max_age\": 14400, \"include_subdomains\": true, \"endpoints\": [{ \"url\": \"https://w3-reporting.reddit.com/reports\" }]}"
],
"Server": [
"snooserv"
],
"Set-Cookie": [
"edgebucket=EPDDnGPcPAp4XhPonG; Domain=reddit.com; Max-Age=63071999; Path=/; secure"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubdomains"
],
"Via": [
"1.1 varnish"
],
"X-Content-Type-Options": [
"nosniff"
],
"X-Frame-Options": [
"SAMEORIGIN"
],
"X-XSS-Protection": [
"1; mode=block"
],
"x-moose": [
"majestic"
],
"x-ratelimit-remaining": [
"299"
],
"x-ratelimit-reset": [
"341"
],
"x-ratelimit-used": [
"1"
]
},
"status": {
"code": 200,
"message": "OK"
},
"url": "https://www.reddit.com/api/v1/access_token"
}
},
{
"request": {
"body": [
[
"api_type",
"json"
],
[
"mobileBannerImage",
""
]
],
"headers": {
"Accept-Encoding": [
"identity"
],
"Authorization": [
"bearer <ACCESS_TOKEN>"
],
"Cookie": [
"edgebucket=EPDDnGPcPAp4XhPonG"
],
"User-Agent": [
"<USER_AGENT> Async PRAW/7.6.2.dev0 asyncprawcore/2.3.0"
]
},
"method": "PATCH",
"uri": "https://oauth.reddit.com/api/v1/structured_styles/<TEST_SUBREDDIT>?raw_json=1"
},
"response": {
"body": {
"string": "{}"
},
"headers": {
"Accept-Ranges": [
"bytes"
],
"Cache-Control": [
"private, s-maxage=0, max-age=0, must-revalidate, no-store"
],
"Connection": [
"keep-alive"
],
"Content-Length": [
"2"
],
"Content-Type": [
"application/json; charset=UTF-8"
],
"Date": [
"Fri, 09 Dec 2022 00:34:20 GMT"
],
"Expires": [
"-1"
],
"NEL": [
"{\"report_to\": \"w3-reporting-nel\", \"max_age\": 14400, \"include_subdomains\": false, \"success_fraction\": 0.2, \"failure_fraction\": 0.2}"
],
"Report-To": [
"{\"group\": \"w3-reporting-nel\", \"max_age\": 14400, \"include_subdomains\": true, \"endpoints\": [{ \"url\": \"https://w3-reporting-nel.reddit.com/reports\" }]}, {\"group\": \"w3-reporting\", \"max_age\": 14400, \"include_subdomains\": true, \"endpoints\": [{ \"url\": \"https://w3-reporting.reddit.com/reports\" }]}"
],
"Server": [
"snooserv"
],
"Set-Cookie": [
"redesign_optout=true; Domain=reddit.com; Max-Age=94607999; Path=/; expires=Mon, 08-Dec-2025 00:34:19 GMT; secure",
"session_tracker=fbeimfmkbpieehfrjq.0.1670546059960.Z0FBQUFBQmprb0tNLWhSMjh0RDhyTWZUWS1pcE13TWZ4SWhFR0MtS0FMQm1Gb0djN0NfOUhEYkNHdm1nVlpjMjZRZVA3NngwMjQwTFJqeUpBYUktUFB0WVdrZk8zWm1pS2RmNEJ4djM2NEIyY29EM21GRGNmdWpabzBDajRfY1lyWHRVeFRFcm9MbGY; Domain=reddit.com; Max-Age=7199; Path=/; expires=Fri, 09-Dec-2022 02:34:20 GMT; secure"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubdomains"
],
"Via": [
"1.1 varnish"
],
"X-Content-Type-Options": [
"nosniff"
],
"X-Frame-Options": [
"SAMEORIGIN"
],
"X-XSS-Protection": [
"1; mode=block"
],
"x-moose": [
"majestic"
],
"x-ratelimit-remaining": [
"599.0"
],
"x-ratelimit-reset": [
"341"
],
"x-ratelimit-used": [
"1"
],
"x-ua-compatible": [
"IE=edge"
]
},
"status": {
"code": 200,
"message": "OK"
},
"url": "https://oauth.reddit.com/api/v1/structured_styles/<TEST_SUBREDDIT>?raw_json=1"
}
}
],
"version": 1
}
Loading

0 comments on commit db8c96d

Please sign in to comment.