mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:26:54 -06:00
30990006a9
This reduces chances of errors where consumers of strings mutate inputs and reduces memory usage of the app. Test suite passes now, but there may be some stuff left, so we will run a few sites on a branch prior to merging
56 lines
1.1 KiB
Ruby
56 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'base64'
|
|
require 'json'
|
|
|
|
class QuandoraApi
|
|
|
|
attr_accessor :domain, :username, :password
|
|
|
|
def initialize(domain, username, password)
|
|
@domain = domain
|
|
@username = username
|
|
@password = password
|
|
end
|
|
|
|
def base_url(domain)
|
|
"https://#{domain}.quandora.com/m/json"
|
|
end
|
|
|
|
def auth_header(username, password)
|
|
encoded = Base64.encode64 "#{username}:#{password}"
|
|
{ Authorization: "Basic #{encoded.strip!}" }
|
|
end
|
|
|
|
def list_bases_url
|
|
"#{base_url @domain}/kb"
|
|
end
|
|
|
|
def list_questions_url(kb_id, limit)
|
|
url = "#{base_url @domain}/kb/#{kb_id}/list"
|
|
url = "#{url}?l=#{limit}" if limit
|
|
url
|
|
end
|
|
|
|
def request(url)
|
|
JSON.parse(Excon.get(url, headers: auth_header(@username, @password)))
|
|
end
|
|
|
|
def list_bases
|
|
response = request list_bases_url
|
|
response['data']
|
|
end
|
|
|
|
def list_questions(kb_id, limit = nil)
|
|
url = list_questions_url(kb_id, limit)
|
|
response = request url
|
|
response['data']['result']
|
|
end
|
|
|
|
def get_question(question_id)
|
|
url = "#{base_url @domain}/q/#{question_id}"
|
|
response = request url
|
|
response['data']
|
|
end
|
|
end
|