Commits

Josh VanderLinden committed 1edf2aa

Working toward a the authenticated version of 2zeus

  • Participants
  • Parent commits 87fc441

Comments (0)

Files changed (3)

File clip2zeus/__init__.py

 APP_TITLE = 'Clip2Zeus'
 __author__ = 'Josh VanderLinden'
-__version__ = '1.3a'
+__version__ = '1.4a'
 

File clip2zeus/common.py

 
 class Clip2ZeusApp(object):
 
-    EXPOSED = ('help', 'get_version', 'get_interval', 'set_interval', 'shorten_urls', 'quit')
+    EXPOSED = ('help', 'get_version', 'get_interval', 'set_interval',
+               'shorten_urls', 'quit', 'get_api_key', 'set_api_key')
 
     def __init__(self, port=DEFAULT_PORT):
         """Creates the container for common functionality"""
         self._has_connection = False
         self.last_check = None
         self.interval = config.get('main', 'interval', 1)
+        self.api_key = config.get('main', 'api_key', '')
         self.threshold = timedelta(seconds=HEARTBEAT_INT)
         socket.setdefaulttimeout(TIMEOUT_SEC)
 
                 # Try to shorten this URL using 2ze.us
                 params = urllib.urlencode({
                     'url': url,
+                    'api': self.api_key,
                 })
 
                 try:
                     logger.info(' - %s' % url)
                     c = UrlOpener.open('http://2ze.us/generate/', params)
+                    c.add_header('X-Requested-With', 'clip2zeus')
                 except (urllib2.HTTPError, urllib2.URLError):
                     # do something?
                     update_data = False
             logger.debug('Updating clipboard')
             self.update_clipboard(self.data)
 
+    def get_api_key(self):
+        """Returns the user's API key"""
+
+        logger.debug('API key requested by client: %s' % (self.api_key,))
+        return self.api_key
+
+    def set_api_key(self, api_key):
+        """Sets the user's API key"""
+
+        logger.debug('API key updated by client: %s' % (api_key,))
+        self.api_key = api_key
+        config.set('main', 'api_key', api_key)
+
     def quit(self):
         """Ends processing"""
 

File clip2zeus/gui.py

         self.scl_interval = tk.Scale(self.parent, from_=0, to=30,
             label='Interval', orient=tk.HORIZONTAL, tickinterval=10,
             command=self.mode_selected)
+        self.txt_api = tk.Text(self.parent, text='API Key', variable=self.api_key,
+            command=self.api_changed)
 
         self.btn_shorten = tk.Button(self.parent, text="Shorten", command=self.check_clipboard)
         self.btn_quit = tk.Button(self.parent, text="Quit", command=self.quit)
         self.btn_shorten.grid(row=0, column=1, sticky='we')
         self.btn_quit.grid(row=1, column=1, sticky='we')
         self.scl_interval.grid(row=2, column=0, columnspan=2, sticky='we')
+        self.txt_api.grid(row=3, column=0, columnspan=2, sticky='we')
 
         cur_interval = self.execute_command('get_interval')
         logger.debug('Received "%s" as the current interval' % (cur_interval,))
         self.scl_interval.set(cur_interval)
 
+        api_key = self.execute_command('get_api_key')
+        self.txt_api.set(api_key)
+
         self.parent.columnconfigure(0, weight=1)
 
     def notify(self, message):
         self.scl_interval.set(interval)
         self.execute_command('set_interval', [interval])
 
+    def api_changed(self):
+        """Updates the user's API key"""
+
+        self.execute_command('set_api_key', [self.txt_api.get()])
+
     def quit(self):
         """Kills the application"""