11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/localization/smartcat/SmartcatCollections.rb', line 11
def self.collections
uri = URI.parse("https://smartcat.com/api/integration/v1/project/#{LocalizationSmartcatInfo::Project_AirBrush}")
request = Net::HTTP::Get.new(uri)
request.basic_auth(LocalizationSmartcatInfo::USERNAME, LocalizationSmartcatInfo::PASSWORD)
request['Content-Type'] = 'application/json'
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(request)
end
if response.code.to_i == 200
project_info = JSON.parse(response.body)
if project_info.nil?
puts "请求失败,响应为空".red
return
end
documents = project_info["documents"]
if documents.nil?
puts "请求失败,documents为空".red
return
end
collections = documents.map { |document| document['name'] }.uniq
else
puts "请求失败,状态码: #{response.code}, 响应: #{response.body}".red
end
end
|