Class: Instagrammer::Post

Inherits:
Object
  • Object
show all
Includes:
Capybara::DSL, Utils
Defined in:
lib/instagrammer/post.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#get_page_status

Constructor Details

#initialize(shortcode) ⇒ Post

Returns a new instance of Post.



9
10
11
12
# File 'lib/instagrammer/post.rb', line 9

def initialize(shortcode)
  @shortcode = shortcode
  @data = nil
end

Instance Attribute Details

#image_urlObject (readonly)

Returns the value of attribute image_url.



7
8
9
# File 'lib/instagrammer/post.rb', line 7

def image_url
  @image_url
end

#image_urlsObject (readonly)

Returns the value of attribute image_urls.



7
8
9
# File 'lib/instagrammer/post.rb', line 7

def image_urls
  @image_urls
end

#shortcodeObject (readonly)

Returns the value of attribute shortcode.



7
8
9
# File 'lib/instagrammer/post.rb', line 7

def shortcode
  @shortcode
end

Instance Method Details

#captionObject



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

def caption
  data["caption"]
end

#comment_countObject



54
55
56
# File 'lib/instagrammer/post.rb', line 54

def comment_count
  data["commentCount"].to_i
end

#dataObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/instagrammer/post.rb', line 19

def data
  get_data unless @data

  case @status
  when :private then raise Instagrammer::PrivatePost.new("Private post: #{@shortcode}")
  when :not_found then raise Instagrammer::PostNotFound.new("Post not found: #{@shortcode}")
  when :invalid then raise Instagrammer::PostInvalid.new("Post invalid: #{@shortcode}")
  else @data
  end
end

#like_countObject



58
59
60
# File 'lib/instagrammer/post.rb', line 58

def like_count
  data["interactionStatistic"]["userInteractionCount"].to_i if photo?
end

#photo?Boolean

Returns:

  • (Boolean)


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

def photo?
  type == :photo
end

#public?Boolean

Returns:

  • (Boolean)


14
15
16
17
# File 'lib/instagrammer/post.rb', line 14

def public?
  get_data unless @data
  @status == :public
end

#typeObject



30
31
32
# File 'lib/instagrammer/post.rb', line 30

def type
  data["@type"] == "ImageObject" ? :photo : :video
end

#upload_dateObject



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

def upload_date
  DateTime.parse data["uploadDate"]
end

#userObject



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

def user
  Instagrammer::User.new data["author"]["alternateName"]
end

#video?Boolean

Returns:

  • (Boolean)


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

def video?
  type == :video
end

#watch_countObject



62
63
64
# File 'lib/instagrammer/post.rb', line 62

def watch_count
  data["interactionStatistic"]["userInteractionCount"].to_i if video?
end