class AptlyAPI::Repo
This class represents an Aptly repo
Attributes
comment[R]
component[R]
distribution[R]
name[R]
Public Class Methods
new(server, json)
click to toggle source
Creates a new Repo
definitation with data json
located on server
# File lib/repo.rb, line 12 def initialize(server, json) @server = server @http = Net::HTTP.new(@server.host, @server.port) @name = json['Name'] @comment = json['Comment'] @distrubution = json['DefaultDistribution'] @component = json['DefaultComponent'] end
Public Instance Methods
edit(properties)
click to toggle source
Edit repo properties
# File lib/repo.rb, line 30 def edit(properties) hput("/api/repos/#{@name}", properties) end
import_files(directory, options = {})
click to toggle source
Import all files uploaded to directory
# File lib/repo.rb, line 24 def import_files(directory, options = {}) hpost("/api/repos/#{@name}/file/#{directory}", options) end
packages(query = nil)
click to toggle source
Return a listing of Packages for the repo
# File lib/repo.rb, line 36 def packages(query = nil) packages = Array.new if !query url = "/api/repos/#{@name}/packages" else url = "/api/repos/#{@name}/packages?q=#{URI.escape(query)}" end hget(url).each do |key| packages.push(Package.new(@server, key)) end packages end
Protected Instance Methods
hdelete(path)
click to toggle source
Sends HTTP delete call to path
# File lib/repo.rb, line 85 def hdelete(path) request = Net::HTTP::Delete.new("#{@server.path}#{URI.escape(path)}") response = @http.request(request) return response.code.to_i end
hget(path)
click to toggle source
Get an hash of JSON data from server path
# File lib/repo.rb, line 54 def hget(path) request = Net::HTTP::Get.new("#{@server.path}#{URI.escape(path)}") response = @http.request(request) if response.code.to_i != 200 return response.code.to_i end return JSON.parse(response.body) end
hpost(path, data)
click to toggle source
Post data
hash to path
as JSON
# File lib/repo.rb, line 65 def hpost(path, data) request = Net::HTTP::Post.new("#{@server.path}#{URI.escape(path)}") request.add_field('Content-Type', 'application/json') request.body = data.to_json response = @http.request(request) return response.code.to_i end
hput(path, data)
click to toggle source
Put data
hash to path
as JSON
# File lib/repo.rb, line 75 def hput(path, data) request = Net::HTTP::Put.new("#{@server.path}#{URI.escape(path)}") request.add_field('Content-Type', 'application/json') request.body = data.to_json response = @http.request(request) return response.code.to_i end