Skip to content

Commit

Permalink
feat: added logout
Browse files Browse the repository at this point in the history
  • Loading branch information
jtundag committed Jul 27, 2020
1 parent 3b2f104 commit d171632
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
6 changes: 6 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"caption": "Mem.dev: Logout",
"command": "mmdv_logout"
}
]
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Mem.dev Sublime Text Plugin

![./images/st_demo.gif](./images/st_demo.gif)

### Logout

To logout your account, just do `Ctrl + Shift + P` (for windows) and find `Mem.dev: Logout` command.
Binary file added images/st_demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 14 additions & 15 deletions mmdv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@
import json
import os

class MmdvLogoutCommand(sublime_plugin.TextCommand):
def run(self, edit):
if 'MEMDEV_ACCESS' in os.environ:
del os.environ['MEMDEV_ACCESS']

class MmdvCommand(sublime_plugin.TextCommand):
def __init__(self, view):
super().__init__(view)
self.BASE_URL = 'localhost:3000'
self.BASE_URL = 'mem.dev'
self.connection = 'https'
self.__title = ''
self.__source = ''
self.__content = ''

def __api(self, uri, params, method = 'POST'):
conn = http.client.HTTPConnection(self.BASE_URL)
if self.connection == 'http':
conn = http.client.HTTPConnection(self.BASE_URL)
else:
conn = http.client.HTTPSConnection(self.BASE_URL)
headers = {
'Content-type': 'application/json'
}
Expand All @@ -27,22 +35,16 @@ def __api(self, uri, params, method = 'POST'):
response = conn.getresponse()
return json.loads(response.read().decode())

def __show_source_panel(self):
window = self.view.window()

window.show_input_panel("Source", "", self.on_source_input_done, None, None)

def on_token_input_done(self, input_val):
params = {'id': input_val}
response_json = self.__api('/api/v2/authorize/ext_auth', params)

if response_json['token']:
os.environ['MEMDEV_ACCESS'] = str(response_json['token'])

self.__show_source_panel()
self.send_snippet()

def on_source_input_done(self, input_val):
self.__source = input_val
def send_snippet(self):
syntax = self.view.settings().get("syntax")

if 'Plain text' not in syntax:
Expand All @@ -53,7 +55,6 @@ def on_source_input_done(self, input_val):
params = {
'content': self.__content,
'title': self.__title,
'source': input_val,
'syntax': syntax,
'topic': syntax
}
Expand All @@ -71,8 +72,6 @@ def on_title_input_done(self, input_string):
window.show_input_panel("Enter your auth token", "", self.on_token_input_done, None, None)
return

self.__show_source_panel()

def run(self, edit):
window = self.view.window()
view = self.view
Expand All @@ -81,4 +80,4 @@ def run(self, edit):
region1 = sel[0]
self.__content = view.substr(region1)

window.show_input_panel("I just learned how to...", "", self.on_title_input_done, None, None)
window.show_input_panel("I just learned how to...", "", self.on_title_input_done, None, None)

0 comments on commit d171632

Please sign in to comment.