Class: CureLine::User

Inherits:
Object
  • Object
show all
Includes:
ResourceMethods
Defined in:
lib/cure_line/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ResourceMethods

#resource_url

Constructor Details

#initialize(user_id) ⇒ User

Returns a new instance of User.

Examples:

# read https://timeline.line.me/user/_dYbbV3vmaJrvqBoV5ZlpCbPN2CWUZdDQayBvjBE
user = CureLine::User.new("_dYbbV3vmaJrvqBoV5ZlpCbPN2CWUZdDQayBvjBE")

Parameters:

  • user_id (String)


15
16
17
# File 'lib/cure_line/user.rb', line 15

def initialize(user_id)
  @user_id = user_id
end

Instance Attribute Details

#user_idObject (readonly)

Returns the value of attribute user_id.



6
7
8
# File 'lib/cure_line/user.rb', line 6

def user_id
  @user_id
end

Instance Method Details

#header_urlString

Returns:

  • (String)


25
26
27
# File 'lib/cure_line/user.rb', line 25

def header_url
  resource_url(preloaded_state["userHome"]["homeInfo"]["resourceId"])
end

#infoCureLine::Mash

Returns:



20
21
22
# File 'lib/cure_line/user.rb', line 20

def info
  preloaded_state["userHome"]["homeInfo"]["userInfo"]
end

#postsArray<CureLine::Post>

Returns:



30
31
32
# File 'lib/cure_line/user.rb', line 30

def posts
  preloaded_state["userHome"]["feeds"].map { |feed| CureLine::Post.new(feed) }
end

#preloaded_stateCureLine::Mash

Returns:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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