Skip to content

Commit

Permalink
release 0.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
xjsender committed Jul 16, 2015
1 parent 57e609e commit 256dfc2
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 17 deletions.
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ Release History
---------------


0.2.4 (2015-07-16)
++++++++++++++++++
* List folder and its related files when open gist, if you click list folder name, plugin will open all files in this gist
* Add http proxy for all http request, fix issue #4


0.2.3 (2015-07-11)
++++++++++++++++++
* Move events module from main.py to new event.py
Expand Down
6 changes: 6 additions & 0 deletions config/messages/0.2.4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Build 0.2.4
-----------
Release Date: 16 July 2015

* List folder and its related files when open gist, if you click list folder name, plugin will open all files in this gist
* Add http proxy for all http request, fix issue #4
13 changes: 12 additions & 1 deletion config/settings/HaoGist.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,16 @@
"auto_update_on_save": true,

// If set to true, debug message will be output to console
"debug_mode": false
"debug_mode": false,

// http_proxies settings, you can set it as below example,
// see more detail at:
// http://docs.python-requests.org/en/latest/user/advanced/#proxies
/*
"http_proxies": {
"http" : "http://user:%23Cpassword%23C:server:port",
"https" : "http://user:%23Cpassword%23C:server:port"
}
*/
"http_proxies": {}
}
2 changes: 1 addition & 1 deletion config/settings/HaoGistPackage.sublime-settings
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "HaoGist",
"version": "0.2.3",
"version": "0.2.4",
"description": "HaoGist is sublime plugin for CRUD on Github gist",
"author": "Hao Liu",
"email": "mouse.mliu@gmail.com",
Expand Down
15 changes: 8 additions & 7 deletions gist/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(self, token):
self.res = None
self._token = token
self.settings = util.get_settings()
self.proxies = self.settings["http_proxies"]
self.headers = {
"Accept": "application/json",
"Authorization": "token %s" % self._token
Expand All @@ -30,7 +31,7 @@ def list(self, force=False):
# If we don't add the per_page parameter, we can't get all gists
# However, this is not mentioned in the gist API document
self.res = requests.get(GIST_BASE_URL % "gists?per_page=1000",
headers=self.headers)
headers=self.headers, proxies=self.proxies)
except requests.exceptions.RequestException as e:
if self.settings["debug_mode"]:
print ("requests request exception: " + str(e))
Expand All @@ -39,7 +40,7 @@ def list(self, force=False):

def get(self, url):
try:
self.res = requests.get(url, headers=self.headers)
self.res = requests.get(url, headers=self.headers, proxies=self.proxies)
except requests.exceptions.RequestException as e:
if self.settings["debug_mode"]:
print ("requests request exception: " + str(e))
Expand All @@ -49,7 +50,7 @@ def get(self, url):
def retrieve(self, raw_url):
self.headers["Accept"] = "application/text"
try:
self.res = requests.get(raw_url, headers=self.headers)
self.res = requests.get(raw_url, headers=self.headers, proxies=self.proxies)
self.res.encoding = "utf-8"
except requests.exceptions.RequestException as e:
if self.settings["debug_mode"]:
Expand All @@ -62,7 +63,7 @@ def post(self, post_url, params):

try:
self.res = requests.post(post_url, data=json.dumps(params),
headers=self.headers)
headers=self.headers, proxies=self.proxies)
except requests.exceptions.RequestException as e:
if self.settings["debug_mode"]:
print ("requests request exception: " + str(e))
Expand All @@ -74,7 +75,7 @@ def patch(self, patch_url, params):

try:
self.res = requests.patch(patch_url, data=json.dumps(params),
headers=self.headers)
headers=self.headers, proxies=self.proxies)
except requests.exceptions.RequestException as e:
if self.settings["debug_mode"]:
print ("requests request exception: " + str(e))
Expand All @@ -83,9 +84,9 @@ def patch(self, patch_url, params):

def delete(self, url):
try:
self.res = requests.delete(url, headers=self.headers)
self.res = requests.delete(url, headers=self.headers, proxies=self.proxies)
except requests.exceptions.RequestException as e:
if self.settings["debug_mode"]:
print ("requests request exception: " + str(e))
return
return self.res
return self.res
1 change: 1 addition & 0 deletions gist/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def get_settings():
settings["auto_update_on_save"] = s.get("auto_update_on_save", True)
settings["default_chrome_path"] = s.get("default_chrome_path", "")
settings["delay_seconds_for_hiding_panel"] = s.get("delay_seconds_for_hiding_panel", 1)
settings["http_proxies"] = s.get("http_proxies", {})

# If user didn't set the workspace
workspace = s.get("workspace")
Expand Down
31 changes: 23 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,40 @@ def choose_gist(self, res, options={}):
"gist": _gist
}
else:
# Get gist description
description = _gist["description"]
if not description:
description = "gist:%s" % _gist["id"]

files_number = len(_gist["files"])
if files_number > 1:
self.items.append(description)

# Add gist files to items
gist_items_property = []
for key, value in _gist["files"].items():
if files_number > 1:
key = "%s%s" % (" " * 8, key)
self.items.append(key)
self.items_property[key] = {
self.items_property[key] = [{
"fileName": key,
"fileProperty": value,
"gist": _gist
}
}]
gist_items_property.extend(self.items_property[key])

# Populate items_property
self.items_property[description] = gist_items_property

self.window.show_quick_panel(self.items, self.on_done)

def on_done(self, index):
if index == -1: return

chosen_item = self.items[index]
self.window.run_command(self.callback_command, {
"options": self.items_property[chosen_item]
})
for item in self.items_property[self.items[index]]:
self.window.run_command(self.callback_command, {
"options": item
})

class OpenGist(sublime_plugin.WindowCommand):
def __init__(self, *args, **kwargs):
Expand All @@ -121,7 +137,7 @@ def run(self, options={}):
api = GistApi(settings["token"])
thread = threading.Thread(target=api.retrieve, args=(fileProperty["raw_url"], ))
thread.start()
ThreadProgress(api, thread, 'Opening Gist %s' % filename,
ThreadProgress(api, thread, 'Opening Gist %s' % filename.strip(),
callback.open_gist, _callback_options=options
)

Expand Down Expand Up @@ -499,4 +515,3 @@ def __init__(self, *args, **kwargs):

def run(self):
util.open_with_browser("https://github.com/xjsender/HaoGist")

1 comment on commit 256dfc2

@xjsender
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deliver enhancement for issue #4

Please sign in to comment.