Permalink
Browse files

added goo.gl shortlinks feature. [optional]

  • Loading branch information...
ozcan committed May 15, 2013
1 parent 0cdca05 commit e830aff55246c71e8faabe0db5778ed0d7111ee3
Showing with 22 additions and 1 deletion.
  1. +2 −1 enlinuxclipper/config.py
  2. +20 −0 enlinuxclipper/enapi.py
View
@@ -11,7 +11,8 @@ class ConfigManager():
# set default values
config = ConfigParser.SafeConfigParser({'access_token': '',
'play-sound': 'True',
'copy-to-clipboard': 'True'})
'copy-to-clipboard': 'True',
'googl-shortlink': 'True'})
# config path
cfg_dir = os.environ['HOME'] + '/.config/en-linuxclipper/'
View
@@ -3,6 +3,8 @@
import hashlib
import binascii
import subprocess
import httplib
from cgi import escape
import evernote.edam.userstore.constants as UserStoreConstants
@@ -219,5 +221,23 @@ def copy_link_to_clipboard(guid):
url = "https://%s/shard/%s/sh/%s/%s" % (HOST, ENAPI.user.shardId,
guid, shareKey)
if ConfigManager.get_conf('googl-shortlink'):
url = ENAPI.googl_shortlink(url)
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
clipboard.set_text(url, len(url))
@staticmethod
def googl_shortlink(url):
try:
connection = httplib.HTTPSConnection("www.googleapis.com")
headers = {"Content-type": "application/json"}
data = '{"longUrl": "' + url + '"}'
connection.request('POST', '/urlshortener/v1/url', data, headers)
response = connection.getresponse().read()
return response.split('"id": "')[1].split('"')[0]
except:
return url

0 comments on commit e830aff

Please sign in to comment.