Class: RMetaWebLog

Inherits:
XMLRPC::Client
  • Object
show all
Defined in:
lib/rmetaweblog.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ RMetaWebLog

Initialize RMetaWebLog with: host, path, port(optional), options

RMetaWebLog.new(“hostname”, “/path/to/xmlrpc”,

:blog_url => "http://path/to/blog",
:blog_id => "blogid",
:api_user => "username",
:api_pass => "password"

)

Optional parameters are: blog_url = blog_id = api_user = api_pass = proxy_host = proxy_port = user = password = use_ssl = timeout =



24
25
26
27
28
29
30
31
32
# File 'lib/rmetaweblog.rb', line 24

def initialize(*args)
  options = extract_hash_from_args!(args)
  args[2] ||= 80
  @blog_url = options[:blog_url]
  @blog_id = options[:blog_id]
  @api_user = options[:api_user] 
  @api_pass = options[:api_pass]
  super(args[0], args[1], args[2], options[:proxy_host], options[:proxy_port], options[:user], options[:password], options[:use_ssl], options[:timeout])
end

Instance Method Details

#categoriesObject

Returns Hash.



74
75
76
# File 'lib/rmetaweblog.rb', line 74

def categories
  call('metaWeblog.getCategories', @blog_id, @api_user, @api_pass)
end

#delete_post!(postid) ⇒ Object

Returns True.



45
46
47
# File 'lib/rmetaweblog.rb', line 45

def delete_post!(postid)
  call('metaWeblog.deletePost', "appkey", postid, @api_user, @api_pass, true)	  
end

#edit_post(postid, title, content) ⇒ Object

Returns True.



57
58
59
60
# File 'lib/rmetaweblog.rb', line 57

def edit_post(postid, title, content)
  object = { 'title' => title, 'link' => @blog_url, 'description' => content }
  call('metaWeblog.editPost', postid, @api_user, @api_pass, object, true)
end

#new_media_object(name, type, filename) ⇒ Object

Returns Hash.



63
64
65
66
67
68
69
70
71
# File 'lib/rmetaweblog.rb', line 63

def new_media_object(name, type, filename)
require 'base64'
  object = {
    'name' => name,
    'type' => type,
    'bits' => XMLRPC::Base64.new(File.read(filename)) 
  }
  call('metaWeblog.newMediaObject', @blog_id, @api_user, @api_pass, object)
end

#new_post(title, content) ⇒ Object

Returns String (postid).



51
52
53
54
# File 'lib/rmetaweblog.rb', line 51

def new_post(title, content)
  object = { 'title' => title, 'link' => @blog_url, 'description' => content }
  call('metaWeblog.newPost', @blog_id, @api_user, @api_pass, object, true)
end

#post(postid) ⇒ Object

Returns Hash.



35
36
37
# File 'lib/rmetaweblog.rb', line 35

def post(postid)
  call('metaWeblog.getPost', postid, @api_user, @api_pass)	  
end

#posts(count = 5) ⇒ Object

Returns Hash.



40
41
42
# File 'lib/rmetaweblog.rb', line 40

def posts(count = 5)
  call('metaWeblog.getRecentPosts', @blog_id, @api_user, @api_pass, count)
end

#recent_posts(number = 5) ⇒ Object

Returns array of hashes.



79
80
81
# File 'lib/rmetaweblog.rb', line 79

def recent_posts(number = 5)
  call('metaWeblog.getRecentPosts', @blog_id, @api_user, @api_pass, number)
end