Sha256: 04055d5059113e2728537cb477c256137006abeae39982e08b86685b7ddfd846

Contents?: true

Size: 1.93 KB

Versions: 24

Compression:

Stored size: 1.93 KB

Contents

# encoding: UTF-8
#
# Copyright (c) 2010-2015 GoodData Corporation. All rights reserved.
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

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

      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

      alias_method :get, :[]
      alias_method :get_key, :[]

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

      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
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
gooddata-edge-0.6.27.edge lib/gooddata/models/project_metadata.rb
gooddata-0.6.49 lib/gooddata/models/project_metadata.rb
gooddata-0.6.48 lib/gooddata/models/project_metadata.rb
gooddata-0.6.47 lib/gooddata/models/project_metadata.rb
gooddata-0.6.46 lib/gooddata/models/project_metadata.rb
gooddata-0.6.45 lib/gooddata/models/project_metadata.rb
gooddata-0.6.44 lib/gooddata/models/project_metadata.rb
gooddata-0.6.43 lib/gooddata/models/project_metadata.rb
gooddata-0.6.42 lib/gooddata/models/project_metadata.rb
gooddata-0.6.41 lib/gooddata/models/project_metadata.rb
gooddata-0.6.40 lib/gooddata/models/project_metadata.rb
gooddata-0.6.39 lib/gooddata/models/project_metadata.rb
gooddata-0.6.38 lib/gooddata/models/project_metadata.rb
gooddata-0.6.37 lib/gooddata/models/project_metadata.rb
gooddata-0.6.36 lib/gooddata/models/project_metadata.rb
gooddata-0.6.35 lib/gooddata/models/project_metadata.rb
gooddata-0.6.34 lib/gooddata/models/project_metadata.rb
gooddata-0.6.33 lib/gooddata/models/project_metadata.rb
gooddata-0.6.32 lib/gooddata/models/project_metadata.rb
gooddata-0.6.31 lib/gooddata/models/project_metadata.rb