Class: WpRpc::Blog
- Inherits:
-
Object
- Object
- WpRpc::Blog
- Defined in:
- lib/wp_rpc/blog.rb
Instance Attribute Summary collapse
-
#blog_id ⇒ Object
Returns the value of attribute blog_id.
-
#password ⇒ Object
Returns the value of attribute password.
-
#url ⇒ Object
Returns the value of attribute url.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #attachments ⇒ Object
- #call(*args) ⇒ Object
- #categories ⇒ Object
- #edit_post(qid, attributes, published = nil) ⇒ Object
- #get_post(qid) ⇒ Object
- #get_recent_posts(limit = 10) ⇒ Object
-
#initialize(options = { }) ⇒ Blog
constructor
A new instance of Blog.
- #new_post(attributes, published = nil) ⇒ Object
- #posts ⇒ Object
- #upload_file(name, mimetype, bits, overwrite = false) ⇒ Object
- #xmlrpc ⇒ Object
Constructor Details
#initialize(options = { }) ⇒ Blog
Returns a new instance of Blog.
5 6 7 8 9 10 |
# File 'lib/wp_rpc/blog.rb', line 5 def initialize( = { }) @username = [:username] if [:username] @password = [:password] if [:password] @blog_id = [:blog_id] || 1 @url = [:url] if [:url] end |
Instance Attribute Details
#blog_id ⇒ Object
Returns the value of attribute blog_id.
3 4 5 |
# File 'lib/wp_rpc/blog.rb', line 3 def blog_id @blog_id end |
#password ⇒ Object
Returns the value of attribute password.
3 4 5 |
# File 'lib/wp_rpc/blog.rb', line 3 def password @password end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/wp_rpc/blog.rb', line 3 def url @url end |
#username ⇒ Object
Returns the value of attribute username.
3 4 5 |
# File 'lib/wp_rpc/blog.rb', line 3 def username @username end |
Instance Method Details
#attachments ⇒ Object
16 17 18 |
# File 'lib/wp_rpc/blog.rb', line 16 def ||= Collection::Attachments.new(:conn => self) end |
#call(*args) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/wp_rpc/blog.rb', line 50 def call(*args) xmlrpc.call(*args) rescue XMLRPC::FaultException => e if e. =~ /XML-RPC services are disabled/ raise WpRpc::ConnectionFailure, e. else raise WpRpc::Error, e. end end |
#categories ⇒ Object
20 21 22 |
# File 'lib/wp_rpc/blog.rb', line 20 def categories @categories ||= Collection::Categories.new(:conn => self) end |
#edit_post(qid, attributes, published = nil) ⇒ Object
32 33 34 35 36 |
# File 'lib/wp_rpc/blog.rb', line 32 def edit_post(qid, attributes, published = nil) cargs = ['metaWeblog.editPost', qid, username, password, attributes] cargs << published unless published.nil? call(*cargs) end |
#get_post(qid) ⇒ Object
28 29 30 |
# File 'lib/wp_rpc/blog.rb', line 28 def get_post(qid) call('metaWeblog.getPost', qid, username, password) end |
#get_recent_posts(limit = 10) ⇒ Object
24 25 26 |
# File 'lib/wp_rpc/blog.rb', line 24 def get_recent_posts(limit = 10) call('metaWeblog.getRecentPosts', blog_id, username, password, limit) end |
#new_post(attributes, published = nil) ⇒ Object
38 39 40 41 42 |
# File 'lib/wp_rpc/blog.rb', line 38 def new_post(attributes, published = nil) cargs = ['metaWeblog.newPost', blog_id, username, password, attributes] cargs << published unless published.nil? call(*cargs) end |
#posts ⇒ Object
12 13 14 |
# File 'lib/wp_rpc/blog.rb', line 12 def posts @post_collection ||= Collection::Posts.new(:conn => self) end |
#upload_file(name, mimetype, bits, overwrite = false) ⇒ Object
44 45 46 47 48 |
# File 'lib/wp_rpc/blog.rb', line 44 def upload_file(name, mimetype, bits, overwrite = false) call('wp.uploadFile', blog_id, username, password, { :name => name, :type => mimetype, :bits => XMLRPC::Base64.new(bits), :overwrite => overwrite }) end |
#xmlrpc ⇒ Object
60 61 62 |
# File 'lib/wp_rpc/blog.rb', line 60 def xmlrpc @xclient ||= XMLRPC::Client.new2(url) end |