class Gemnasium::GitlabService::Connection

Constants

DEFAULT_AGENT
DEFAULT_API_VERSION
DEFAULT_ENDPOINT
DEFAULT_SSL

Public Class Methods

new(options = {}) click to toggle source
# File lib/gemnasium/gitlab_service/connection.rb, line 12
def initialize(options = {})
  use_ssl = options.fetch(:use_ssl){ DEFAULT_SSL }
  host = options.fetch(:host){ DEFAULT_ENDPOINT }
  port = options.fetch(:port){ use_ssl ? 443 : 80 }
  api_version = options.fetch(:api_version){ DEFAULT_API_VERSION }.to_s

  @connection = Net::HTTP.new(host, port)
  @connection.use_ssl = use_ssl
  @api_key = options.fetch(:api_key)
  @base_url = "/#{ api_version }/"
end

Public Instance Methods

get(path, headers = {}) click to toggle source
# File lib/gemnasium/gitlab_service/connection.rb, line 31
def get(path, headers = {})
  request = Net::HTTP::Get.new(@base_url + path, headers.merge('Accept' => 'application/json', 'Content-Type' => 'application/json', 'User-Agent' => DEFAULT_AGENT))
  request.basic_auth('X', @api_key)
  @connection.request(request)
end
post(path, body, headers = {}) click to toggle source
# File lib/gemnasium/gitlab_service/connection.rb, line 24
def post(path, body, headers = {})
  request = Net::HTTP::Post.new(@base_url + path, headers.merge('Accept' => 'application/json', 'Content-Type' => 'application/json', 'User-Agent' => DEFAULT_AGENT))
  request.basic_auth('X', @api_key)
  request.body = body
  @connection.request(request)
end