class SocialNet::Instagram::Models::Video

Attributes

caption[R]
id[R]
thumbnail_url[R]
video_url[R]

Public Class Methods

find_by(params = {}) click to toggle source

Returns the existing Instagram video matching the provided attributes or nil when the video is not found.

@return [SocialNet::Instagram::Models::Video] when the video is found. @return [nil] when the video is not found. @param [Hash] params the attributes to find a video by. @option params [String] :media_id The Instagram video's media id.

# File lib/social_net/instagram/models/video.rb, line 26
def self.find_by(params = {})
  find_by! params
rescue Errors::UnknownVideo
  nil
end
find_by!(params = {}) click to toggle source

Returns the existing Instagram video matching the provided attributes or raises an error when the video is not found.

@return [SocialNet::Instagram::Models::Video] when the video is found. @return [nil] when the video is not found. @param [Hash] params the attributes to find a video by. @option params [String] :media_id The Instagram video's media id. @raise [SocialNet::Errors::UnknownVideo] if the video is not found.

# File lib/social_net/instagram/models/video.rb, line 40
def self.find_by!(params = {})
  if params[:shortcode]
    find_by_shortcode! params[:shortcode]
  end
end
new(attrs = {}) click to toggle source
# File lib/social_net/instagram/models/video.rb, line 11
def initialize(attrs = {})
  @id = attrs['id']
  @video_url = attrs['video_url']
  @thumbnail_url = attrs['thumbnail_url']
  @link = attrs['link']
  @caption = attrs['caption'] if attrs['caption']
end

Private Class Methods

find_by_shortcode!(id) click to toggle source
# File lib/social_net/instagram/models/video.rb, line 48
def self.find_by_shortcode!(id)
  request = Api::ScrapeRequest.new shortcode: id
  video = request.run
  new video
rescue Errors::ResponseError => error
  case error.response
  when Net::HTTPBadRequest then raise Errors::UnknownVideo
  when Net::HTTPNotFound then raise Errors::UnknownVideo
  end
end