Class: Instagrammer::Post
- Inherits:
-
Object
- Object
- Instagrammer::Post
- Includes:
- Capybara::DSL, Utils
- Defined in:
- lib/instagrammer/post.rb
Instance Attribute Summary collapse
-
#image_url ⇒ Object
readonly
Returns the value of attribute image_url.
-
#image_urls ⇒ Object
readonly
Returns the value of attribute image_urls.
-
#shortcode ⇒ Object
readonly
Returns the value of attribute shortcode.
Instance Method Summary collapse
- #caption ⇒ Object
- #comment_count ⇒ Object
- #data ⇒ Object
-
#initialize(shortcode) ⇒ Post
constructor
A new instance of Post.
- #inspect ⇒ Object
- #like_count ⇒ Object
- #photo? ⇒ Boolean
- #public? ⇒ Boolean
- #type ⇒ Object
- #upload_date ⇒ Object
- #user ⇒ Object
- #video? ⇒ Boolean
- #watch_count ⇒ Object
Methods included from Utils
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_url ⇒ Object (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_urls ⇒ Object (readonly)
Returns the value of attribute image_urls.
7 8 9 |
# File 'lib/instagrammer/post.rb', line 7 def image_urls @image_urls end |
#shortcode ⇒ Object (readonly)
Returns the value of attribute shortcode.
7 8 9 |
# File 'lib/instagrammer/post.rb', line 7 def shortcode @shortcode end |
Instance Method Details
#caption ⇒ Object
53 54 55 |
# File 'lib/instagrammer/post.rb', line 53 def caption data["caption"] end |
#comment_count ⇒ Object
61 62 63 |
# File 'lib/instagrammer/post.rb', line 61 def comment_count data["commentCount"].to_i end |
#data ⇒ Object
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 |
#inspect ⇒ Object
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_count ⇒ Object
65 66 67 |
# File 'lib/instagrammer/post.rb', line 65 def like_count data["interactionStatistic"]["userInteractionCount"].to_i if photo? end |
#photo? ⇒ Boolean
41 42 43 |
# File 'lib/instagrammer/post.rb', line 41 def photo? type == :photo end |
#public? ⇒ Boolean
21 22 23 24 |
# File 'lib/instagrammer/post.rb', line 21 def public? get_data unless @data @status == :public end |
#type ⇒ Object
37 38 39 |
# File 'lib/instagrammer/post.rb', line 37 def type data["@type"] == "ImageObject" ? :photo : :video end |
#upload_date ⇒ Object
57 58 59 |
# File 'lib/instagrammer/post.rb', line 57 def upload_date DateTime.parse data["uploadDate"] end |
#user ⇒ Object
49 50 51 |
# File 'lib/instagrammer/post.rb', line 49 def user Instagrammer::User.new data["author"]["alternateName"] end |
#video? ⇒ Boolean
45 46 47 |
# File 'lib/instagrammer/post.rb', line 45 def video? type == :video end |
#watch_count ⇒ Object
69 70 71 |
# File 'lib/instagrammer/post.rb', line 69 def watch_count data["interactionStatistic"]["userInteractionCount"].to_i if video? end |