Commits

Vic Bukhantsov committed 1a06d64

add pushover sounds API request

Comments (0)

Files changed (2)

pushnotify/pushover.py

 PUBLIC_API_URL = u'https://api.pushover.net/1'
 VERIFY_URL = u'/'.join([PUBLIC_API_URL, u'users/validate.json'])
 NOTIFY_URL = u'/'.join([PUBLIC_API_URL, u'messages.json'])
+SOUND_URL = u'/'.join([PUBLIC_API_URL, u'sounds.json'])
 
 DESC_LIMIT = 512
 
         super(self.__class__, self).__init__(developerkey, application)
 
         self._type = 'pushover'
-        self._urls = {'notify': NOTIFY_URL, 'verify': VERIFY_URL}
+        self._urls = {'notify': NOTIFY_URL,
+                      'verify': VERIFY_URL,
+                      'sounds': SOUND_URL}
 
     def _parse_response(self, stream, verify=False):
 
         self._last['status'] = response.get('status', None)
         self._last['token'] = response.get('token', None)
         self._last['user'] = response.get('user', None)
+        self._last['sounds'] = response.get('sounds', None)
 
         return self._last['status']
 
 
         return self._last['status']
 
+    def sounds(self):
+        """ Retrieve available sounds list.
+
+        Returns:
+            A hash with each key being the actual sound parameter to store for the user
+            and send to Pushover, with its value describing the sound.
+        """
+        response = self._get(self._urls['sounds'],
+                             {'token': self.developerkey})
+        self._parse_response(response, True)
+        return self._last['sounds']
 
 if __name__ == '__main__':
     pass

pushnotify/tests/tests.py

         self.assertRaises(exceptions.ApiKeyError, self.client.verify_device,
                           'foo', device_key)
 
+    def test_sound(self):
+        """ Test retrieve sounds list from pushover
+        """
+        sounds = self.client.sounds()
+        self.assertGreater(len(sounds.keys()), 0)
 
 if __name__ == '__main__':
     pass