Class: WordpressClient::Post

Inherits:
Object
  • Object
show all
Defined in:
lib/wordpress_client/post.rb

Overview

Represents a post in Wordpress.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, slug: nil, url: nil, guid: nil, status: "unknown", title_html: nil, excerpt_html: nil, content_html: nil, updated_at: nil, date: nil, categories: [], tags: [], category_ids: [], tag_ids: [], featured_media: nil, meta: {}) ⇒ Post

Construct a new instance with the given attributes.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/wordpress_client/post.rb', line 66

def initialize(
  id: nil,
  slug: nil,
  url: nil,
  guid: nil,
  status: "unknown",
  title_html: nil,
  excerpt_html: nil,
  content_html: nil,
  updated_at: nil,
  date: nil,
  categories: [],
  tags: [],
  category_ids: [],
  tag_ids: [],
  featured_media: nil,
  meta: {}
)
  @id = id
  @slug = slug
  @url = url
  @guid = guid
  @status = status
  @title_html = title_html
  @excerpt_html = excerpt_html
  @content_html = content_html
  @updated_at = updated_at
  @date = date
  @categories = categories
  @tags = tags
  @category_ids = category_ids
  @tag_ids = tag_ids
  @featured_media = featured_media
  @meta = meta
end

Instance Attribute Details

#categoriesArray[Category]

Returns the Categories the post belongs to.

Returns:

See Also:



38
39
40
# File 'lib/wordpress_client/post.rb', line 38

def categories
  @categories
end

#category_idsObject

Returns the value of attribute category_ids.



8
9
10
# File 'lib/wordpress_client/post.rb', line 8

def category_ids
  @category_ids
end

#content_htmlObject

Returns the value of attribute content_html.



8
9
10
# File 'lib/wordpress_client/post.rb', line 8

def content_html
  @content_html
end

#dateTime?

Returns the date of the post, in UTC if available.

Returns:

  • (Time, nil)

    the date of the post, in UTC if available



21
22
23
# File 'lib/wordpress_client/post.rb', line 21

def date
  @date
end

#excerpt_htmlObject

Returns the value of attribute excerpt_html.



8
9
10
# File 'lib/wordpress_client/post.rb', line 8

def excerpt_html
  @excerpt_html
end

Returns the featured image, as an instance of Media.

Returns:

  • (Media, nil)

    the featured image, as an instance of Media

See Also:



46
47
48
# File 'lib/wordpress_client/post.rb', line 46

def featured_media
  @featured_media
end

Returns the value of attribute featured_media_id.



8
9
10
# File 'lib/wordpress_client/post.rb', line 8

def featured_media_id
  @featured_media_id
end

#guidString

Returns the permalink/GUID of the post for internal addressing.

Returns:

  • (String)

    the permalink/GUID of the post for internal addressing

See Also:



27
28
29
# File 'lib/wordpress_client/post.rb', line 27

def guid
  @guid
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/wordpress_client/post.rb', line 8

def id
  @id
end

#metaHash<String,String>

Returns the Post meta, as a Hash of String => String.

Examples:

post.meta # => {"Mood" => "Happy", "reviewed_by" => "user:45"}

Returns:

  • (Hash<String,String>)

    the post meta, as a Hash.

See Also:



50
51
52
# File 'lib/wordpress_client/post.rb', line 50

def meta
  @meta
end

#slugObject

Returns the value of attribute slug.



8
9
10
# File 'lib/wordpress_client/post.rb', line 8

def slug
  @slug
end

#status"publish", ...

Returns the current status of the post, or nil if undetermined.

Returns:

  • ("publish", "future", "draft", "pending", "private", nil)

    the current status of the post, or nil if undetermined



34
35
36
# File 'lib/wordpress_client/post.rb', line 34

def status
  @status
end

#tag_idsObject

Returns the value of attribute tag_ids.



8
9
10
# File 'lib/wordpress_client/post.rb', line 8

def tag_ids
  @tag_ids
end

#tagsArray[Tag]

Returns the Tags the post belongs to.

Returns:

  • (Array[Tag])

    the Tags the post belongs to.

See Also:



42
43
44
# File 'lib/wordpress_client/post.rb', line 42

def tags
  @tags
end

#title_htmlString

Returns the title of the media, HTML escaped.

Examples:

post.title_html #=> "Fire &#038; diamonds!"

Returns:

  • (String)

    the title of the media, HTML escaped



16
17
18
# File 'lib/wordpress_client/post.rb', line 16

def title_html
  @title_html
end

#updated_atTime?

Returns the modification date of the post, in UTC if available.

Returns:

  • (Time, nil)

    the modification date of the post, in UTC if available



24
25
26
# File 'lib/wordpress_client/post.rb', line 24

def updated_at
  @updated_at
end

#urlString

Returns the URL (link) to the post.

Returns:

  • (String)

    the URL (link) to the post



31
32
33
# File 'lib/wordpress_client/post.rb', line 31

def url
  @url
end

Class Method Details

.parse(data) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



61
62
63
# File 'lib/wordpress_client/post.rb', line 61

def self.parse(data)
  PostParser.parse(data)
end

Instance Method Details

Returns the featured media, if the featured media is an image.



103
104
105
106
107
# File 'lib/wordpress_client/post.rb', line 103

def featured_image
  if featured_media
    featured_media.as_image
  end
end