Class: WpRpc::Collection::Posts

Inherits:
Base
  • Object
show all
Defined in:
lib/wp_rpc/collections/posts.rb

Instance Method Summary collapse

Methods inherited from Base

#change_attributes, #conn, #initialize, #pattern

Constructor Details

This class inherits a constructor from WpRpc::Base

Instance Method Details

#allObject



25
26
27
# File 'lib/wp_rpc/collections/posts.rb', line 25

def all
  change_attributes(conn.call('wp.getPosts', conn.blog_id, conn.username, conn.password), pattern)
end

#delete(ids) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/wp_rpc/collections/posts.rb', line 29

def delete(ids)
  posts = {}
  if ids.is_a?(Array)
    ids.each do |id|
      posts = posts.merge({id => conn.call('wp.deletePost', conn.blog_id, conn.username, conn.password, id) })
    end 
    posts
  else 
    conn.call('wp.deletePost', conn.blog_id, conn.username, conn.password, id)
  end
end

#find(qid, options = { }) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/wp_rpc/collections/posts.rb', line 10

def find(qid, options = { })
  if qid.is_a?(Array)
    qid.collect { |sqid| find(sqid) }
  elsif qid == :recent
    find_recent(options)
  else
    post = conn.get_post(qid)
    Post.new(post, :conn => conn)
  end
end

#find_recent(options = { }) ⇒ Object



4
5
6
7
8
# File 'lib/wp_rpc/collections/posts.rb', line 4

def find_recent(options = { })
  options = { :limit => 10 }.merge(options)
  posts = conn.get_recent_posts(options[:limit])
  posts.collect { |post|  Post.new(post, :conn => conn) }
end

#formatsObject



45
46
47
# File 'lib/wp_rpc/collections/posts.rb', line 45

def formats
  conn.call('wp.getPostFormats', conn.blog_id, conn.username, conn.password)
end

#new(attributes = { }) ⇒ Object



21
22
23
# File 'lib/wp_rpc/collections/posts.rb', line 21

def new(attributes = { })
  WpRpc::Post.new(attributes, :conn => conn)
end

#statusObject



41
42
43
# File 'lib/wp_rpc/collections/posts.rb', line 41

def status
  conn.call('wp.getPostStatusList', conn.blog_id, conn.username, conn.password)
end

#type(name) ⇒ Object



53
54
55
# File 'lib/wp_rpc/collections/posts.rb', line 53

def type(name)
  conn.call('wp.getPostType', conn.blog_id, conn.username, conn.password, name)
end

#typesObject



49
50
51
# File 'lib/wp_rpc/collections/posts.rb', line 49

def types
  conn.call('wp.getPostTypes', conn.blog_id, conn.username, conn.password)
end