Class: Wordpressto::WordpressPost

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#conn

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 = { }, options = { })
  super(options)
  self.attributes = attributes
end

Instance Attribute Details

#categoriesObject

Returns the value of attribute categories.



141
142
143
# File 'lib/wordpressto.rb', line 141

def categories
  @categories
end

#created_atObject

Returns the value of attribute created_at.



140
141
142
# File 'lib/wordpressto.rb', line 140

def created_at
  @created_at
end

#descriptionObject

Returns the value of attribute description.



139
140
141
# File 'lib/wordpressto.rb', line 139

def description
  @description
end

#keywordsObject

Returns the value of attribute keywords.



141
142
143
# File 'lib/wordpressto.rb', line 141

def keywords
  @keywords
end

#publishedObject

Returns the value of attribute published.



141
142
143
# File 'lib/wordpressto.rb', line 141

def published
  @published
end

#titleObject

Returns the value of attribute title.



139
140
141
# File 'lib/wordpressto.rb', line 139

def title
  @title
end

Instance Method Details

#attributesObject



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

#createObject



175
176
177
178
# File 'lib/wordpressto.rb', line 175

def create
  @id = conn.new_post(attributes, published)
  self
end

#idObject



162
163
164
# File 'lib/wordpressto.rb', line 162

def id
  @id
end

#publishObject



180
181
182
183
# File 'lib/wordpressto.rb', line 180

def publish
  self.published = true
  save
end

#reloadObject



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

#saveObject



166
167
168
# File 'lib/wordpressto.rb', line 166

def save
  id ? update : create
end

#updateObject



170
171
172
173
# File 'lib/wordpressto.rb', line 170

def update
  conn.edit_post(id, attributes, published)
  self
end