Sha256: 4f74907410d2b447ab3d64270038e50276f3610272205bdd3fbb7838bdbcc907

Contents?: true

Size: 1011 Bytes

Versions: 1

Compression:

Stored size: 1011 Bytes

Contents

module Siteleaf
  class Page < Entity

    attr_accessor :title, :body, :slug, :url, :parent_id, :site_id, :published_at, :meta
    attr_reader :id, :created_at, :updated_at
    
    def self.all
      result = Client.get "#{self.endpoint}", {'include' => ['meta']}
      result.map { |r| self.new(r) } if result
    end
    
    def self.find(id)
      result = Client.get "#{self.endpoint}/#{id}", {'include' => ['meta']}
      self.new(result) if result
    end
    
    def create_endpoint
      "sites/#{self.site_id}/pages"
    end
    
    def site
      Site.find(self.site_id) if self.site_id
    end
    
    def posts
      result = Client.get "pages/#{self.id}/posts", {'include' => ['meta','taxonomy']}
      result.map { |r| Post.new(r) } if result
    end
    
    def pages
      result = Client.get "pages/#{self.id}/pages", {'include' => ['meta']}
      result.map { |r| self.new(r) } if result
    end
    
    def page
      Page.find(self.parent_id) if self.parent_id
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
siteleaf-0.9.0 lib/siteleaf/page.rb