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



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

def caption
  data["caption"]
end

#comment_countObject



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

def comment_count
  data["commentCount"].to_i
end

#dataObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/instagrammer/post.rb', line 26

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

#inspectObject



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

def inspect
  attributes = i(shortcode caption upload_date comment_count like_count)
  attributes += i(image_url image_urls) if photo?
  attributes << "watch_count" if video?
  "#<#{self.class.name}:#{object_id} #{attributes.map { |attr| "#{attr}:#{send(attr).inspect}" }.join(", ")}>"
end

#like_countObject



65
66
67
# File 'lib/instagrammer/post.rb', line 65

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

#photo?Boolean

Returns:

  • (Boolean)


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

def photo?
  type == :photo
end

#public?Boolean

Returns:

  • (Boolean)


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

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

#typeObject



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

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

#upload_dateObject



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

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

#userObject



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

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

#video?Boolean

Returns:

  • (Boolean)


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

def video?
  type == :video
end

#watch_countObject



69
70
71
# File 'lib/instagrammer/post.rb', line 69

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