Class: FerrisBueller::JiraAPI
- Inherits:
-
Object
- Object
- FerrisBueller::JiraAPI
- Defined in:
- lib/ferris-bueller/jira_api.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ JiraAPI
constructor
A new instance of JiraAPI.
- #send(path, data = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ JiraAPI
Returns a new instance of JiraAPI.
11 12 13 14 15 16 17 18 |
# File 'lib/ferris-bueller/jira_api.rb', line 11 def initialize ={} @user = .fetch :user @pass = .fetch :pass @api_url = .fetch :api_url @base_path = .fetch :base_path, '/rest/api/2' @logger = .fetch :logger, Slog.new log.debug event: 'Jira API client initialized' end |
Instance Method Details
#send(path, data = {}) ⇒ Object
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 45 46 47 48 49 50 51 52 |
# File 'lib/ferris-bueller/jira_api.rb', line 20 def send path, data={} uri = URI File.join(@api_url, @base_path, path) http = Net::HTTP.new uri.hostname, uri.port http.use_ssl if uri.scheme == 'https' req = Net::HTTP::Post.new uri req.basic_auth @user, @pass req['Content-Type'] = 'application/json' req['Accept'] = 'application/json' req.body = JSON.generate data log.debug \ event: 'sending Jira API request', path: path, data: data raw_res = http.request(req).body begin return nil unless raw_res res = JSON.parse raw_res, symbolize_names: true log.debug \ event: 'Jira API request returned', path: path, data: data, response: res res rescue => e log.error \ event: 'exception parsing jira response', response: raw_res.inspect, exception: e.class, message: e..inspect, backtrace: e.backtrace raise e end end |