Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull in the user profile/settings/default publication/published posts #23

Merged
merged 10 commits into from
Dec 6, 2023

Conversation

patricker
Copy link
Contributor

@patricker patricker commented Dec 1, 2023

This PR adds several new endpoint calls to pull in the user profile/settings/published posts/get draft

This allows for:

  • Automatic USER_ID lookup
  • Automatic "Primary Publication" lookup (in this PR I actually remove the publication URL as a parameter, and default to the users default publication. They can then override it. I'm open to feedback)
  • Get published posts
  • Get existing draft body content back for continued editing.

I also made it so you can change the publication after api instantiation in case you want to change which publication you are working on; and by default it uses the users default publication.

I ran into a lot of issues because I have a custom_domain. This lead to all sorts of cookie issues.

  • To solve this I added one extra step to login to do a publication sign-in. This allows for custom domains to get the needed cookies to be able to make API calls, otherwise they don't work.

Some examples of the new calls:

api = Api(
            email=os.getenv("EMAIL"),
            password=os.getenv("PASSWORD"),
        )

user_id = api.get_user_id()
user_publication = api.get_user_primary_publication()
user_publications = api.get_user_publications()

# Get the published posts
posts = api.get_published_posts()

# change publication URL to something else
api.change_publication(user_publication)

# get the draft
draft = api.get_draft(drafts[3].get("id"))
# Conver the draft body back into a list of dicts for further modification
draft_body = json.loads(draft.get("draft_body"))

Adds details on how to find your user_id and how to set a password if you have an account that doesn't have one
@patricker patricker changed the title Update README.md Pull in the user profile/settings Dec 1, 2023
@patricker patricker changed the title Pull in the user profile/settings Pull in the user profile/settings/default publication/published posts Dec 1, 2023
@ma2za
Copy link
Owner

ma2za commented Dec 3, 2023

hey, thanks a lot, especially for the user id method. Can you put a deprecated warning on the publication_url parameter? I'll take it out in future versions.

@ma2za
Copy link
Owner

ma2za commented Dec 3, 2023

If the parameter is None, then set it to the primary publication.

@patricker
Copy link
Contributor Author

Yeah, will do.
I'm out of town, but I'll plan to update it tomorrow.

@patricker
Copy link
Contributor Author

@ma2za I couldn't find any reasonable way to mark a parameter in python as deprecated, and since Python doesn't allow Constructor overloading, I couldn't mark the "function" as deprecated either...

However, I think the approach I took to matching up a URL to the new "publication" object works well. Let me know what you think.

@ma2za ma2za merged commit e3235b8 into ma2za:main Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants