Class: Katello::Resources::Candlepin::Content

Inherits:
CandlepinResource show all
Defined in:
app/lib/katello/resources/candlepin/content.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

.all(owner_label, include_only: nil) ⇒ Object



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

def all(owner_label, include_only: nil)
  includes = include_only ? "?#{included_list(include_only)}" : ""
  content_json = Candlepin::CandlepinResource.get(path(owner_label) + includes, self.default_headers).body
  JSON.parse(content_json)
end

.create(owner_label, attrs) ⇒ Object



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

def create(owner_label, attrs)
  JSON.parse(self.post(path(owner_label), JSON.generate(attrs), self.default_headers).body).with_indifferent_access
end

.destroy(owner_label, id) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'app/lib/katello/resources/candlepin/content.rb', line 21

def destroy(owner_label, id)
  fail ArgumentError, "content id has to be specified" unless id

  begin
    self.delete(path(owner_label, id), self.default_headers).code.to_i
  rescue RestClient::NotFound
    # this is OK
    :content_gone
  end
end

.get(owner_label, id) ⇒ Object



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

def get(owner_label, id)
  content_json = super(path(owner_label, id), self.default_headers).body
  JSON.parse(content_json).with_indifferent_access
end

.path(owner_label, id = nil) ⇒ Object



36
37
38
# File 'app/lib/katello/resources/candlepin/content.rb', line 36

def path(owner_label, id = nil)
  "/candlepin/owners/#{owner_label}/content/#{id}"
end

.update(owner_label, attrs) ⇒ Object



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

def update(owner_label, attrs)
  JSON.parse(self.put(path(owner_label, attrs[:id] || attrs['id']), JSON.generate(attrs), self.default_headers).body).with_indifferent_access
end