Class: CureLine::User
- Inherits:
-
Object
- Object
- CureLine::User
- Includes:
- ResourceMethods
- Defined in:
- lib/cure_line/user.rb
Instance Attribute Summary collapse
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Instance Method Summary collapse
- #header_url ⇒ String
- #info ⇒ CureLine::Mash
-
#initialize(user_id) ⇒ User
constructor
A new instance of User.
- #posts ⇒ Array<CureLine::Post>
- #preloaded_state ⇒ CureLine::Mash
Methods included from ResourceMethods
Constructor Details
#initialize(user_id) ⇒ User
Returns a new instance of User.
15 16 17 |
# File 'lib/cure_line/user.rb', line 15 def initialize(user_id) @user_id = user_id end |
Instance Attribute Details
#user_id ⇒ Object (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_url ⇒ String
25 26 27 |
# File 'lib/cure_line/user.rb', line 25 def header_url resource_url(preloaded_state["userHome"]["homeInfo"]["resourceId"]) end |
#info ⇒ CureLine::Mash
20 21 22 |
# File 'lib/cure_line/user.rb', line 20 def info preloaded_state["userHome"]["homeInfo"]["userInfo"] end |
#posts ⇒ Array<CureLine::Post>
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_state ⇒ CureLine::Mash
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 = {} ["User-Agent"] = CureLine.config.user_agent if CureLine.config.user_agent url = "https://timeline.line.me/user/#{user_id}" html = URI.open(url, ).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 |