2016-01-27 01:51:23 -05:00
|
|
|
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
|
|
|
|
|
2017-06-15 20:08:15 -04:00
|
|
|
def request(url)
|
|
|
|
JSON.parse(Excon.get(url, headers: auth_header(@username, @password)))
|
2016-01-27 01:51:23 -05:00
|
|
|
end
|
2017-06-15 20:08:15 -04:00
|
|
|
|
2016-01-27 01:51:23 -05:00
|
|
|
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
|