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

Dev #54

Merged
merged 2 commits into from
Jul 31, 2024
Merged

Dev #54

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
12 changes: 3 additions & 9 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
:doc: https://simperium.com/docs/reference/http/#auth
"""

import base64
import functools
import json
import logging
Expand All @@ -22,16 +21,11 @@
__all__ = ["Simplenote"]


SIMPLENOTE_APP_ID: str = "chalk-bump-f49"
SIMPLENOTE_APP_KEY: str = base64.b64decode("YzhjMmI4NjMzNzE1NGNkYWJjOTg5YjIzZTMwYzZiZjQ=").decode("utf-8")
SIMPLENOTE_BUCKET: str = "note"


class URL:
BASE: str = "simperium.com/1"
AUTH = f"https://auth.{BASE}"
DATA = f"https://api.{BASE}/{SIMPLENOTE_APP_ID}/{SIMPLENOTE_BUCKET}"
__auth = f"{AUTH}/{SIMPLENOTE_APP_ID}/authorize/"
DATA = f"https://api.{BASE}/{CONFIG.SIMPLENOTE_APP_ID}/{CONFIG.SIMPLENOTE_BUCKET}"
__auth = f"{AUTH}/{CONFIG.SIMPLENOTE_APP_ID}/authorize/"
__index = DATA + "/index"
__retrieve = DATA + "/i/%s"
__modify = __retrieve
Expand Down Expand Up @@ -113,7 +107,7 @@ def authenticate(username: str, password: str):
response = request(
URL.auth(),
method="POST",
headers={"X-Simperium-API-Key": SIMPLENOTE_APP_KEY},
headers={"X-Simperium-API-Key": CONFIG.SIMPLENOTE_APP_KEY},
data={"username": username, "password": password},
data_as_json=False,
)
Expand Down
15 changes: 15 additions & 0 deletions gui.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import logging
import os
from typing import Optional

import sublime

from ._config import CONFIG


logger = logging.getLogger()


__all__ = [
"edit_settings",
"show_message",
"remove_status",
"get_view_window",
Expand All @@ -29,6 +33,17 @@
# SETTINGS.add_on_change("password", reload_if_needed)


def edit_settings():
# sublime.run_command("open_file", {"file": CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH})
sublime.run_command(
"edit_settings",
{
"base_file": os.path.join(CONFIG.SIMPLENOTE_PACKAGE_DIR, CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH),
"default": "// Simplenote Settings - User\n{\n\t$0\n}\n",
},
)


def _show_message(message: str = ""):
if not isinstance(message, str):
try:
Expand Down
10 changes: 3 additions & 7 deletions simplenotecommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sublime_plugin

from ._config import CONFIG
from .gui import close_view, open_view, remove_status, show_message
from .gui import close_view, edit_settings, open_view, remove_status, show_message
from .models import Note
from .operations import NoteCreator, NoteDeleter, NotesIndicator, NoteUpdater, OperationManager
from .simplenote import clear_orphaned_filepaths, on_note_changed
Expand Down Expand Up @@ -248,19 +248,15 @@ def start():
global SIMPLENOTE_STARTED

settings = sublime.load_settings(CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH)
logger.info(("SIMPLENOTE_SETTINGS_FILE_PATH", CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH))
username = settings.get("username")
password = settings.get("password")

if username and password:
sync()
SIMPLENOTE_STARTED = True
else:
sublime.active_window().open_file(CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH)
show_message(
"Simplenote: Please configure username/password, Please check settings file: %s"
% CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH
)
edit_settings()
show_message("Simplenote: Please configure username/password, Please check settings file.")
sublime.set_timeout(remove_status, 2000)
SIMPLENOTE_STARTED = False
return SIMPLENOTE_STARTED
Expand Down