May 11 2009

Cool Rule – "Search & Swap"

 

Search & Swap

 

This rule “watches” searches on book-selling sites and informs the user if the same book is available at a local library.  This rule has applications for just about any place where you want to divert traffic for specific items or information from one site to another. 

 

 ruleset library {


    global {

datasource library_search

                  <- "http://www.example.com/bookdata/?wt=json" cachable;

    }

    rule book_notfication is active {

        select using "www.amazon.com/gp/product/(\d+)/" setting(isbn)

        pre {

        book_data = datasource:library_search("q="+isbn);

    url = book_data.pick("$..docs[0].url");

   title = book_data.pick("$..docs[0].title");

 msg = <<

This book's available at your local library.

Click here to see: <a id="MLN_link" href="#{url}">#{title}</a>

>>;

}

if(book_data.pick("$..numFound") > 0) then {

  notify("Local Library", msg)

              with sticky = true;

}

        callbacks {

           success { click class="MLN_link" }

        }

    }

}

 

 In this example the user went to a book-selling site and searched for a specific business book.  When the search results came up, the KNS rule recognized that this book was available at their local library and prompted them with a floating message. 

search-swap

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Back to Blog