4
4
import json
5
5
import os
6
6
7
+ class MmdvLogoutCommand (sublime_plugin .TextCommand ):
8
+ def run (self , edit ):
9
+ if 'MEMDEV_ACCESS' in os .environ :
10
+ del os .environ ['MEMDEV_ACCESS' ]
11
+
7
12
class MmdvCommand (sublime_plugin .TextCommand ):
8
13
def __init__ (self , view ):
9
14
super ().__init__ (view )
10
- self .BASE_URL = 'localhost:3000'
15
+ self .BASE_URL = 'mem.dev'
16
+ self .connection = 'https'
11
17
self .__title = ''
12
- self .__source = ''
13
18
self .__content = ''
14
19
15
20
def __api (self , uri , params , method = 'POST' ):
16
- conn = http .client .HTTPConnection (self .BASE_URL )
21
+ if self .connection == 'http' :
22
+ conn = http .client .HTTPConnection (self .BASE_URL )
23
+ else :
24
+ conn = http .client .HTTPSConnection (self .BASE_URL )
17
25
headers = {
18
26
'Content-type' : 'application/json'
19
27
}
@@ -27,22 +35,16 @@ def __api(self, uri, params, method = 'POST'):
27
35
response = conn .getresponse ()
28
36
return json .loads (response .read ().decode ())
29
37
30
- def __show_source_panel (self ):
31
- window = self .view .window ()
32
-
33
- window .show_input_panel ("Source" , "" , self .on_source_input_done , None , None )
34
-
35
38
def on_token_input_done (self , input_val ):
36
39
params = {'id' : input_val }
37
40
response_json = self .__api ('/api/v2/authorize/ext_auth' , params )
38
41
39
42
if response_json ['token' ]:
40
43
os .environ ['MEMDEV_ACCESS' ] = str (response_json ['token' ])
41
44
42
- self .__show_source_panel ()
45
+ self .send_snippet ()
43
46
44
- def on_source_input_done (self , input_val ):
45
- self .__source = input_val
47
+ def send_snippet (self ):
46
48
syntax = self .view .settings ().get ("syntax" )
47
49
48
50
if 'Plain text' not in syntax :
@@ -53,7 +55,6 @@ def on_source_input_done(self, input_val):
53
55
params = {
54
56
'content' : self .__content ,
55
57
'title' : self .__title ,
56
- 'source' : input_val ,
57
58
'syntax' : syntax ,
58
59
'topic' : syntax
59
60
}
@@ -71,8 +72,6 @@ def on_title_input_done(self, input_string):
71
72
window .show_input_panel ("Enter your auth token" , "" , self .on_token_input_done , None , None )
72
73
return
73
74
74
- self .__show_source_panel ()
75
-
76
75
def run (self , edit ):
77
76
window = self .view .window ()
78
77
view = self .view
@@ -81,4 +80,4 @@ def run(self, edit):
81
80
region1 = sel [0 ]
82
81
self .__content = view .substr (region1 )
83
82
84
- window .show_input_panel ("I just learned how to..." , "" , self .on_title_input_done , None , None )
83
+ window .show_input_panel ("I just learned how to..." , "" , self .on_title_input_done , None , None )
0 commit comments