Class: GoodData::ProjectMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/gooddata/models/project_metadata.rb

Class Method Summary collapse

Class Method Details

.[](key, opts = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Object Also known as: get, get_key



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gooddata/models/project_metadata.rb', line 14

def [](key, opts = { :client => GoodData.connection, :project => GoodData.project })
  client, project = GoodData.get_client_and_project(opts)

  get_opts = {
    do_not_log: [
      RestClient::ResourceNotFound
    ]
  }

  if key == :all
    uri = "/gdc/projects/#{project.pid}/dataload/metadata"
    res = client.get(uri, get_opts)
    res['metadataItems']['items'].reduce({}) do |memo, i|
      memo[i['metadataItem']['key']] = i['metadataItem']['value']
      memo
    end
  else
    uri = "/gdc/projects/#{project.pid}/dataload/metadata/#{key}"
    res = client.get(uri, get_opts)
    res['metadataItem']['value']
  end
end

.[]=(key, opts = { :client => GoodData.connection, :project => GoodData.project }, val = nil) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/gooddata/models/project_metadata.rb', line 47

def []=(key, opts = { :client => GoodData.connection, :project => GoodData.project }, val = nil)
  client, project = GoodData.get_client_and_project(opts)

  data = {
    :metadataItem => {
      :key => key,
      :value => val
    }
  }
  uri = "/gdc/projects/#{project.pid}/dataload/metadata/"
  update_uri = uri + key

  if key?(key, opts)
    client.put(update_uri, data)
  else
    client.post(uri, data)
  end
end

.key?(key, opts = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
# File 'lib/gooddata/models/project_metadata.rb', line 40

def key?(key, opts = { :client => GoodData.connection, :project => GoodData.project })
  [key, opts]
  true
rescue RestClient::ResourceNotFound
  false
end

.keys(opts = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Object



10
11
12
# File 'lib/gooddata/models/project_metadata.rb', line 10

def keys(opts = { :client => GoodData.connection, :project => GoodData.project })
  [:all, opts].keys
end