class SocialNet::Byte::Models::Post

Attributes

author_id[R]
caption[R]
category[R]
comment_count[R]
comments[R]
date[R]
id[R]
like_count[R]
loop_count[R]
mentions[R]
thumb_src[R]
video_src[R]

Public Class Methods

find_by(params = {}) click to toggle source

Returns the existing Byte post matching the provided attributes or nil when the post is not found.

@return [SocialNet::Byte::Models::post] when the post is found. @return [nil] when the post is not found. @param [Hash] params the attributes to find a post by. @option params [String] :id The Byte post’s id

(case-insensitive).
# File lib/social_net/byte/models/post.rb, line 33
def self.find_by(params = {})
  find_by! params
rescue Errors::UnknownPost
  nil
end
find_by!(params = {}) click to toggle source

Returns the existing Byte post matching the provided attributes or nil when the post is not found, and raises an error when the post is not found.

@return [SocialNet::Byte::Models::Post] the Byte post. @param [Hash] params the attributes to find a post by. @option params [String] :id The Byte post id

(case-sensitive).

@raise [SocialNet::Errors::UnknownPost] if the post is unknown.

# File lib/social_net/byte/models/post.rb, line 47
def self.find_by!(params = {})
  if params[:id]
    find_by_id! params[:id]
  end
end
new(attrs = {}) click to toggle source
# File lib/social_net/byte/models/post.rb, line 21
def initialize(attrs = {})
  attrs.each{|k, v| instance_variable_set("@#{k}", v) unless v.nil?}
end

Private Class Methods

find_by_id!(id) click to toggle source
# File lib/social_net/byte/models/post.rb, line 55
def self.find_by_id!(id)
  request = Api::Request.new endpoint: "/post/id/#{id}"
  if post = request.run['data']
    new post.deep_transform_keys { |key| key.underscore.to_sym }
  else
    raise Errors::UnknownPost
  end
end