Class: Nexus::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/nexus/repository.rb

Constant Summary collapse

NEXUS_PARAMETERS =
{
  :group => :g,
  :name => :a,
  :type => :p
}

Instance Method Summary collapse

Constructor Details

#initialize(baseuri, username = nil, password = nil) ⇒ Repository

Returns a new instance of Repository.



12
13
14
15
16
# File 'lib/nexus/repository.rb', line 12

def initialize(baseuri, username = nil, password = nil)
  @baseuri = baseuri
  @username = username
  @password = password
end

Instance Method Details

#delete(artifact) ⇒ Object



28
29
30
31
# File 'lib/nexus/repository.rb', line 28

def delete(artifact)
  url = "#{@baseuri}/service/local/repositories/#{artifact.repo}/content/#{artifact.group.gsub(/\./, '/')}/#{artifact.name}/#{artifact.version}/"
  RestClient::Resource.new(url, :user => @username, :password => @password).delete.code
end

#download(artifact) ⇒ Object



24
25
26
# File 'lib/nexus/repository.rb', line 24

def download(artifact)
  RestClient.get(artifact.uri).body
end

#find_artifacts(args) ⇒ Object



18
19
20
21
22
# File 'lib/nexus/repository.rb', line 18

def find_artifacts(args)
  url = "#{@baseuri}/service/local/data_index/repo_groups/public?#{build_query_parameters_from(args)}"
  response = RestClient.get(url, :accept => 'application/json')
  Crack::JSON.parse(response.body)['data'].map {|data| Nexus::Artifact.new(data)}
end

#put(artifact, file) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/nexus/repository.rb', line 33

def put(artifact, file)
  filename = artifact.name

  if(artifact.classifier)
    filename = filename + "-" + artifact.classifier
  end

  filename = filename + "." + artifact.type

  url = "#{@baseuri}/service/local/repositories/#{artifact.repo}/content/#{artifact.group.gsub(/\./, '/')}/#{artifact.name}/#{artifact.version}/#{filename}"
  RestClient::Resource.new(url, :user => @username, :password => @password).put(:file => file).code
end