Sha256: a3abe66be69fca56dcbd3f073ffd63f12644aa2193fda3a9d291d3674e82f5e0

Contents?: true

Size: 1.36 KB

Versions: 4

Compression:

Stored size: 1.36 KB

Contents

module CureLine
  class Post < Mash
    include TimeMethods
    include ResourceMethods

    # @return [String]
    def nickname
      dig("post", "userInfo", "nickname")
    end

    # @return [String]
    def picture_url
      dig("post", "userInfo", "pictureUrl")
    end

    # @return [String]
    def post_url
      home_id = dig("post", "postInfo", "homeId")
      post_id = dig("post", "postInfo", "postId")
      "https://timeline.line.me/post/#{home_id}/#{post_id}"
    end

    # @return [String]
    def text
      dig("post", "contents", "text")
    end

    # @return [ActiveSupport::TimeWithZone] When `Time.zone` is initialized
    # @return [Time] When `Time.zone` is not initialized or without activesupport
    def created_time
      millisec = dig("post", "postInfo", "createdTime")
      time_at(millisec / 1000)
    end

    # @return [ActiveSupport::TimeWithZone] When `Time.zone` is initialized
    # @return [Time] When `Time.zone` is not initialized or without activesupport
    def updated_time
      millisec = dig("post", "postInfo", "updatedTime")
      time_at(millisec / 1000)
    end

    # @return [Array<String>]
    def photo_urls
      medias.select { |media| media["type"] == "PHOTO" }.map { |media| resource_url(media["resourceId"]) }
    end

    # @return [Array<Hash>]
    def medias
      dig("post", "contents", "media") || []
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cure_line-1.0.1 lib/cure_line/post.rb
cure_line-1.0.0 lib/cure_line/post.rb
cure_line-0.1.3 lib/cure_line/post.rb
cure_line-0.1.2 lib/cure_line/post.rb