class Jira::API
Public Instance Methods
delete(path, options={})
click to toggle source
# File lib/jira/api.rb, line 19 def delete(path, options={}) response = client.delete(path, options[:params] || {}, headers) process(response, options) end
get(path, options={})
click to toggle source
# File lib/jira/api.rb, line 4 def get(path, options={}) response = client.get(path, options[:params] || {}, headers) process(response, options) end
patch(path, options={})
click to toggle source
# File lib/jira/api.rb, line 14 def patch(path, options={}) response = client.put(path, options[:params] || {}, headers) process(response, options) end
post(path, options={})
click to toggle source
# File lib/jira/api.rb, line 9 def post(path, options={}) response = client.post(path, options[:params] || {}, headers) process(response, options) end
Protected Instance Methods
client()
click to toggle source
# File lib/jira/api.rb, line 49 def client @client ||= Faraday.new(endpoint) do |faraday| faraday.request :basic_auth, Jira::Core.username, Jira::Core.password unless Jira::Core.password.nil? faraday.request :token_auth, Jira::Core.token unless Jira::Core.token.nil? faraday.request :json faraday.response :json faraday.adapter :net_http end end
endpoint()
click to toggle source
# File lib/jira/api.rb, line 59 def endpoint "#{Jira::Core.url}/rest/api/2" end
headers()
click to toggle source
# File lib/jira/api.rb, line 63 def headers { 'Content-Type' => 'application/json' }.merge(cookies) end
process(response, options)
click to toggle source
# File lib/jira/api.rb, line 26 def process(response, options) raise UnauthorizedException if response.status == 401 body = response.body || {} json = (body if body.class == Hash) || {} if response.success? && json['errorMessages'].nil? respond_to(options[:success], body) else puts json['errorMessages'].join('. ') unless json['errorMessages'].nil? respond_to(options[:failure], body) end body end
respond_to(block, body)
click to toggle source
# File lib/jira/api.rb, line 39 def respond_to(block, body) return if block.nil? case block.arity when 0 block.call when 1 block.call(body) end end