class UserRetriever

Public Class Methods

new(parser) click to toggle source
# File lib/retriever/user_retriever.rb, line 6
def initialize(parser)
  @parser = parser
end

Public Instance Methods

load(username) click to toggle source
# File lib/retriever/user_retriever.rb, line 10
def load(username)
  parsed_url = parse_url(username)

  user = UserBuilder.new(parsed_url['User']).build

  posts_raw = parsed_url['Post']
  posts_raw.each { |post_raw| user.add_post(retrieve_post(post_raw)) }

  user
end

Private Instance Methods

parse_url(username) click to toggle source
# File lib/retriever/user_retriever.rb, line 27
def parse_url(username)
  @parser.new("https://www.medium.com/@#{username}?format=json").parse['references']
end
retrieve_post(post_raw) click to toggle source
# File lib/retriever/user_retriever.rb, line 23
def retrieve_post(post_raw)
  PostRetriever.new(@parser).load(user.user_id, post_raw[1]['id'])
end