class BlogRPC::SampleHandler

A sample MetaWeblog RPC handler. Bear in mind that you will need to rewrite most of it.

Define the standard methods for MetaWeblog API here. If you have a valiation problem or somesuch within the method just raise from there, exceptions will be translated into RPC fault codes.

You will need to take a look at (and override) get_entry and friends to retrofit that to your own engine.

Entry struct

A fundamental unit of the MT/MW API is the Entry struct (a Hash). Return that Hash anytime an entry struct is required. Here a short intro on the fields of the struct (you can use both symbols and strings for keys):

title, for the title of the entry;
description, for the body of the entry;
dateCreated, to set the created-on date of the entry;
In addition, Movable Type’s implementation allows you to pass in values for five other keys:
int mt_allow_comments, the value for the allow_comments field;
int mt_allow_pings, the value for the allow_pings field;
String mt_convert_breaks, the value for the convert_breaks field;
String mt_text_more, the value for the additional entry text;
String mt_excerpt, the value for the excerpt field;
String mt_keywords, the value for the keywords field;
String mt_basename, the value for the slug field;
array mt_tb_ping_urls, the list of TrackBack ping URLs for this entry;

If specified, dateCreated should be in ISO.8601 format. Also note that most blogging clients will have BIG issues if you supply non-UTC timestamps, so if you are using ActiveRecord timezone support (and you should!) take care to do all of your RPC operations with all timezones switched to UTC.

Constants

STRUCT_TO_CATEGORY
STRUCT_TO_ENTRY

An example mapping for the XMLRPC fieldnames to ActiveRecord fields.

Private Instance Methods

blog_url() click to toggle source

Return your blog url from here

# File lib/blogrpc/sample_handler.rb, line 276
def blog_url
end
category_to_struct(c) click to toggle source

Convert a category to RPC struct (hash)

# File lib/blogrpc/sample_handler.rb, line 224
def category_to_struct(c)
  STRUCT_TO_CATEGORY.inject({}) do | struct, kv |
    struct[kv[0]] = c[kv[1]].to_s
    struct
  end
end
change_entry(entry_obj, entry_struct, publish_bit) click to toggle source

Change an entry with data in the entry_struct, honoring the publish bit

# File lib/blogrpc/sample_handler.rb, line 241
def change_entry(entry_obj, entry_struct, publish_bit)
  entry_struct.each_pair do | k, v |
    # ActiveRecord YAMLifies that if we are not careful. XML-RPC gives us Time.to_gm by default
    v = v.to_time if(v.is_a?(XMLRPC::DateTime))
    model_field = STRUCT_TO_ENTRY[k]
    entry_obj.send("#{model_field}=", v) if model_field
  end
  entry_obj.save!
end
check_blog_permission!(blog_id, user) click to toggle source

Raise from here if the user cannot post to this specific blog

# File lib/blogrpc/sample_handler.rb, line 280
def check_blog_permission!(blog_id, user)
end
entry_to_struct(entry) click to toggle source

Transform an entry into a struct

# File lib/blogrpc/sample_handler.rb, line 257
def entry_to_struct(entry)
  STRUCT_TO_ENTRY.inject({}) do | struct, kv |
    k, v = kv
    
    # Dates and times have to pass through unscathed, converted to utc (!)
    struct[k] = if entry[v].respond_to?(:strftime)
      entry[v].utc
    else
      entry[v].to_s
    end
    struct
  end
end
find_all_categories() click to toggle source
# File lib/blogrpc/sample_handler.rb, line 231
def find_all_categories
  Category.find(:all)
end
get_categories_of(entry) click to toggle source

Get categories of the entry. The entry passed will be one recieved from one of your own methods

# File lib/blogrpc/sample_handler.rb, line 213
def get_categories_of(entry)
  entry.categories.map{|c| category_to_struct(c) }
end
get_entry(id) click to toggle source

Get an entry by ID

# File lib/blogrpc/sample_handler.rb, line 208
def get_entry(id)
  Entry.find(id)
end
latest_entries(n) click to toggle source

Return the latest N entries

# File lib/blogrpc/sample_handler.rb, line 252
def latest_entries(n)
  Entry.find(:all, :order => 'created_at DESC', :limit => n)
end
login!(user, pass) click to toggle source

Raise from here if the user is illegal

# File lib/blogrpc/sample_handler.rb, line 272
def login!(user, pass)
end
make_new_entry() click to toggle source

Get a fresh entry

# File lib/blogrpc/sample_handler.rb, line 236
def make_new_entry
  Entry.new
end
set_category_ids(entry, ids) click to toggle source

Assign category ids to an entry

# File lib/blogrpc/sample_handler.rb, line 218
def set_category_ids(entry, ids)
  entry.category_ids = ids
  entry.save!
end
site_root() click to toggle source

Get the site root

# File lib/blogrpc/sample_handler.rb, line 203
def site_root
  File.dirname(__FILE__)
end