Class: Runcible::Resources::Consumer

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

Overview

Direct Known Subclasses

Extensions::Consumer

Class Method Summary collapse

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, #log_info, #logger, #path, #process_response, #required_params

Constructor Details

This class inherits a constructor from Runcible::Base

Class Method Details

.path(id = nil) ⇒ String

Generates the API path for Consumers

Parameters:

  • id (String) (defaults to: nil)

    the ID of the consumer

Returns:

  • (String)

    the consumer path, may contain the id if passed



32
33
34
# File 'lib/runcible/resources/consumer.rb', line 32

def self.path(id = nil)
  (id.nil?) ? 'consumers/' : "consumers/#{id}/"
end

Instance Method Details

#applicability(options = {}) ⇒ RestClient::Response

retrieve the applicability for some set of consumers

Parameters:

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

    hash representing criteria

Returns:

  • (RestClient::Response)


176
177
178
# File 'lib/runcible/resources/consumer.rb', line 176

def applicability(options = {})
  call(:post, path + 'content/applicability/', :payload => { :required => options })
end

#bind(id, repo_id, distributor_id, optional = {}) ⇒ RestClient::Response

Bind a consumer to a repository for a given distributor

Parameters:

  • id (String)

    the ID of the consumer

  • repo_id (String)

    the ID of the repository

  • distributor_id (String)

    the ID of the distributor

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

    optional parameters

Returns:

  • (RestClient::Response)


116
117
118
119
# File 'lib/runcible/resources/consumer.rb', line 116

def bind(id, repo_id, distributor_id, optional = {})
  required = required_params(binding.send(:local_variables), binding, ['id'])
  call(:post, path("#{id}/bindings/"), :payload => { :required => required, :optional => optional })
end

#create(id, optional = {}) ⇒ RestClient::Response

Creates a consumer

Parameters:

  • id (String)

    the ID of the consumer

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

    container for all optional parameters

Returns:

  • (RestClient::Response)


41
42
43
44
# File 'lib/runcible/resources/consumer.rb', line 41

def create(id, optional = {})
  required = required_params(binding.send(:local_variables), binding)
  call(:post, path, :payload => { :required => required, :optional => optional })
end

#delete(id) ⇒ RestClient::Response

Deletes a consumer

Parameters:

  • id (String)

    the id of the consumer

Returns:

  • (RestClient::Response)


67
68
69
# File 'lib/runcible/resources/consumer.rb', line 67

def delete(id)
  call(:delete, path(id))
end

#install_units(id, units, options = {}) ⇒ RestClient::Response

Install a set of units onto a consumer

Parameters:

  • id (String)

    the ID of the consumer

  • units (Array)

    array of units to install

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

    hash of install options

Returns:

  • (RestClient::Response)


137
138
139
140
# File 'lib/runcible/resources/consumer.rb', line 137

def install_units(id, units, options = {})
  required = required_params(binding.send(:local_variables), binding, ['id'])
  call(:post, path("#{id}/actions/content/install/"), :payload => { :required => required })
end

#regenerate_applicability(options = {}) ⇒ RestClient::Response

(Re)Generate applicability for some set of consumers

Parameters:

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

    payload representing criteria

Returns:

  • (RestClient::Response)


168
169
170
# File 'lib/runcible/resources/consumer.rb', line 168

def regenerate_applicability(options = {})
  call(:post, path('actions/content/regenerate_applicability/'), :payload => { :required => options})
end

#retrieve(id) ⇒ RestClient::Response

Retrieves a consumer

Parameters:

  • id (String)

    the ID of the consumer

Returns:

  • (RestClient::Response)


50
51
52
# File 'lib/runcible/resources/consumer.rb', line 50

def retrieve(id)
  call(:get, path(id))
end

#retrieve_binding(id, repo_id, distributor_id) ⇒ RestClient::Response

Retrieve a consumer binding

Parameters:

  • id (String)

    the ID of the consumer

  • repo_id (String)

    the ID of the repository

  • distributor_id (String)

    the ID of the distributor

Returns:

  • (RestClient::Response)


97
98
99
# File 'lib/runcible/resources/consumer.rb', line 97

def retrieve_binding(id, repo_id, distributor_id)
  call(:get, path("#{id}/bindings/#{repo_id}/#{distributor_id}"))
end

#retrieve_bindings(id) ⇒ RestClient::Response

Retrieve all consumer bindings

Parameters:

  • id (String)

    the ID of the consumer

Returns:

  • (RestClient::Response)


105
106
107
# File 'lib/runcible/resources/consumer.rb', line 105

def retrieve_bindings(id)
  call(:get, path("#{id}/bindings/"))
end

#retrieve_profile(id, content_type) ⇒ RestClient::Response

Retrieve a consumer profile

Parameters:

  • id (String)

    the ID of the consumer

  • content_type (String)

    the content type

Returns:

  • (RestClient::Response)


87
88
89
# File 'lib/runcible/resources/consumer.rb', line 87

def retrieve_profile(id, content_type)
  call(:get, path("#{id}/profiles/#{content_type}/"))
end

#unbind(id, repo_id, distributor_id) ⇒ RestClient::Response

Unbind a consumer to a repository for a given distributor

Parameters:

  • id (String)

    the ID of the consumer

  • repo_id (String)

    the ID of the repository

  • distributor_id (String)

    the ID of the distributor

Returns:

  • (RestClient::Response)


127
128
129
# File 'lib/runcible/resources/consumer.rb', line 127

def unbind(id, repo_id, distributor_id)
  call(:delete, path("#{id}/bindings/#{repo_id}/#{distributor_id}"))
end

#uninstall_units(id, units, options = {}) ⇒ RestClient::Response

Uninstall a set of units from a consumer

Parameters:

  • id (String)

    the ID of the consumer

  • units (Array)

    array of units to uninstall

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

    hash of uninstall options

Returns:

  • (RestClient::Response)


159
160
161
162
# File 'lib/runcible/resources/consumer.rb', line 159

def uninstall_units(id, units, options = {})
  required = required_params(binding.send(:local_variables), binding, ['id'])
  call(:post, path("#{id}/actions/content/uninstall/"), :payload => { :required => required })
end

#update(id, optional = {}) ⇒ RestClient::Response

Updates a consumer

Parameters:

  • id (String)

    the ID of the consumer

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

    container for all optional parameters

Returns:

  • (RestClient::Response)


59
60
61
# File 'lib/runcible/resources/consumer.rb', line 59

def update(id, optional = {})
  call(:put, path(id), :payload => { :delta => optional })
end

#update_units(id, units, options = {}) ⇒ RestClient::Response

Update a set of units on a consumer

Parameters:

  • id (String)

    the ID of the consumer

  • units (Array)

    array of units to update

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

    hash of update options

Returns:

  • (RestClient::Response)


148
149
150
151
# File 'lib/runcible/resources/consumer.rb', line 148

def update_units(id, units, options = {})
  required = required_params(binding.send(:local_variables), binding, ['id'])
  call(:post, path("#{id}/actions/content/update/"), :payload => { :required => required })
end

#upload_profile(id, content_type, profile) ⇒ RestClient::Response

Create consumer profile

Parameters:

  • id (String)

    the ID of the consumer

  • content_type (String)

    the content type

  • profile (Hash)

    hash representing the consumer profile

Returns:

  • (RestClient::Response)


77
78
79
80
# File 'lib/runcible/resources/consumer.rb', line 77

def upload_profile(id, content_type, profile)
  required = required_params(binding.send(:local_variables), binding, ['id'])
  call(:post, path("#{id}/profiles/"), :payload => { :required => required })
end