add mock recommender service for development, add user-context recommended posts

This commit is contained in:
r888888888
2018-07-21 13:24:43 -07:00
parent 93c074c15b
commit 344c46ed00
20 changed files with 250 additions and 33 deletions

View File

@@ -0,0 +1,22 @@
require 'socket'
require 'timeout'
require 'httparty'
module MockServiceHelper
extend self
DANBOORU_PORT = 3000
def fetch_post_ids()
begin
s = TCPSocket.new("localhost", DANBOORU_PORT)
s.close
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
sleep 1
retry
end
json = HTTParty.get("http://localhost:#{DANBOORU_PORT}/posts.json?random=true&limit=10").body
return JSON.parse(json).map {|x| x["id"]}
end
end