class Bizside::Redmine::Connection
Attributes
api_key[R]
host[R]
verify_ssl[R]
Public Class Methods
new(overrides = {})
click to toggle source
# File lib/bizside/redmine/connection.rb, line 7 def initialize(overrides = {}) @host = overrides[:host] || Bizside::Redmine::Client.config[:host] @api_key = overrides[:api_key] || Bizside::Redmine::Client.config[:api_key] @verify_ssl = overrides.has_key?(:verify_ssl) ? overrides[:verify_ssl] : Bizside::Redmine::Client.config[:verify_ssl] end
Public Instance Methods
get(path, params = {})
click to toggle source
# File lib/bizside/redmine/connection.rb, line 15 def get(path, params = {}) begin connection.get(path, params) do |request| request.headers['X-Redmine-API-Key'] = api_key end rescue Faraday::ConnectionFailed raise 'Could not connect to the Redmine server.' end end
post(path, params = {})
click to toggle source
# File lib/bizside/redmine/connection.rb, line 25 def post(path, params = {}) begin connection.post(path) do |request| request.headers['X-Redmine-API-Key'] = api_key request.headers['Content-Type'] = 'application/json' request.body = params.to_json end rescue Faraday::ConnectionFailed raise 'Could not connect to the Redmine server.' end end
post_or_put(path, content)
click to toggle source
# File lib/bizside/redmine/connection.rb, line 49 def post_or_put(path, content) begin connection.put(path) do |request| request.headers['X-Redmine-API-Key'] = api_key request.headers['Content-Type'] = 'application/xml' request.body = content end rescue Faraday::ConnectionFailed raise 'Could not connect to the Redmine server.' end end
post_with_multipart(path, params = {})
click to toggle source
# File lib/bizside/redmine/connection.rb, line 61 def post_with_multipart(path, params = {}) begin connection(:multipart => true).post(path) do |request| request.headers['X-Redmine-API-Key'] = api_key request.headers['Content-Type'] = 'application/octet-stream' request.body = File.binread(params[:file].path) end rescue Faraday::ConnectionFailed raise 'Could not connect to the Redmine server.' end end
put(path, params = {})
click to toggle source
# File lib/bizside/redmine/connection.rb, line 37 def put(path, params = {}) begin connection.put(path) do |request| request.headers['X-Redmine-API-Key'] = api_key request.headers['Content-Type'] = 'application/json' request.body = params.to_json end rescue Faraday::ConnectionFailed raise 'Could not connect to the Redmine server.' end end
Private Instance Methods
connection(options = {})
click to toggle source
# File lib/bizside/redmine/connection.rb, line 75 def connection(options = {}) Faraday.new(:url => 'https://' + host, :ssl => ssl_options) do |faraday| if options[:multipart] faraday.request :multipart else faraday.request :url_encoded end faraday.adapter Faraday.default_adapter end end
ssl_options()
click to toggle source
# File lib/bizside/redmine/connection.rb, line 86 def ssl_options ssl_dir = File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), 'ssl')) { :ca_path => ssl_dir, :ca_file => File.join(ssl_dir, 'cert.pem'), :verify => verify_ssl, } end