Project

General

Profile

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

runcible / lib / runcible / resources / content.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/rest-api/content/index.html
6
    class Content < Runcible::Base
7
      # Generates the API path for Contents
8
      #
9
      # @param  [String]  upload_id  the id of the upload_request
10
      # @return [String]             the content path, may contain the upload_id if passed
11
      def upload_path(upload_id = nil)
12
        upload_id.nil? ? 'content/uploads/' : "content/uploads/#{upload_id}/"
13
      end
14

    
15
      # Creates an Upload Request
16
      #
17
      # Request Body Contents: None
18
      # @return [RestClient::Response] Pulp returns the upload_id which is used for subsequent operations
19
      def create_upload_request
20
        call(:post, upload_path)
21
      end
22

    
23
      # Upload bits
24
      #
25
      # @param  [String]  upload_id  the id of the upload_request returned by create_upload_request
26
      # @param  [Numeric] offset     offset for file assembly
27
      # @param  [File]    content    content of the file being uploaded to the server
28
      # @return  [RestClient::Response] none
29
      def upload_bits(upload_id, offset, content)
30
        call(:put, upload_path("#{upload_id}/#{offset}/"), :payload => content)
31
      end
32

    
33
      # Import into a repository
34
      #
35
      # @param  [String]  repo_id       identifies the associated repository
36
      # @param  [String]  unit_type_id  identifies the type of unit the upload represents
37
      # @param  [String]  upload_id     the id of the upload_request returned by create_upload_request
38
      # @param  [Object]  unit_key      unique identifier for the new unit; the contents are contingent
39
      #                                  on the type of unit being uploaded
40
      # @param  [Hash]    optional      container for all optional parameters
41
      # @return [RestClient::Response]  none
42
      def import_into_repo(repo_id, unit_type_id, upload_id, unit_key, optional = {})
43
        required = required_params(binding.send(:local_variables), binding)
44
        call(:post, Repository.path("#{repo_id}/actions/import_upload/"),
45
                                    :payload => { :required => required, :optional => optional })
46
      end
47

    
48
      # Delete an upload request
49
      #
50
      # @param  [String]  upload_id  the id of the upload_request returned by create_upload_request
51
      # Query Parameters: None
52
      # @return [RestClient::Response] none
53
      def delete_upload_request(upload_id)
54
        call(:delete, upload_path("#{upload_id}/"))
55
      end
56

    
57
      # List all upload requests
58
      #
59
      # Query Parameters: None
60
      # @return [RestClient::Response]  the list of IDs for all upload requests
61
      #                                 on the server; empty list if there are none
62
      def list_all_requests
63
        call(:get, upload_path)
64
      end
65

    
66
      # Generates an api path for orphaned content
67
      #
68
      # @param  [String]  type_id  the type id of the orphaned content
69
      # @return [String]  the content path, may contain the type_id if passed
70
      def orphan_path(type_id = nil)
71
        path = 'content/orphans/'
72
        path << "#{type_id}/" if type_id
73
        path
74
      end
75

    
76
      # List all orphaned content optionally by type
77
      #
78
      # @param type_id  content unit type (rpm, puppet_module, etc.)
79
      # @return list of orphaned content
80
      def list_orphans(type_id = nil)
81
        call(:get, orphan_path(type_id))
82
      end
83

    
84
      # Delete all orphaned content optionally by type
85
      #
86
      # @param type_id  content unit type (rpm, puppet_module, etc.)
87
      # @return list of orphaned content
88
      def remove_orphans(type_id = nil)
89
        call(:delete, orphan_path(type_id))
90
      end
91
    end
92
  end
93
end