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, #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



34
35
36
# File 'lib/runcible/resources/consumer.rb', line 34

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)


178
179
180
# File 'lib/runcible/resources/consumer.rb', line 178

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)


118
119
120
121
# File 'lib/runcible/resources/consumer.rb', line 118

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)


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

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)


69
70
71
# File 'lib/runcible/resources/consumer.rb', line 69

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)


139
140
141
142
# File 'lib/runcible/resources/consumer.rb', line 139

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)


170
171
172
# File 'lib/runcible/resources/consumer.rb', line 170

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)


52
53
54
# File 'lib/runcible/resources/consumer.rb', line 52

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)


99
100
101
# File 'lib/runcible/resources/consumer.rb', line 99

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)


107
108
109
# File 'lib/runcible/resources/consumer.rb', line 107

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)


89
90
91
# File 'lib/runcible/resources/consumer.rb', line 89

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)


129
130
131
# File 'lib/runcible/resources/consumer.rb', line 129

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)


161
162
163
164
# File 'lib/runcible/resources/consumer.rb', line 161

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)


61
62
63
# File 'lib/runcible/resources/consumer.rb', line 61

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)


150
151
152
153
# File 'lib/runcible/resources/consumer.rb', line 150

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)


79
80
81
82
# File 'lib/runcible/resources/consumer.rb', line 79

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