Module: X::Resources::References

Included in:
Post
Defined in:
x-resources/lib/x/resources/references.rb

Overview

Resolves the posts a post refers to through its referenced_posts attribute

Internal to x-resources: the methods it gives a post, such as replied_to, are public API, but the module is only how they are shared, and which classes extend or include it can change within 1.x.

Instance Method Summary collapse

Instance Method Details

#quote? ⇒ Boolean

Check whether this post is a quote

Examples:

Check whether a post is a quote

post.quote?

Returns:

  • (Boolean) —

    true if the post quotes another post



88
89
90
# File 'x-resources/lib/x/resources/references.rb', line 88

def quote?
  !quoted.nil?
end

#quoted ⇒ Post?

The post this post quotes

Examples:

Get the quoted post

post.quoted

Returns:

  • (Post, nil) —

    the quoted post

Raises:

  • (InvalidAttribute) —

    if the response holds a referenced post that is not an object



57
58
59
# File 'x-resources/lib/x/resources/references.rb', line 57

def quoted
  reference(QUOTED)
end

#references ⇒ Array<Post>

The referenced posts, resolved from the includes or built as stubs

Examples:

Get the referenced posts

post.references

Returns:

  • (Array<Post>) —

    the referenced posts

Raises:

  • (InvalidAttribute) —

    if the response holds a referenced post that is not an object



33
34
35
36
37
# File 'x-resources/lib/x/resources/references.rb', line 33

def references
  referenced_posts.filter_map do |reference|
    resolve(Post, reference["id"]) #: Post?
  end.freeze
end

#replied_to ⇒ Post?

The post this post replies to

Examples:

Get the replied-to post

post.replied_to

Returns:

  • (Post, nil) —

    the replied-to post

Raises:

  • (InvalidAttribute) —

    if the response holds a referenced post that is not an object



46
47
48
# File 'x-resources/lib/x/resources/references.rb', line 46

def replied_to
  reference(REPLIED_TO)
end

#reply? ⇒ Boolean

Check whether this post is a reply

Examples:

Check whether a post is a reply

post.reply?

Returns:

  • (Boolean) —

    true if the post replies to another post



78
79
80
# File 'x-resources/lib/x/resources/references.rb', line 78

def reply?
  !replied_to.nil?
end

#repost? ⇒ Boolean Also known as: retweet?

Check whether this post is a repost

Examples:

Check whether a post is a repost

post.repost?

Returns:

  • (Boolean) —

    true if the post reposts another post



98
99
100
# File 'x-resources/lib/x/resources/references.rb', line 98

def repost?
  !reposted.nil?
end

#reposted ⇒ Post? Also known as: retweeted

The post this post reposts

Examples:

Get the reposted post

post.reposted

Returns:

  • (Post, nil) —

    the reposted post

Raises:

  • (InvalidAttribute) —

    if the response holds a referenced post that is not an object



68
69
70
# File 'x-resources/lib/x/resources/references.rb', line 68

def reposted
  reference(REPOSTED, RETWEETED)
end