Class: Wordpressto::WordpressBlog
- Inherits:
-
Object
- Object
- Wordpressto::WordpressBlog
- Defined in:
- lib/wordpressto.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 = { }) ⇒ WordpressBlog
constructor
A new instance of WordpressBlog.
- #new_post(attributes, published = nil) ⇒ Object
- #posts ⇒ Object
- #upload_file(name, mimetype, bits, overwrite = false) ⇒ Object
- #xmlrpc ⇒ Object
Constructor Details
#initialize(options = { }) ⇒ WordpressBlog
Returns a new instance of WordpressBlog.
11 12 13 14 15 16 |
# File 'lib/wordpressto.rb', line 11 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.
9 10 11 |
# File 'lib/wordpressto.rb', line 9 def blog_id @blog_id end |
#password ⇒ Object
Returns the value of attribute password.
9 10 11 |
# File 'lib/wordpressto.rb', line 9 def password @password end |
#url ⇒ Object
Returns the value of attribute url.
9 10 11 |
# File 'lib/wordpressto.rb', line 9 def url @url end |
#username ⇒ Object
Returns the value of attribute username.
9 10 11 |
# File 'lib/wordpressto.rb', line 9 def username @username end |
Instance Method Details
#attachments ⇒ Object
22 23 24 |
# File 'lib/wordpressto.rb', line 22 def @attachments ||= WordpressAttachmentCollection.new(:conn => self) end |
#call(*args) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/wordpressto.rb', line 55 def call(*args) xmlrpc.call(*args) rescue XMLRPC::FaultException => e if e. =~ /XML-RPC services are disabled/ raise Wordpressto::ConnectionFailure, e. else raise Wordpressto::Error, e. end end |
#categories ⇒ Object
26 27 28 |
# File 'lib/wordpressto.rb', line 26 def categories @categories ||= CategoryCollection.new(:conn => self) end |
#edit_post(qid, attributes, published = nil) ⇒ Object
38 39 40 41 42 |
# File 'lib/wordpressto.rb', line 38 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
34 35 36 |
# File 'lib/wordpressto.rb', line 34 def get_post(qid) call('metaWeblog.getPost', qid, username, password) end |
#get_recent_posts(limit = 10) ⇒ Object
30 31 32 |
# File 'lib/wordpressto.rb', line 30 def get_recent_posts(limit = 10) call('metaWeblog.getRecentPosts', blog_id, username, password, limit) end |
#new_post(attributes, published = nil) ⇒ Object
44 45 46 47 48 |
# File 'lib/wordpressto.rb', line 44 def new_post(attributes, published = nil) cargs = ['metaWeblog.newPost', blog_id, username, password, attributes] cargs << published unless published.nil? call(*cargs) end |
#posts ⇒ Object
18 19 20 |
# File 'lib/wordpressto.rb', line 18 def posts @post_collection ||= WordpressPostCollection.new(:conn => self) end |
#upload_file(name, mimetype, bits, overwrite = false) ⇒ Object
50 51 52 53 |
# File 'lib/wordpressto.rb', line 50 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
65 66 67 |
# File 'lib/wordpressto.rb', line 65 def xmlrpc @xclient ||= XMLRPC::Client.new2(url) end |