Class: GdsApi::Panopticon

Inherits:
Base
  • Object
show all
Includes:
ExceptionHandling
Defined in:
lib/gds_api/panopticon.rb,
lib/gds_api/panopticon/registerer.rb

Defined Under Namespace

Classes: Registerer

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods included from ExceptionHandling

#build_specific_http_error, #error_class_for_code, #ignoring, #ignoring_missing

Methods inherited from Base

#client, #create_client, #get_list!, #initialize, #url_for_slug

Constructor Details

This class inherits a constructor from GdsApi::Base

Instance Method Details

#allObject



9
10
11
12
13
# File 'lib/gds_api/panopticon.rb', line 9

def all
  url = base_url + '.json'
  json = get_json url
  to_ostruct json
end

#artefact_for_slug(slug, opts = {}) ⇒ Object



15
16
17
18
# File 'lib/gds_api/panopticon.rb', line 15

def artefact_for_slug(slug, opts = {})
  return nil if slug.nil? or slug == ''
  get_json(url_for_slug(slug))
end

#create_artefact(artefact) ⇒ Object



20
21
22
23
24
# File 'lib/gds_api/panopticon.rb', line 20

def create_artefact(artefact)
  ignoring GdsApi::HTTPErrorResponse do
    create_artefact! artefact
  end
end

#create_artefact!(artefact) ⇒ Object



26
27
28
# File 'lib/gds_api/panopticon.rb', line 26

def create_artefact!(artefact)
  post_json!(base_url + ".json", artefact)
end

#create_tag(attributes) ⇒ Object



52
53
54
# File 'lib/gds_api/panopticon.rb', line 52

def create_tag(attributes)
  post_json!("#{endpoint}/tags.json", attributes)
end

#delete_artefact!(id_or_slug) ⇒ Object



48
49
50
# File 'lib/gds_api/panopticon.rb', line 48

def delete_artefact!(id_or_slug)
  delete_json!("#{base_url}/#{id_or_slug}.json")
end

#publish_tag(tag_type, tag_id) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/gds_api/panopticon.rb', line 63

def publish_tag(tag_type, tag_id)
  post_json!(
    tag_url(tag_type, tag_id, '/publish'),
    # we don't need to send any more data along with the publish request,
    # but a body is still required, so sending an empty JSON hash instead
    { }
  )
end

#put_artefact(id_or_slug, artefact) ⇒ Object



30
31
32
33
34
# File 'lib/gds_api/panopticon.rb', line 30

def put_artefact(id_or_slug, artefact)
  ignoring GdsApi::HTTPErrorResponse do
    put_artefact! id_or_slug, artefact
  end
end

#put_artefact!(id_or_slug, artefact) ⇒ Object



36
37
38
# File 'lib/gds_api/panopticon.rb', line 36

def put_artefact!(id_or_slug, artefact)
  put_json!("#{base_url}/#{id_or_slug}.json", artefact)
end

#put_tag(tag_type, tag_id, attributes) ⇒ Object



56
57
58
59
60
61
# File 'lib/gds_api/panopticon.rb', line 56

def put_tag(tag_type, tag_id, attributes)
  put_json!(
    tag_url(tag_type, tag_id),
    attributes
  )
end

#update_artefact(id_or_slug, artefact) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/gds_api/panopticon.rb', line 40

def update_artefact(id_or_slug, artefact)
  self.class.logger.warn(
    "The update_artefact method is deprecated and may be removed in a " +
    "future release. You should use put_artefact instead."
  )
  put_artefact(id_or_slug, artefact)
end