class OnlyofficeBugzillaHelper::BugzillaHelper
Class to check bugzilla via http
Attributes
url[R]
Public Class Methods
new(bugzilla_url: 'https://bugzilla.onlyoffice.com', api_key: BugzillaHelper.read_token)
click to toggle source
# File lib/onlyoffice_bugzilla_helper.rb, line 25 def initialize(bugzilla_url: 'https://bugzilla.onlyoffice.com', api_key: BugzillaHelper.read_token) @url = URI.parse(bugzilla_url) @key = api_key @show_bug_path = '/show_bug.cgi' @show_bug_param = 'id' end
read_token(force_file_read: false, token_path: "
click to toggle source
Read access token from file system @param force_file_read [True, False] force read api key from file @param token_path [String] path to file with API Token @return [String] token
# File lib/onlyoffice_bugzilla_helper.rb, line 53 def self.read_token(force_file_read: false, token_path: "#{Dir.home}/.bugzilla/api_key") return ENV['BUGZILLA_API_KEY'] if ENV['BUGZILLA_API_KEY'] && !force_file_read File.read(token_path).delete("\n") rescue Errno::ENOENT raise Errno::ENOENT, "No access token found in #{Dir.home}/.bugzilla/api_key" \ "Please create files #{Dir.home}/.bugzilla/api_key" end
Public Instance Methods
bug_id_from_string(string)
click to toggle source
Get bug id from url @param string [String] string for error @return [Integer, Nil] result of bug id from url
# File lib/onlyoffice_bugzilla_helper.rb, line 36 def bug_id_from_string(string) uri = URI.parse(string) return nil unless uri.host == url.host return nil unless uri.path == @show_bug_path id = CGI.parse(uri.query)[@show_bug_param].first.to_i return nil if id.zero? id rescue URI::InvalidURIError nil end
Private Instance Methods
bug_url(id, suffix = '')
click to toggle source
@param id [Integer] id of bug @return [String] url of bug on server with api key
# File lib/onlyoffice_bugzilla_helper.rb, line 68 def bug_url(id, suffix = '') "/rest/bug/#{id}#{suffix}?api_key=#{@key}" end
get_bug_result(bug_id)
click to toggle source
@param bug_id [Integer] id of bug @return [Net::HTTPResponse] result of request
# File lib/onlyoffice_bugzilla_helper.rb, line 74 def get_bug_result(bug_id) req = Net::HTTP::Get.new(bug_url(bug_id)) perform_request(req) end