Sha256: cee375e8337507f18cce801d6ac8d1e1269b1204a0575fbed48f0b6cc75e2179

Contents?: true

Size: 919 Bytes

Versions: 4

Compression:

Stored size: 919 Bytes

Contents

module Siteleaf
  class Page < Entity

    attr_accessor :title, :body, :slug, :url, :parent_id, :site_id, :published_at, :user_id, :meta, :assets
    attr_reader :id, :created_at, :updated_at
    
    def self.all
      result = Client.get "#{self.endpoint}"
      result.map { |r| self.new(r) } if result
    end
    
    def self.find(id)
      result = Client.get "#{self.endpoint}/#{id}"
      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"
      result.map { |r| Post.new(r) } if result
    end
    
    def pages
      result = Client.get "pages/#{self.id}/pages"
      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

4 entries across 4 versions & 1 rubygems

Version Path
siteleaf-0.9.12 lib/siteleaf/page.rb
siteleaf-0.9.11 lib/siteleaf/page.rb
siteleaf-0.9.10 lib/siteleaf/page.rb
siteleaf-0.9.9 lib/siteleaf/page.rb