aptlyapi 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86419976f3ae9c047089ab04ed93c46b13a58f90
4
- data.tar.gz: b84c5ffaf897b099836f5e4c74ee7d261ff1be1d
3
+ metadata.gz: f1d378ad6bff6b52a60de1fdd3b2dd51baae8758
4
+ data.tar.gz: a8bf12dd05a0e65134715d2effb76879164f6359
5
5
  SHA512:
6
- metadata.gz: ecdd464c50421929317ae5cf23b6059b5c69382bfa0f9d39ed66564c297e51456f13971a4ea228e558016b8fe7cacff5d5797fe77353fba9c59ac42eb48f18db
7
- data.tar.gz: 369a645a16aa97a841a87bdaac32cf40dc55cc7136e51c99d3628b4e1e853b899e1cb88d02e4709ea20aa3a138985672c6bec2bc3cdc0ad1a9008ca60a5f5196
6
+ metadata.gz: 8e28a3dd3cca7baa6eeab5e29189dd8498faade20f42cb1e753f3a6400b87fb5b80bd53ff6b92eeb7131de070ba8869f3a6c509fd8a22b69b0e62d246c1bf9e1
7
+ data.tar.gz: 0f1591b009003b4c1ad79d007145e7acbbc3fe99d80a98cf23c85e267e52e020ba352a6eb65aca508cf95ee4d11b1f7b4dbb19d73196be52daa73fa86213170a
@@ -14,3 +14,4 @@
14
14
 
15
15
  require_relative 'server.rb'
16
16
  require_relative 'repo.rb'
17
+ require_relative 'package.rb'
@@ -0,0 +1,69 @@
1
+
2
+ require 'uri'
3
+ require 'net/http'
4
+ require 'json'
5
+
6
+ module AptlyAPI
7
+ ##
8
+ # This class represents an Aptly Package
9
+ class Package
10
+ ##
11
+ # Creates a new Package definitation with data +json+ located on +server+
12
+ def initialize(server, json)
13
+ @server = server
14
+ @http = Net::HTTP.new(@server.host, @server.port)
15
+
16
+ info = hget("/api/packages/#{json}")
17
+
18
+ if !info.is_a?(Integer)
19
+ @name = info['Package']
20
+ @description = info['Description']
21
+ @architecture = info['Architecture']
22
+ @priority = info['Priority']
23
+ @version = info['Version']
24
+ end
25
+ end
26
+
27
+ attr_reader :name, :description, :architecture, :priority, :version
28
+
29
+ protected
30
+ ##
31
+ # Get an hash of JSON data from server +path+
32
+ def hget(path)
33
+ request = Net::HTTP::Get.new("#{@server.path}#{URI.escape(path)}")
34
+ response = @http.request(request)
35
+ if response.code.to_i != 200
36
+ return response.code.to_i
37
+ end
38
+ return JSON.parse(response.body)
39
+ end
40
+
41
+ ##
42
+ # Post +data+ hash to +path+ as JSON
43
+ def hpost(path, data)
44
+ request = Net::HTTP::Post.new("#{@server.path}#{URI.escape(path)}")
45
+ request.add_field('Content-Type', 'application/json')
46
+ request.body = data.to_json
47
+ response = @http.request(request)
48
+ return response.code.to_i
49
+ end
50
+
51
+ ##
52
+ # Put +data+ hash to +path+ as JSON
53
+ def hput(path, data)
54
+ request = Net::HTTP::Put.new("#{@server.path}#{URI.escape(path)}")
55
+ request.add_field('Content-Type', 'application/json')
56
+ request.body = data.to_json
57
+ response = @http.request(request)
58
+ return response.code.to_i
59
+ end
60
+
61
+ ##
62
+ # Sends HTTP delete call to +path+
63
+ def hdelete(path)
64
+ request = Net::HTTP::Delete.new("#{@server.path}#{URI.escape(path)}")
65
+ response = @http.request(request)
66
+ return response.code.to_i
67
+ end
68
+ end
69
+ end
@@ -31,13 +31,28 @@ module AptlyAPI
31
31
  hput("/api/repos/#{@name}", properties)
32
32
  end
33
33
 
34
+ ##
35
+ # Return a listing of Packages for the repo
36
+ def packages(query = nil)
37
+ packages = Array.new
38
+ if !query
39
+ url = "/api/repos/#{@name}/packages"
40
+ else
41
+ url = "/api/repos/#{@name}/packages?q=#{URI.escape(query)}"
42
+ end
43
+ hget(url).each do |key|
44
+ packages.push(Package.new(@server, key))
45
+ end
46
+ packages
47
+ end
48
+
34
49
  attr_reader :name, :comment, :distribution, :component
35
50
 
36
51
  protected
37
52
  ##
38
53
  # Get an hash of JSON data from server +path+
39
54
  def hget(path)
40
- request = Net::HTTP::Get.new("#{@server.path}#{path}")
55
+ request = Net::HTTP::Get.new("#{@server.path}#{URI.escape(path)}")
41
56
  response = @http.request(request)
42
57
  if response.code.to_i != 200
43
58
  return response.code.to_i
@@ -48,7 +63,7 @@ module AptlyAPI
48
63
  ##
49
64
  # Post +data+ hash to +path+ as JSON
50
65
  def hpost(path, data)
51
- request = Net::HTTP::Post.new("#{@server.path}#{path}")
66
+ request = Net::HTTP::Post.new("#{@server.path}#{URI.escape(path)}")
52
67
  request.add_field('Content-Type', 'application/json')
53
68
  request.body = data.to_json
54
69
  response = @http.request(request)
@@ -58,7 +73,7 @@ module AptlyAPI
58
73
  ##
59
74
  # Put +data+ hash to +path+ as JSON
60
75
  def hput(path, data)
61
- request = Net::HTTP::Put.new("#{@server.path}#{path}")
76
+ request = Net::HTTP::Put.new("#{@server.path}#{URI.escape(path)}")
62
77
  request.add_field('Content-Type', 'application/json')
63
78
  request.body = data.to_json
64
79
  response = @http.request(request)
@@ -68,7 +83,7 @@ module AptlyAPI
68
83
  ##
69
84
  # Sends HTTP delete call to +path+
70
85
  def hdelete(path)
71
- request = Net::HTTP::Delete.new("#{@server.path}#{path}")
86
+ request = Net::HTTP::Delete.new("#{@server.path}#{URI.escape(path)}")
72
87
  response = @http.request(request)
73
88
  return response.code.to_i
74
89
  end
@@ -135,7 +135,7 @@ module AptlyAPI
135
135
  ##
136
136
  # Get an hash of JSON data from server +path+
137
137
  def hget(path)
138
- request = Net::HTTP::Get.new("#{@server.path}#{path}")
138
+ request = Net::HTTP::Get.new("#{@server.path}#{URI.escape(path)}")
139
139
  response = @http.request(request)
140
140
  if !response.code.to_i.between?(200, 299)
141
141
  return response.code.to_i
@@ -146,7 +146,7 @@ module AptlyAPI
146
146
  ##
147
147
  # Post +data+ hash to +path+ as JSON
148
148
  def hpost(path, data)
149
- request = Net::HTTP::Post.new("#{@server.path}#{path}")
149
+ request = Net::HTTP::Post.new("#{@server.path}#{URI.escape(path)}")
150
150
  request.add_field('Content-Type', 'application/json')
151
151
  request.body = data.to_json
152
152
  response = @http.request(request)
@@ -156,7 +156,7 @@ module AptlyAPI
156
156
  ##
157
157
  # Put +data+ hash to +path+ as JSON
158
158
  def hput(path, data)
159
- request = Net::HTTP::Put.new("#{@server.path}#{path}")
159
+ request = Net::HTTP::Put.new("#{@server.path}#{URI.escape(path)}")
160
160
  request.add_field('Content-Type', 'application/json')
161
161
  request.body = data.to_json
162
162
  response = @http.request(request)
@@ -166,7 +166,7 @@ module AptlyAPI
166
166
  ##
167
167
  # Sends HTTP delete call to +path+
168
168
  def hdelete(path)
169
- request = Net::HTTP::Delete.new("#{@server.path}#{path}")
169
+ request = Net::HTTP::Delete.new("#{@server.path}#{URI.escape(path)}")
170
170
  response = @http.request(request)
171
171
  return response.code.to_i
172
172
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aptlyapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander von Gluck IV
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-14 00:00:00.000000000 Z
11
+ date: 2016-02-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Manage remote Aptly servers via the Aptly API
14
14
  email: Alex.vonGluck@r1soft.com
@@ -17,6 +17,7 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - lib/aptlyapi.rb
20
+ - lib/package.rb
20
21
  - lib/repo.rb
21
22
  - lib/server.rb
22
23
  homepage: https://github.com/avongluck-r1soft/aptlyapi