Class: Runcible::Resources::Content

Inherits:
Base
  • Object
show all
Defined in:
lib/runcible/resources/content.rb

Overview

Instance Method Summary collapse

Methods inherited from Base

#add_http_auth_header, #add_oauth_header, #call, #combine_get_params, #config, #format_payload_json, #generate_log_message, #generate_payload, #get_response, #initialize, #lazy_config=, #log_debug, #log_exception, #logger, #path, #process_response, #required_params

Constructor Details

This class inherits a constructor from Runcible::Base

Instance Method Details

#create_upload_requestRestClient::Response

Creates an Upload Request

Request Body Contents: None

Returns:

  • (RestClient::Response)

    Pulp returns the upload_id which is used for subsequent operations



43
44
45
# File 'lib/runcible/resources/content.rb', line 43

def create_upload_request
  call(:post, upload_path)
end

#delete_upload_request(upload_id) ⇒ RestClient::Response

Delete an upload request

Query Parameters: None

Parameters:

  • upload_id (String)

    the id of the upload_request returned by create_upload_request

Returns:

  • (RestClient::Response)

    none



75
76
77
# File 'lib/runcible/resources/content.rb', line 75

def delete_upload_request(upload_id)
  call(:delete, upload_path("#{upload_id}/"))
end

#import_into_repo(repo_id, unit_type_id, upload_id, unit_key, optional = {}) ⇒ RestClient::Response

Import into a repository

Parameters:

  • repo_id (String)

    identifies the associated repository

  • unit_type_id (String)

    identifies the type of unit the upload represents

  • upload_id (String)

    the id of the upload_request returned by create_upload_request

  • unit_key (Object)

    unique identifier for the new unit; the contents are contingent on the type of unit being uploaded

  • optional (Hash) (defaults to: {})

    container for all optional parameters

Returns:

  • (RestClient::Response)

    none



65
66
67
68
# File 'lib/runcible/resources/content.rb', line 65

def import_into_repo(repo_id, unit_type_id, upload_id,  unit_key, optional={})
  required = required_params(binding.send(:local_variables), binding)
  call(:post, Repository.path("#{repo_id}/actions/import_upload/"), :payload => { :required =>required, :optional => optional })
end

#list_all_requestsRestClient::Response

List all upload requests

Query Parameters: None

Returns:

  • (RestClient::Response)

    the list of IDs for all upload requests on the server; empty list if there are none



83
84
85
# File 'lib/runcible/resources/content.rb', line 83

def list_all_requests
  call(:get, upload_path)
end

#list_orphans(type_id = nil) ⇒ Object

List all orphaned content optionally by type

Parameters:

  • type_id (defaults to: nil)

    content unit type (rpm, puppet_module, etc.)

Returns:

  • list of orphaned content



101
102
103
# File 'lib/runcible/resources/content.rb', line 101

def list_orphans(type_id = nil)
  call(:get, orphan_path(type_id))
end

#orphan_path(type_id = nil) ⇒ String

Generates an api path for orphaned content

Parameters:

  • type_id (String) (defaults to: nil)

    the type id of the orphaned content

Returns:

  • (String)

    the content path, may contain the type_id if passed



91
92
93
94
95
# File 'lib/runcible/resources/content.rb', line 91

def orphan_path(type_id = nil)
  path = "content/orphans/"
  path << "#{type_id}/" if type_id
  path
end

#remove_orphans(type_id = nil) ⇒ Object

Delete all orphaned content optionally by type

Parameters:

  • type_id (defaults to: nil)

    content unit type (rpm, puppet_module, etc.)

Returns:

  • list of orphaned content



109
110
111
# File 'lib/runcible/resources/content.rb', line 109

def remove_orphans(type_id = nil)
  call(:delete, orphan_path(type_id))
end

#upload_bits(upload_id, offset, content) ⇒ RestClient::Response

Upload bits

Parameters:

  • upload_id (String)

    the id of the upload_request returned by create_upload_request

  • offset (Numeric)

    offset for file assembly

  • content (File)

    content of the file being uploaded to the server

Returns:

  • (RestClient::Response)

    none



53
54
55
# File 'lib/runcible/resources/content.rb', line 53

def upload_bits(upload_id, offset, content)
  call(:put, upload_path("#{upload_id}/#{offset}/"), :payload => content)
end

#upload_path(upload_id = nil) ⇒ String

Generates the API path for Contents

Parameters:

  • upload_id (String) (defaults to: nil)

    the id of the upload_request

Returns:

  • (String)

    the content path, may contain the upload_id if passed



35
36
37
# File 'lib/runcible/resources/content.rb', line 35

def upload_path(upload_id=nil)
  (upload_id == nil) ? "content/uploads/" : "content/uploads/#{upload_id}/"
end