Skip to content

Commit

Permalink
Make repo_package_query work w/ multiple options
Browse files Browse the repository at this point in the history
instead of one at a time.
  • Loading branch information
msabramo committed Jul 23, 2016
1 parent e0b3638 commit f62c207
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
16 changes: 7 additions & 9 deletions lib/aptly_repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'aptly_load'
require 'httmultiparty'
require 'json'
require 'uri'

module AptlyCli
# Aptly class to work with Repo API
Expand Down Expand Up @@ -58,15 +59,12 @@ def repo_package_query(repo_options = { name: nil, query: nil,
else
uri = '/repos/' + repo_options[:name] + '/packages'
end
uri += if repo_options[:query]
"?q=#{repo_options[:query]}"
elsif repo_options[:format]
"?format=#{repo_options[:format]}"
elsif repo_options[:with_deps]
'?withDeps=1'
else
''
end

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
end

Expand Down
13 changes: 10 additions & 3 deletions test/test_aptly_repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,16 @@ def test_package_query_with_name
name: 'testrepotoquery',
dir: 'testdir2/',
file: 'test_1.0_amd64.deb')
assert_includes repo_api.repo_package_query(name: 'testrepotoquery',
query: 'geoipupdate').to_s,
'["Pamd64 geoipupdate 2.0.0'
res = repo_api.repo_package_query(
name: 'testrepotoquery',
query: 'geoipupdate',
with_deps: true,
format: 'details',
)
assert_equal res.request.uri.to_s,
'http://127.0.0.1:8082/api/repos/testrepotoquery/packages'\
'?q=geoipupdate&format=details&withDeps=1'
assert_includes res.to_s, 'Pamd64 geoipupdate 2.0.0'
end
end

Expand Down

0 comments on commit f62c207

Please sign in to comment.