21 lines
566 B
Ruby
21 lines
566 B
Ruby
class Projects::ElasticsearchService < ApplicationService
|
|
attr_reader :keyword
|
|
|
|
def initialize(keyword)
|
|
@keyword = keyword
|
|
end
|
|
|
|
def call
|
|
domain = EduSetting.get("search_api_url") || "https://statistics.gitlink.org.cn"
|
|
api_url = "#{domain}/search?page=1&size=1000&term=#{@keyword}&type=1"
|
|
response = Faraday.get(api_url)
|
|
result = JSON.parse(response&.body)
|
|
project_ids = result[:data][:rows].map{|d|d[:instanceId]}
|
|
project_ids
|
|
rescue => e
|
|
puts "ElasticsearchService error: #{e.message}"
|
|
raise Error, e.message
|
|
end
|
|
|
|
end
|