lib/aptly_snapshot.rb in aptly_cli-0.1.3 vs lib/aptly_snapshot.rb in aptly_cli-0.1.4

- old
+ new

@@ -10,14 +10,14 @@ # Load aptly-cli.conf and establish base_uri config = AptlyCli::AptlyLoad.new.configure_with("/etc/aptly-cli.conf") base_uri "http://#{config[:server]}:#{config[:port]}/api" - def snapshot_delete(name, force=0) + def snapshot_delete(name, force=nil) uri = "/snapshots/#{name}" - if force == 1 + if force == true uri = uri + "?force=1" end self.class.delete(uri) end @@ -69,11 +69,11 @@ if search_options.has_key?(:q) @options[:query] = {q: "Name (~ #{search_options[:q]})" } end - if search_options[:withDeps] == 1 + if search_options[:withDeps] == true @options[:query] = {withDeps: "1" } end self.class.get(uri, @options) @@ -82,16 +82,28 @@ def snapshot_show(name) uri = "/snapshots/#{name}" self.class.get(uri) end - def snapshot_update(name, name_update, description=nil) + def snapshot_update(name, new_name, description=nil) uri = "/snapshots/#{name}" + unless new_name.nil? + snap_name = name + else + snap_name = new_name + end + + @query = {} + @query[:Name] = snap_name + + unless description.nil? + @query[:Description] = description + end + @query_json = @query.to_json + begin - self.class.put(uri, :query => { 'Name' => name_update, - 'Description' => description }.to_json, - :headers => {'Content-Type'=>'application/json'}) + self.class.put(uri, :query => @query_json, :headers => {'Content-Type'=>'application/json'}) rescue HTTPary::Error => e puts e end end