implement generic rule API class

So that we can reuse the code.