Class: Wordpressto::WordpressBlog

Inherits:
Object
  • Object
show all
Defined in:
lib/wordpressto.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = { })
  @username = options[:username] if options[:username]
  @password = options[:password] if options[:password]
  @blog_id = options[:blog_id] || 1
  @url = options[:url] if options[:url]
end

Instance Attribute Details

#blog_idObject

Returns the value of attribute blog_id.



9
10
11
# File 'lib/wordpressto.rb', line 9

def blog_id
  @blog_id
end

#passwordObject

Returns the value of attribute password.



9
10
11
# File 'lib/wordpressto.rb', line 9

def password
  @password
end

#urlObject

Returns the value of attribute url.



9
10
11
# File 'lib/wordpressto.rb', line 9

def url
  @url
end

#usernameObject

Returns the value of attribute username.



9
10
11
# File 'lib/wordpressto.rb', line 9

def username
  @username
end

Instance Method Details

#attachmentsObject



22
23
24
# File 'lib/wordpressto.rb', line 22

def attachments
  @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.message =~ /XML-RPC services are disabled/
    raise Wordpressto::ConnectionFailure, e.message
  else
    raise Wordpressto::Error, e.message
  end
end

#categoriesObject



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

#postsObject



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

#xmlrpcObject



65
66
67
# File 'lib/wordpressto.rb', line 65

def xmlrpc
  @xclient ||= XMLRPC::Client.new2(url)
end