lib/wp/api/resources/post.rb in wp-api-0.0.2 vs lib/wp/api/resources/post.rb in wp-api-0.0.3
- old
+ new
@@ -1,4 +1,35 @@
module WP::API
class Post < Resource
+ def categories
+ terms['category'].collect {|cat| WP::API::Category.new(cat) }
+ end
+
+ def prev
+ item = link_header_items.find {|rel, url| rel == "prev" }
+ item.last if item
+ end
+
+ def next
+ item = link_header_items.find {|rel, url| rel == "next" }
+ item.last if item
+ end
+
+ def items
+ items = link_header_items.select {|rel, url| rel == "item" }
+ items.empty? ? [] : items.collect(&:last)
+ end
+
+ private
+
+ def link_header_items
+ @link_header_items ||= headers['link'].split(', ').collect do |header|
+ [
+ header.match(/rel="([^"]+)"/)[1],
+ header.match(/<([^>]+)>/)[1]
+ ]
+ end
+ rescue
+ []
+ end
end
end