Index: python/implugin.py
===================================================================
--- python/implugin.py	(revision 17aa9a25179aa9d24b7af138a73254a6680ce69f)
+++ python/implugin.py	(revision 513be3b5ce40cce99099f46c5d514cb6f7fe4653)
@@ -1,15 +1,9 @@
 #!/usr/bin/python
 
-import sys
 import bjsonrpc
 from bjsonrpc.handlers import BaseHandler
 
-import operator
-import random
 import re
 import socket
-import time
-
-import requests
 
 # List of functions an IM plugin can export. This library will indicate to
@@ -55,4 +49,20 @@
 	# away states, put them in a list in this variable.
 	AWAY_STATES = None
+
+	SETTINGS = {
+		"oauth": {
+			"default": False,
+			"type": "bool",
+		},
+		"test": {
+			"default": 123,
+			"type": "int",
+		},
+		"stringetje": {
+			"default": "testje",
+			"flags": 0x04,
+		}
+	}
+	_settings_values = {}
 	
 	# Filled in during initialisation:
@@ -64,6 +74,4 @@
 	bee = None
 	
-	BASE_URL = "https://newsblur.com"
-	
 	@classmethod
 	def _factory(cls, *args, **kwargs):
@@ -73,10 +81,4 @@
 		return handler_factory
 	
-	#def __init__(self, connection, *args, **kwargs):
-	#	BaseHandler.__init__(self,connection)
-
-	def url(self, path):
-		return (self.BASE_URL + path)
-
 	def init(self, bee):
 		self.bee = RpcForwarder(bee["method_list"], self._conn.call)
@@ -84,5 +86,4 @@
 		self.bitlbee_version_str = bee["version_str"]
 
-		# TODO: See how to call into the module here.
 		return {
 			"name": self.NAME,
@@ -90,93 +91,27 @@
 			"account_flags": self.ACCOUNT_FLAGS,
 			"away_state_list": self.AWAY_STATES,
-			"settings": {
-				"oauth": {
-					"default": "off",
-					"type": "bool",
-				},
-				"test": {
-					"default": "123",
-					"type": "int",
-				},
-				"stringetje": {
-					"default": "testje",
-					"flags": 0x04,
-				}
-			},
+			"settings": self.SETTINGS,
 		}
+
+	def login(self, account):
+		for key, value in account.get("settings", {}).iteritems():
+			self.set_set(key, value)
+
+	def set_set(self, key, value):
+		self._settings_values[key] = value
+		try:
+			func = self.__getattribute__("set_set_%s" % key)
+		except AttributeError:
+			return
+		func(key, value)
 	
-	def login(self, account):
-		self.ua = requests.Session()
-		creds = {"username": account["user"], "password": account["pass"]}
-		r = self.ua.post(self.url("/api/login"), creds)
-		self.bee.log("You're running BitlBee %d.%d.%d" % self.bitlbee_version)
-		if r.status_code != 200:
-			self.bee.error("HTTP error %d" % r.status_code)
-			self.bee.logout(True)
-		elif r.json()["errors"]:
-			self.bee.error("Authentication error")
-			self.bee.logout(False)
-		else:
-			self.bee.add_buddy("rss", None)
-			self.bee.connected()
-			self.seen_hashes = set()
-			self.keepalive()
-
-	def logout(self):
-		self.bee.error("Ok bye!")
-
-	def buddy_msg(self, handle, msg, flags):
-		feed = self.feeds[handle]
-		cmd = re.split(r"\s+", msg)
-	
-	def set_set(self, setting, value):
-		print "Setting %s changed to %r" % (setting, value)
-	
-	# BitlBee will call us here every minute which is actually a neat way
-	# to get periodic work (like RSS polling) scheduled. :-D
-	def keepalive(self):
-		r = self.ua.post(
-			self.url("/reader/unread_story_hashes"),
-			{"include_timestamps": True})
-		if r.status_code != 200:
-			self.bee.error("HTTP error %d" % r.status_code)
-			return
-
-		# Throw all unread-post hashes in a long list and sort it by posting time.
-		feed_hashes = r.json()["unread_feed_story_hashes"]
-		all_hashes = []
-		for feed, hashes in feed_hashes.iteritems():
-			all_hashes += [tuple(h) for h in hashes]
-		all_hashes.sort(key=operator.itemgetter(1))
-		
-		# Look at the most recent 20, grab the ones we haven't shown yet.
-		req_hashes = []
-		for hash, _ in all_hashes[-20:]:
-			if hash not in self.seen_hashes:
-				req_hashes.append(hash)
-		
-		if not req_hashes:
-			return
-		
-		# Grab post details.
-		r = self.ua.post(self.url("/reader/river_stories"), {"h": req_hashes})
-		if r.status_code != 200:
-			self.bee.error("HTTP error %d" % r.status_code)
-			return
-		
-		# Response is not in the order we requested. :-( Make it a hash
-		# and reconstruct order from our request.
-		stories = {s["story_hash"]: s for s in r.json()["stories"]}
-		for s in (stories[hash] for hash in req_hashes):
-			line = "%(story_title)s <%(story_permalink)s>" % s
-			ts = int(s.get("story_timestamp", "0"))
-			self.bee.buddy_msg("rss", line, 0, ts)
-			self.seen_hashes.add(s["story_hash"])
+	def setting(self, key):
+		return self._settings_values[key]
 
 
-def RunPlugin(plugin, debug=True):
+def RunPlugin(plugin, debug=False):
 	sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
 	sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-	sock.bind("/tmp/rpcplugins/test2")
+	sock.bind("/tmp/rpcplugins/%s.sock" % plugin.NAME)
 	sock.listen(3)
 	
@@ -185,4 +120,2 @@
 	srv.debug_socket(debug)
 	srv.serve()
-
-RunPlugin(BitlBeeIMPlugin)
Index: python/newsblur.py
===================================================================
--- python/newsblur.py	(revision 513be3b5ce40cce99099f46c5d514cb6f7fe4653)
+++ python/newsblur.py	(revision 513be3b5ce40cce99099f46c5d514cb6f7fe4653)
@@ -0,0 +1,95 @@
+#!/usr/bin/python
+
+import operator
+import re
+
+import requests
+
+import implugin
+
+class NewsBlurPlugin(implugin.BitlBeeIMPlugin):
+	NAME = "newsblur"
+	ACCOUNT_FLAGS = 0
+	SETTINGS = {
+		"backlog": {
+			"default": 20,
+			"type": "int",
+		},
+	}
+	
+	BASE_URL = "https://newsblur.com"
+	
+	def url(self, path):
+		return (self.BASE_URL + path)
+
+	def login(self, account):
+		super(NewsBlurPlugin, self).login(account)
+		self.ua = requests.Session()
+		creds = {"username": account["user"], "password": account["pass"]}
+		r = self.ua.post(self.url("/api/login"), creds)
+		self.bee.log("You're running BitlBee %d.%d.%d" % self.bitlbee_version)
+		if r.status_code != 200:
+			self.bee.error("HTTP error %d" % r.status_code)
+			self.bee.logout(True)
+		elif r.json()["errors"]:
+			self.bee.error("Authentication error")
+			self.bee.logout(False)
+		else:
+			self.bee.add_buddy("rss", None)
+			self.bee.connected()
+			self.seen_hashes = set()
+			self.keepalive()
+
+	def logout(self):
+		self.bee.log("Ok bye!")
+
+	def buddy_msg(self, handle, msg, flags):
+		feed = self.feeds[handle]
+		cmd = re.split(r"\s+", msg)
+	
+	def set_set_backlog(self, setting, value):
+		print "Setting %s changed to %r" % (setting, value)
+	
+	# BitlBee will call us here every minute which is actually a neat way
+	# to get periodic work (like RSS polling) scheduled. :-D
+	def keepalive(self):
+		r = self.ua.post(
+			self.url("/reader/unread_story_hashes"),
+			{"include_timestamps": True})
+		if r.status_code != 200:
+			self.bee.error("HTTP error %d" % r.status_code)
+			return
+
+		# Throw all unread-post hashes in a flat list and sort it by posting time.
+		feed_hashes = r.json()["unread_feed_story_hashes"]
+		all_hashes = []
+		for feed, hashes in feed_hashes.iteritems():
+			all_hashes += [tuple(h) for h in hashes]
+		all_hashes.sort(key=operator.itemgetter(1))
+		
+		# Look at the most recent posts, grab the ones we haven't shown yet.
+		req_hashes = []
+		for hash, _ in all_hashes[-self.setting("backlog"):]:
+			if hash not in self.seen_hashes:
+				req_hashes.append(hash)
+		
+		if not req_hashes:
+			return
+		
+		# Grab post details.
+		r = self.ua.post(self.url("/reader/river_stories"), {"h": req_hashes})
+		if r.status_code != 200:
+			self.bee.error("HTTP error %d" % r.status_code)
+			return
+		
+		# Response is not in the order we requested. :-( Make it a hash
+		# and reconstruct order from our request.
+		stories = {s["story_hash"]: s for s in r.json()["stories"]}
+		for s in (stories[hash] for hash in req_hashes):
+			line = "%(story_title)s <%(story_permalink)s>" % s
+			ts = int(s.get("story_timestamp", "0"))
+			self.bee.buddy_msg("rss", line, 0, ts)
+			self.seen_hashes.add(s["story_hash"])
+
+
+implugin.RunPlugin(NewsBlurPlugin, debug=True)
