class Gemnasium::Connection

Public Class Methods

new() click to toggle source
# File lib/gemnasium/connection.rb, line 5
def initialize
  @connection = Net::HTTP.new(Gemnasium.config.site, Gemnasium.config.use_ssl ? 443 : 80)
  @connection.use_ssl = Gemnasium.config.use_ssl
end

Public Instance Methods

api_path_for(item) click to toggle source

Set the API path for a specific item

@param item [String] item the route should point to @return [String] API path

# File lib/gemnasium/connection.rb, line 27
def api_path_for item
  base = "/api/#{Gemnasium.config.api_version}"

  case item
  when 'base'
    base
  when 'projects'
    "#{base}/projects"
  when 'dependency_files'
    "#{base}/projects/#{Gemnasium.config.project_slug}/dependency_files"
  else
    raise "No API path found for #{item}"
  end
end
get(path, headers = {}) click to toggle source
# File lib/gemnasium/connection.rb, line 17
def get(path, headers = {})
  request = Net::HTTP::Get.new(path, headers.merge('Accept' => 'application/json', 'Content-Type' => 'application/json'))
  request.basic_auth('X', Gemnasium.config.api_key)
  @connection.request(request)
end
post(path, body, headers = {}) click to toggle source
# File lib/gemnasium/connection.rb, line 10
def post(path, body, headers = {})
  request = Net::HTTP::Post.new(path, headers.merge('Accept' => 'application/json', 'Content-Type' => 'application/json'))
  request.basic_auth('X', Gemnasium.config.api_key)
  request.body = body
  @connection.request(request)
end