Class: WpApiClient::Entities::Post

Inherits:
Base
  • Object
show all
Defined in:
lib/wp_api_client/entities/post.rb

Instance Attribute Summary

Attributes inherited from Base

#resource

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

build, #initialize, #links, #method_missing, #relations

Constructor Details

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class WpApiClient::Entities::Base

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.parse(post["date_gmt"]) if post["date_gmt"]
end

#excerptObject



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

def excerpt
  post["excerpt"]["rendered"]
end

#meta(key = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/wp_api_client/entities/post.rb', line 30

def meta(key = nil)
  @meta ||= relations("https://api.w.org/meta")

  if key
    @meta[key.to_s]
  else
    @meta
  end
end

#terms(taxonomy = nil) ⇒ Object



26
27
28
# File 'lib/wp_api_client/entities/post.rb', line 26

def terms(taxonomy = nil)
  relations("https://api.w.org/term", taxonomy)
end

#titleObject



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

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