Class: WpApiClient::Entities::Term

Inherits:
BaseEntity show all
Defined in:
lib/wp_api_client/entities/term.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/term.rb', line 6

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

Instance Method Details

#idObject



28
29
30
# File 'lib/wp_api_client/entities/term.rb', line 28

def id
  term["id"]
end

#nameObject



20
21
22
# File 'lib/wp_api_client/entities/term.rb', line 20

def name
  term["name"]
end

#posts(post_type = "post") ⇒ Object



14
15
16
17
18
# File 'lib/wp_api_client/entities/term.rb', line 14

def posts(post_type = "post")
  post_type_links = links["http://api.w.org/v2/post_type"]
  link = post_type_links.find { |link| link["href"] =~ /wp\/v2\/#{post_type}/ }
  @api.get(link["href"]) if link
end

#slugObject



24
25
26
# File 'lib/wp_api_client/entities/term.rb', line 24

def slug
  term["slug"]
end

#taxonomyObject



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

def taxonomy
  @api.get(links["about"].first["href"])
end