Project

General

Profile

Download (3.21 KB) Statistics
| Branch: | Tag: | Revision:

runcible / lib / runcible / resources / repository_group.rb @ 27b106f4

1
require 'active_support/core_ext/hash'
2

    
3
module Runcible
4
  module Resources
5
    # @see https://docs.pulpproject.org/dev-guide/integration/integration/rest-api/repo/groups/
6
    class RepositoryGroup < Runcible::Base
7
      # Generates the API path for Repository Groups
8
      #
9
      # @param  [String]  id  the ID of the Repository group
10
      # @return [String]      the Repository group path, may contain the id if passed
11
      def self.path(id = nil)
12
        groups = 'repo_groups/'
13
        id.nil? ? groups : groups + "#{id}/"
14
      end
15

    
16
      # Creates a Repository Group
17
      #
18
      # @param  [String]                id        the ID of the group
19
      # @param  [Hash]                  optional  container for all optional parameters
20
      # @return [RestClient::Response]
21
      def create(id, optional = {})
22
        required = required_params(binding.send(:local_variables), binding)
23
        call(:post, path, :payload => { :required => required, :optional => optional })
24
      end
25

    
26
      # Retrieves a Repository Group
27
      #
28
      # @param  [String]                id  the ID of the Repository group
29
      # @return [RestClient::Response]
30
      def retrieve(id)
31
        call(:get, path(id))
32
      end
33

    
34
      # Retrieves a Repository Group's distributors
35
      #
36
      # @param  [String]                id  the ID of the Repository group
37
      # @return [RestClient::Response]
38
      def retrieve_distributors(id)
39
        call(:get, path(id) + 'distributors/')
40
      end
41

    
42
      # Retrieves all Repository Group
43
      #
44
      # @return [RestClient::Response]
45
      def retrieve_all
46
        call(:get, path)
47
      end
48

    
49
      # Deletes a Repository Group
50
      #
51
      # @param  [String]                id  the ID of the Repository group
52
      # @return [RestClient::Response]
53
      def delete(id)
54
        call(:delete, path(id))
55
      end
56

    
57
      # Associates Repositories with a Repository Group
58
      #
59
      # @param  [String]                id        the ID of the Repository group
60
      # @param  [Hash]                  criteria  criteria based on Mongo syntax representing repos to associate
61
      # @return [RestClient::Response]
62
      def associate(id, criteria)
63
        call(:post, path(id) + 'actions/associate/', :payload => {:required => criteria})
64
      end
65

    
66
      # Unassociates Repositories with a Repository Group
67
      #
68
      # @param  [String]                id        the ID of the Repository group
69
      # @param  [Hash]                  criteria  criteria based on Mongo syntax representing repos ta unassociate
70
      # @return [RestClient::Response]
71
      def unassociate(id, criteria)
72
        call(:post, path(id) + 'actions/unassociate/', :payload => {:required => criteria})
73
      end
74

    
75
      # Publishes a repository group using the specified distributor
76
      #
77
      # @param  [String]                id              the id of the repository
78
      # @param  [String]                distributor_id  the id of the distributor
79
      # @param  [Hash]                  optional  optional params
80
      # @return [RestClient::Response]
81
      def publish(id, distributor_id, optional = {})
82
        call(:post, "#{path(id)}actions/publish/",
83
             :payload => {:required => {:id => distributor_id}, :optional => optional})
84
      end
85
    end
86
  end
87
end