Class: WpRpc::Post
Instance Attribute Summary collapse
-
#categories ⇒ Object
Returns the value of attribute categories.
-
#content ⇒ Object
Returns the value of attribute content.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#keywords ⇒ Object
Returns the value of attribute keywords.
-
#published ⇒ Object
Returns the value of attribute published.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #attributes ⇒ Object
- #attributes=(attr) ⇒ Object
- #create ⇒ Object
- #id ⇒ Object
-
#initialize(attributes = { }, options = { }) ⇒ Post
constructor
A new instance of Post.
- #publish ⇒ Object
- #reload ⇒ Object
- #save ⇒ Object
- #update ⇒ Object
Methods inherited from Base
#change_attributes, #conn, #pattern
Constructor Details
#initialize(attributes = { }, options = { }) ⇒ Post
Returns a new instance of Post.
8 9 10 11 |
# File 'lib/wp_rpc/post.rb', line 8 def initialize(attributes = { }, = { }) super() self.attributes = attributes end |
Instance Attribute Details
#categories ⇒ Object
Returns the value of attribute categories.
6 7 8 |
# File 'lib/wp_rpc/post.rb', line 6 def categories @categories end |
#content ⇒ Object
Returns the value of attribute content.
4 5 6 |
# File 'lib/wp_rpc/post.rb', line 4 def content @content end |
#created_at ⇒ Object
Returns the value of attribute created_at.
5 6 7 |
# File 'lib/wp_rpc/post.rb', line 5 def created_at @created_at end |
#keywords ⇒ Object
Returns the value of attribute keywords.
6 7 8 |
# File 'lib/wp_rpc/post.rb', line 6 def keywords @keywords end |
#published ⇒ Object
Returns the value of attribute published.
6 7 8 |
# File 'lib/wp_rpc/post.rb', line 6 def published @published end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/wp_rpc/post.rb', line 4 def title @title end |
Instance Method Details
#attributes ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/wp_rpc/post.rb', line 76 def attributes h = { } h[:title] = title if title h[:description] = content if content h[:dateCreated] = created_at if created_at h[:mt_keywords] = keywords.join(",") h[:categories] = categories if categories h end |
#attributes=(attr) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/wp_rpc/post.rb', line 13 def attributes=(attr) symbolized_attr = { } attr = attr.each { |k,v| symbolized_attr[k.to_sym] = v } attr = symbolized_attr @title = attr[:title] @keywords = attr[:keywords].to_s.split(/,|;/).collect { |k| k.strip } @categories = attr[:categories] @content = attr[:content] @created_at = attr[:dateCreated] @id = attr[:postid] @userid = attr[:userid] @published = attr[:published] end |
#create ⇒ Object
40 41 42 43 |
# File 'lib/wp_rpc/post.rb', line 40 def create @id = conn.new_post(attributes, published) self end |
#id ⇒ Object
27 28 29 |
# File 'lib/wp_rpc/post.rb', line 27 def id @id end |
#publish ⇒ Object
45 46 47 48 |
# File 'lib/wp_rpc/post.rb', line 45 def publish self.published = true save end |
#reload ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/wp_rpc/post.rb', line 86 def reload if id saved_id = id self.attributes = conn.posts.find(id).attributes @id = saved_id true end end |
#save ⇒ Object
31 32 33 |
# File 'lib/wp_rpc/post.rb', line 31 def save id ? update : create end |
#update ⇒ Object
35 36 37 38 |
# File 'lib/wp_rpc/post.rb', line 35 def update conn.edit_post(id, attributes, published) self end |