Class: OnlyofficeBugzillaHelper::BugzillaHelper
- Inherits:
-
Object
- Object
- OnlyofficeBugzillaHelper::BugzillaHelper
- Includes:
- BugData, Comments, LoggerWrapper, Networking, UpdateBug
- Defined in:
- lib/onlyoffice_bugzilla_helper.rb
Overview
Class to check bugzilla via http
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
-
.read_token(force_file_read: false, token_path: "#{Dir.home}/.bugzilla/api_key") ⇒ String
Read access token from file system.
Instance Method Summary collapse
-
#bug_id_from_string(string) ⇒ Integer, Nil
Get bug id from url.
-
#initialize(bugzilla_url: 'https://bugzilla.onlyoffice.com', api_key: BugzillaHelper.read_token) ⇒ BugzillaHelper
constructor
A new instance of BugzillaHelper.
Methods included from UpdateBug
Methods included from LoggerWrapper
#hide_keys, #log_request, #logger
Methods included from Comments
Methods included from BugData
#bug_data, #bug_exists?, #bug_status, #get_bug_history, #get_bugs_by_filter
Constructor Details
#initialize(bugzilla_url: 'https://bugzilla.onlyoffice.com', api_key: BugzillaHelper.read_token) ⇒ BugzillaHelper
Returns a new instance of BugzillaHelper.
25 26 27 28 29 30 31 |
# 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 |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
23 24 25 |
# File 'lib/onlyoffice_bugzilla_helper.rb', line 23 def url @url end |
Class Method Details
.read_token(force_file_read: false, token_path: "#{Dir.home}/.bugzilla/api_key") ⇒ String
Read access token from file system
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/onlyoffice_bugzilla_helper.rb', line 53 def self.read_token(force_file_read: false, token_path: "#{Dir.home}/.bugzilla/api_key") # rubocop:disable Style/FetchEnvVar return ENV['BUGZILLA_API_KEY'] if ENV.key?('BUGZILLA_API_KEY') && !force_file_read # rubocop:enable Style/FetchEnvVar 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 |
Instance Method Details
#bug_id_from_string(string) ⇒ Integer, Nil
Get bug id from url
36 37 38 39 40 41 42 43 44 45 46 47 |
# 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 |