Class: Rubypress::Client

Inherits:
Object
  • Object
show all
Includes:
Comments, Media, Options, Posts, Taxonomies, Users
Defined in:
lib/rubypress/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Users

#editProfile, #getAuthors, #getProfile, #getUser, #getUsers, #getUsersBlogs

Methods included from Options

#getOptions, #setOptions

Methods included from Comments

#deleteComment, #editComment, #getComment, #getCommentCount, #getCommentStatusList, #getComments, #newComment

Methods included from Media

#getMediaItem, #getMediaLibrary, #uploadFile

Methods included from Taxonomies

#deleteTerm, #editTerm, #getTaxonomies, #getTaxonomy, #getTerm, #getTerms, #newTerm

Methods included from Posts

#deletePost, #editPost, #getPost, #getPostFormats, #getPostStatusList, #getPostType, #getPostTypes, #getPosts, #newPost

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rubypress/client.rb', line 21

def initialize(options = {})
  {
    :port => 80,
    :ssl_port => 443,
    :use_ssl => false,
    :host => nil,
    :path => '/xmlrpc.php',
    :username => nil,
    :password => nil,
    :default_post_fields => %w(post terms custom_fields),
    :debug => false,
    :http_user => nil,
    :http_password => nil,
    :retry_timeouts => false,
    :timeout => 30,
    :cookie => nil
  }.merge(options).each{ |opt| self.send("#{opt[0]}=", opt[1]) }
  self
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



17
18
19
# File 'lib/rubypress/client.rb', line 17

def connection
  @connection
end

Returns the value of attribute cookie.



18
19
20
# File 'lib/rubypress/client.rb', line 18

def cookie
  @cookie
end

#debugObject

Returns the value of attribute debug.



18
19
20
# File 'lib/rubypress/client.rb', line 18

def debug
  @debug
end

#default_post_fieldsObject

Returns the value of attribute default_post_fields.



18
19
20
# File 'lib/rubypress/client.rb', line 18

def default_post_fields
  @default_post_fields
end

#hostObject

Returns the value of attribute host.



18
19
20
# File 'lib/rubypress/client.rb', line 18

def host
  @host
end

#http_passwordObject

Returns the value of attribute http_password.



18
19
20
# File 'lib/rubypress/client.rb', line 18

def http_password
  @http_password
end

#http_userObject

Returns the value of attribute http_user.



18
19
20
# File 'lib/rubypress/client.rb', line 18

def http_user
  @http_user
end

#passwordObject

Returns the value of attribute password.



18
19
20
# File 'lib/rubypress/client.rb', line 18

def password
  @password
end

#pathObject

Returns the value of attribute path.



18
19
20
# File 'lib/rubypress/client.rb', line 18

def path
  @path
end

#portObject

Returns the value of attribute port.



18
19
20
# File 'lib/rubypress/client.rb', line 18

def port
  @port
end

#retry_timeoutsObject

Returns the value of attribute retry_timeouts.



18
19
20
# File 'lib/rubypress/client.rb', line 18

def retry_timeouts
  @retry_timeouts
end

#ssl_portObject

Returns the value of attribute ssl_port.



18
19
20
# File 'lib/rubypress/client.rb', line 18

def ssl_port
  @ssl_port
end

#timeoutObject

Returns the value of attribute timeout.



18
19
20
# File 'lib/rubypress/client.rb', line 18

def timeout
  @timeout
end

#use_sslObject

Returns the value of attribute use_ssl.



18
19
20
# File 'lib/rubypress/client.rb', line 18

def use_ssl
  @use_ssl
end

#usernameObject

Returns the value of attribute username.



18
19
20
# File 'lib/rubypress/client.rb', line 18

def username
  @username
end

Class Method Details

.defaultObject



52
53
54
# File 'lib/rubypress/client.rb', line 52

def self.default
  self.new(:host => ENV['WORDPRESS_HOST'], :port => 80, :username => ENV['WORDPRESS_USERNAME'], :password => ENV['WORDPRESS_PASSWORD'], :use_ssl => false)
end

Instance Method Details

#execute(method, options) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/rubypress/client.rb', line 56

def execute(method, options)
  args = []
  options_final = {
    :blog_id => 0,
    :username => self.username,
    :password => self.password
  }
  options_final.deep_merge!(options).each{|option| args.push(option[1]) if !option[1].nil?}
  method = "wp.#{method}" unless method.include?('.')
  if self.debug
    connection.set_debug
    server = self.connection.call(method, args)
    pp server
  else
    self.connection.call(method, args)
  end
end