class CureLine::User

Attributes

user_id[R]

Public Class Methods

new(user_id) click to toggle source

@param user_id [String]

@example

# read https://timeline.line.me/user/_dYbbV3vmaJrvqBoV5ZlpCbPN2CWUZdDQayBvjBE
user = CureLine::User.new("_dYbbV3vmaJrvqBoV5ZlpCbPN2CWUZdDQayBvjBE")
# File lib/cure_line/user.rb, line 15
def initialize(user_id)
  @user_id = user_id
end

Public Instance Methods

header_url() click to toggle source

@return [String]

# File lib/cure_line/user.rb, line 25
def header_url
  resource_url(preloaded_state["userHome"]["homeInfo"]["resourceId"])
end
info() click to toggle source

@return [CureLine::Mash]

# File lib/cure_line/user.rb, line 20
def info
  preloaded_state["userHome"]["homeInfo"]["userInfo"]
end
posts() click to toggle source

@return [Array<CureLine::Post>]

# File lib/cure_line/user.rb, line 30
def posts
  preloaded_state["userHome"]["feeds"].map { |feed| CureLine::Post.new(feed) }
end
preloaded_state() click to toggle source

@return [CureLine::Mash]

# File lib/cure_line/user.rb, line 35
def preloaded_state
  return @preloaded_state if @preloaded_state

  options = {}
  options["User-Agent"] = CureLine.config.user_agent if CureLine.config.user_agent

  url = "https://timeline.line.me/user/#{user_id}"
  html = URI.open(url, options).read

  m = html.match(%r{<script id="init_data" type="application/json">({.+})</script>})
  raise %Q(Not Found <script id="init_data" type="application/json"> in #{url}) unless m

  @preloaded_state = CureLine::Mash.new(JSON.parse(m[1]))
end