Advertisement
alfiemax

A plugin's basic structure

Aug 29th, 2014
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.03 KB | None | 0 0
  1. import ..... # what ever needed
  2.  
  3. #you will need to import these
  4. from modules.channel import Channel
  5. from exception import *
  6.  
  7. __cname__ = "wordpress"      #or whichever channel
  8.  
  9. class Wordpress(Channel):
  10.     def __init__(self):
  11.         self.__fields__ = ["Message","Title"]   # and whatever the plugin requires for sending a message
  12.  
  13.     def VerifyCredentials(self):
  14.         # this method should check if the auth info available in the .publish file valid
  15.         # and return True if it checks out and false if it fails
  16.  
  17.     def GetKeys(self):
  18.         # You can look at this function from any other plugin, u'll just need to make a few changes
  19.         # which are channel specific
  20.  
  21.     def Authorize(self):
  22.         # here ask user for authentication info and save it in the .publish file
  23.         # how to do that can be seen if u look at any existing plugins
  24.         # Finally after saving the auth info
  25.         # call VerifyCredentials and check if the given info is worth it
  26.         # if it fails do :
  27.         # raise AuthorizationError({'Wordpress':'Authorization Failed'})
  28.         # i.e raise the AuthorizationError exception and pass a dict with channel name as key
  29.         # and value as the message to be returned to ui
  30.    
  31.     def VerifyFields(self, fields):
  32.         # fields parameter passed is a dictionary of the format :
  33.         # {field1:value, field2:value, ...}
  34.         # here the plugin required fields are checked if they are valid
  35.         # returns True/False
  36.         # for eg: checks if the message passed is empty or not
  37.  
  38.     def SendMsg(self, Message):
  39.         # Message: this is a dictionary in the format
  40.         # {field1:value, field2:value, ...}
  41.         # and here do what is necessary to send message to this channel
  42.         # finally return message like
  43.         # return {'Wordpress':'Blog posted'}
  44.         # return {'Wordpress':'Blog posting failed'}
  45.         # return {'Wordpress':'Unable to access network/server'}
  46.         # u get the idea right.... should return a dict
  47.         # with key as the channel name and value as the message to be returned
  48.  
  49.     # add whichever other methods you want to create
  50.  
  51. # and after declaring the class
  52. __plugin__ = Wordpress  # the channel name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement