lib/aptly_repo.rb in aptly_cli-0.5.0 vs lib/aptly_repo.rb in aptly_cli-0.6.0
- old
+ new
@@ -12,100 +12,96 @@
def repo_create(repo_options = { name: nil,
comment: nil,
DefaultDistribution: nil,
DefaultComponent: nil })
+ raise ArgumentError, 'Repository name is required' if repo_options[:name].nil? || repo_options[:name].empty?
+
uri = '/repos'
name = repo_options[:name]
comment = repo_options[:comment]
default_distribution = repo_options[:DefaultDistribution]
default_component = repo_options[:DefaultComponent]
- self.class.post(uri,
+ post(uri,
:body =>
{ 'Name' => name, 'Comment' => comment,
'DefaultDistribution' => default_distribution,
'DefaultComponent' => default_component }.to_json,
:headers => { 'Content-Type' => 'application/json' })
end
def repo_delete(repo_options = { name: nil, force: nil })
+ raise ArgumentError, 'Repository name is required' if repo_options[:name].nil? || repo_options[:name].empty?
+
uri = '/repos/' + repo_options[:name]
uri += '?force=1' if repo_options[:force] == true
- self.class.delete(uri)
+ delete(uri)
end
- def repo_edit(name, repo_options = { k => v })
- repo_option = ''
- repo_value = ''
- uri = '/repos/' + name unless name.nil?
- repo_options.each do |k, v|
- repo_option = k
- repo_value = v
- end
+ def repo_edit(name, repo_options)
+ raise ArgumentError, 'Repository name is required' if name.nil? || name.empty?
- self.class.put(uri, :body => { repo_option => repo_value }.to_json,
+ uri = "/repos/#{name}"
+
+ put(uri, :body => repo_options.to_json,
:headers => { 'Content-Type' => 'application/json' })
end
def repo_list
uri = '/repos'
- self.class.get(uri)
+ get(uri)
end
def repo_package_add(repo_options, packages)
- if !repo_options.is_a?(Hash) || repo_options[:name].nil?
- raise ArgumentError.new('Must pass a repository name')
- end
+ raise ArgumentError, 'Repository name is required' if repo_options[:name].nil? || repo_options[:name].empty?
uri = '/repos/' + repo_options[:name] + '/packages'
- self.class.post(
+ post(
uri,
:body => { PackageRefs: packages }.to_json,
:headers => { 'Content-Type' => 'application/json' }
)
end
def repo_package_delete(repo_options, packages)
- if !repo_options.is_a?(Hash) || repo_options[:name].nil?
- raise ArgumentError.new('Must pass a repository name')
- end
+ raise ArgumentError, 'Repository name is required' if repo_options[:name].nil? || repo_options[:name].empty?
uri = '/repos/' + repo_options[:name] + '/packages'
- self.class.delete(
+ delete(
uri,
:body => { PackageRefs: packages }.to_json,
:headers => { 'Content-Type' => 'application/json' }
)
end
def repo_package_query(repo_options = { name: nil, query: nil,
with_deps: false,
format: nil })
- if repo_options[:name].nil?
- raise ArgumentError.new('Must pass a repository name')
- else
- uri = '/repos/' + repo_options[:name] + '/packages'
- end
+ raise ArgumentError, 'Repository name is required' if repo_options[:name].nil? || repo_options[:name].empty?
+ uri = '/repos/' + repo_options[:name] + '/packages'
+
qs_hash = {}
qs_hash['q'] = repo_options[:query] if repo_options[:query]
qs_hash['format'] = repo_options[:format] if repo_options[:format]
qs_hash['withDeps'] = 1 if repo_options[:with_deps]
uri += '?' + URI.encode_www_form(qs_hash) if qs_hash
- self.class.get uri
+ get uri
end
def repo_show(name)
uri = if name.nil?
'/repos'
else
'/repos/' + name
end
- self.class.get uri
+ get uri
end
def repo_upload(repo_options = { name: nil, dir: nil, file: nil,
noremove: false, forcereplace: false })
+ raise ArgumentError, 'Repository name is required' if repo_options[:name].nil? || repo_options[:name].empty?
+
name = repo_options[:name]
dir = repo_options[:dir]
file = repo_options[:file]
noremove = repo_options[:noremove]
forcereplace = repo_options[:forcereplace]