class PostRetriever
Public Class Methods
new(parser)
click to toggle source
# File lib/retriever/post_retriever.rb, line 4 def initialize(parser) @parser = parser end
Public Instance Methods
load(user_id, post_id)
click to toggle source
# File lib/retriever/post_retriever.rb, line 8 def load(user_id, post_id) parsed_url = parse_url(user_id, post_id) Post.new( parsed_url['title'], parsed_url['content']['subtitle'], normalize_content(parsed_url['content']['bodyModel']['paragraphs']), parsed_url['canonicalUrl'] ) end
normalize_content(paragraphs_raw)
click to toggle source
# File lib/retriever/post_retriever.rb, line 19 def normalize_content(paragraphs_raw) body = '' paragraphs_raw[1..-1].each do |paragraph| body << paragraph['text'] + '\n\n' end body end
parse_url(user_id, post_id)
click to toggle source
# File lib/retriever/post_retriever.rb, line 27 def parse_url(user_id, post_id) @parser.new("https://www.medium.com/@#{user_id}/#{post_id}?format=json").parse['value'] end