Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
- Nested color and highlight spans override inherited styles of the same type
without creating duplicate ProseMirror marks or changing sibling styles.
Repeated style properties use the last nonempty declaration.
- `Api.get_drafts()` now asks for drafts by default. Substack rejects the
request with `400 Invalid value` when no filter is sent, so calling it
without arguments always failed.

### Development

Expand Down
6 changes: 4 additions & 2 deletions substack/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,13 @@ def get_posts(self) -> dict:

return Api._handle_response(response=response)

def get_drafts(self, filter=None, offset=None, limit=None):
def get_drafts(self, filter="draft", offset=None, limit=None):
"""
List the publication's drafts.

Args:
filter:
filter: Which posts to list. Substack rejects the request when
this is missing.
offset:
limit:

Expand Down
16 changes: 16 additions & 0 deletions tests/substack/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@ def test_get_drafts_extracts_posts_from_response_envelope(self):

self.assertEqual(api.get_drafts(), [{"id": 42}])

def test_get_drafts_asks_for_drafts_by_default(self):
# Substack rejects the request with a 400 unless a filter is sent.
api = Api.__new__(Api)
api.publication_url = "https://writer.substack.com/api/v1"
api._session = Mock()
response = Mock(status_code=200)
response.json.return_value = {"posts": []}
api._session.get.return_value = response

api.get_drafts(limit=5)

api._session.get.assert_called_once_with(
"https://writer.substack.com/api/v1/drafts",
params={"filter": "draft", "offset": None, "limit": 5},
)

@pytest.mark.live
@_e2e
def test_get_posts(self):
Expand Down
Loading