Try to fix URL lookup errors
This commit is contained in:
parent
3f1039e5dc
commit
5150d965a3
@ -21,7 +21,7 @@ class RedditResponse
|
||||
children: Array(RedditWrapper(RedditChild)))
|
||||
|
||||
def self.from_subreddits(subreddits : Array(String))
|
||||
request_url = "https://www.reddit.com/r/#{subreddits.join "+" }/hot.json?limit=30"
|
||||
request_url = URI.new scheme: "https", host: "www.reddit.com", path: "/r/hot.json", query: "limit=30"
|
||||
response = HTTP::Client.get(request_url, headers: HTTP::Headers {
|
||||
"User-agent" => "Joann-Pupper-Bot"
|
||||
})
|
||||
@ -53,7 +53,8 @@ def filter_reddit_json(json, completed, extensions = ["png", "json"])
|
||||
end
|
||||
|
||||
def get_reddit_post(subreddit, completed)
|
||||
json = RedditResponse.from_subreddit subreddit
|
||||
post = json.try { |json| filter_reddit_json(json, completed).first? }
|
||||
post.try { |post| completed.push(post.name); { post.url, post.title } }
|
||||
return nil unless json = RedditResponse.from_subreddit subreddit
|
||||
return nil unless post = filter_reddit_json(json, completed).first?
|
||||
completed.push(post.name)
|
||||
return { post.url, post.title }
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user