Class: Wordpressto::WordpressPost
Instance Attribute Summary collapse
-
#categories ⇒ Object
Returns the value of attribute categories.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#description ⇒ Object
Returns the value of attribute description.
-
#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 = { }) ⇒ WordpressPost
constructor
A new instance of WordpressPost.
- #publish ⇒ Object
- #reload ⇒ Object
- #save ⇒ Object
- #update ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(attributes = { }, options = { }) ⇒ WordpressPost
Returns a new instance of WordpressPost.
143 144 145 146 |
# File 'lib/wordpressto.rb', line 143 def initialize(attributes = { }, = { }) super() self.attributes = attributes end |
Instance Attribute Details
#categories ⇒ Object
Returns the value of attribute categories.
141 142 143 |
# File 'lib/wordpressto.rb', line 141 def categories @categories end |
#created_at ⇒ Object
Returns the value of attribute created_at.
140 141 142 |
# File 'lib/wordpressto.rb', line 140 def created_at @created_at end |
#description ⇒ Object
Returns the value of attribute description.
139 140 141 |
# File 'lib/wordpressto.rb', line 139 def description @description end |
#keywords ⇒ Object
Returns the value of attribute keywords.
141 142 143 |
# File 'lib/wordpressto.rb', line 141 def keywords @keywords end |
#published ⇒ Object
Returns the value of attribute published.
141 142 143 |
# File 'lib/wordpressto.rb', line 141 def published @published end |
#title ⇒ Object
Returns the value of attribute title.
139 140 141 |
# File 'lib/wordpressto.rb', line 139 def title @title end |
Instance Method Details
#attributes ⇒ Object
211 212 213 214 215 216 217 218 219 |
# File 'lib/wordpressto.rb', line 211 def attributes h = { } h[:title] = title if title h[:description] = description if description h[:dateCreated] = created_at if created_at h[:mt_keywords] = keywords.join(",") h[:categories] = categories if categories h end |
#attributes=(attr) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/wordpressto.rb', line 148 def attributes=(attr) symbolized_attr = { } attr = attr.each { |k,v| symbolized_attr[k.to_sym] = v } attr = symbolized_attr @title = attr[:title] @keywords = attr[:mt_keywords].to_s.split(/,|;/).collect { |k| k.strip } @categories = attr[:categories] @description = attr[:description] @created_at = attr[:dateCreated] @id = attr[:postid] @userid = attr[:userid] @published = attr[:published] end |
#create ⇒ Object
175 176 177 178 |
# File 'lib/wordpressto.rb', line 175 def create @id = conn.new_post(attributes, published) self end |
#id ⇒ Object
162 163 164 |
# File 'lib/wordpressto.rb', line 162 def id @id end |
#publish ⇒ Object
180 181 182 183 |
# File 'lib/wordpressto.rb', line 180 def publish self.published = true save end |
#reload ⇒ Object
221 222 223 224 225 226 227 228 |
# File 'lib/wordpressto.rb', line 221 def reload if id saved_id = id self.attributes = conn.posts.find(id).attributes @id = saved_id true end end |
#save ⇒ Object
166 167 168 |
# File 'lib/wordpressto.rb', line 166 def save id ? update : create end |
#update ⇒ Object
170 171 172 173 |
# File 'lib/wordpressto.rb', line 170 def update conn.edit_post(id, attributes, published) self end |