How to integrate your Wordpress Blog in your Rails App (or any Ruby App)? Enter this simple API Wrapper, which makes use of the excellent JSON plugin for wordpress by Dan Phiffer.
-
Install the JSON-API plugin in your wordpress blog
-
HTTParty gem must be installed
Somewhere in your app (e.g. in an initializer file in Rails):
WpRubyApi::Base.site = "http://path/to/your/wordpress-blog"
If you have permalinks enabled in wordpress:
WpRubyApi::Base.permalinks = :enabled
This setting translates the request to either blog-path/api/json_method?params or blog-path?json=json-method¶ms. This is part of the JSON API.
Start your app or hop into the console. You should be able to use methods like this:
WpRubyApi::Post.all WpRubyApi::Post.find(3) WpRubyApi::Post.search("my search term") WpRubyApi::Post.by_category("my-category") WpRubyApi::Page.find('about') WpRubyApi::Comment.create({:name => "John Doe", :email => "[email protected]", :content => "This is a comment!", :post_id => 1}) (requires activation in JSON API)
For more methods and documentation take a look at the code.
Currently only available as a rails plugin.
-
docs
-
tests
-
gemify
Thanks to John Nunemaker for creating HTTParty. It’s awesome!
Copyright © 2010 Daniel Schoppmann, released under the MIT license