Class: Katello::Resources::Candlepin::Environment

Inherits:
CandlepinResource show all
Defined in:
app/lib/katello/resources/candlepin/environment.rb

Constant Summary

Constants inherited from HttpResource

HttpResource::REQUEST_MAP

Instance Attribute Summary

Attributes inherited from HttpResource

#json

Class Method Summary collapse

Methods inherited from CandlepinResource

default_headers, fetch_paged, included_list, logger, name_to_key, process_response, raise_rest_client_exception

Methods inherited from HttpResource

#[], #[]=, hash_to_query, #initialize, issue_request, join_path, logger, process_response, raise_rest_client_exception, rest_client

Methods included from Concerns::FilterSensitiveData

#filter_sensitive_data

Constructor Details

This class inherits a constructor from Katello::HttpResource

Class Method Details

.add_content(env_id, content_ids) ⇒ Object



31
32
33
34
35
# File 'app/lib/katello/resources/candlepin/environment.rb', line 31

def add_content(env_id, content_ids)
  path = self.path(env_id) + "/content"
  params = content_ids.map { |content_id| {:contentId => content_id} }
  JSON.parse(self.post(path, params.to_json, self.default_headers).body).with_indifferent_access
end

.allObject



10
11
12
# File 'app/lib/katello/resources/candlepin/environment.rb', line 10

def all
  JSON.parse(self.get(path, self.default_headers).body).collect { |a| a.with_indifferent_access }
end

.create(owner_id, id, name, description) ⇒ Object



14
15
16
17
18
19
# File 'app/lib/katello/resources/candlepin/environment.rb', line 14

def create(owner_id, id, name, description)
  attrs = {:id => id, :name => name, :description => description}
  path = "/candlepin/owners/#{owner_id}/environments"
  environment_json = self.post(path, attrs.to_json, self.default_headers).body
  JSON.parse(environment_json).with_indifferent_access
end

.delete_content(env_id, content_ids) ⇒ Object



37
38
39
40
41
# File 'app/lib/katello/resources/candlepin/environment.rb', line 37

def delete_content(env_id, content_ids)
  path = self.path(env_id) + "/content"
  params = content_ids.map { |content_id| {:content => content_id}.to_param }.join("&")
  self.delete("#{path}?#{params}", self.default_headers).code.to_i
end

.destroy(id) ⇒ Object



21
22
23
24
25
# File 'app/lib/katello/resources/candlepin/environment.rb', line 21

def destroy(id)
  self.delete(path(id), User.cp_oauth_header).code.to_i
rescue RestClient::NotFound => e
  raise ::Katello::Errors::CandlepinEnvironmentGone, e.message
end

.find(id) ⇒ Object



6
7
8
# File 'app/lib/katello/resources/candlepin/environment.rb', line 6

def find(id)
  JSON.parse(self.get(path(id), self.default_headers).body).with_indifferent_access
end

.path(id = '') ⇒ Object



27
28
29
# File 'app/lib/katello/resources/candlepin/environment.rb', line 27

def path(id = '')
  "/candlepin/environments/#{id}"
end