Class: WpApiClient::Entities::Post

Inherits:
BaseEntity show all
Defined in:
lib/wp_api_client/entities/post.rb

Instance Attribute Summary

Attributes inherited from BaseEntity

#resource

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseEntity

#embedded, #initialize, #links

Constructor Details

This class inherits a constructor from WpApiClient::Entities::BaseEntity

Class Method Details

.represents?(json) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/wp_api_client/entities/post.rb', line 6

def self.represents?(json)
  json.dig("_links", "about") and json["_links"]["about"].first["href"] =~ /wp\/v2\/types/
end

Instance Method Details

#contentObject



18
19
20
# File 'lib/wp_api_client/entities/post.rb', line 18

def content
  post["content"]["rendered"]
end

#dateObject



14
15
16
# File 'lib/wp_api_client/entities/post.rb', line 14

def date
  Time.new(post["date_gmt"])
end

#idObject



22
23
24
# File 'lib/wp_api_client/entities/post.rb', line 22

def id
  post["id"]
end

#termsObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/wp_api_client/entities/post.rb', line 26

def terms
  if embedded?
    terms = []
    embedded["https://api.w.org/term"].map do |taxonomy|
      taxonomy.each do |term|
        terms << WpApiClient::Entities::Term.new(term, @api)
      end
    end
    terms
  end
end

#titleObject



10
11
12
# File 'lib/wp_api_client/entities/post.rb', line 10

def title
  post["title"]["rendered"]
end