lib/gooddata/models/project_metadata.rb in gooddata-0.6.0.pre11 vs lib/gooddata/models/project_metadata.rb in gooddata-0.6.0

- old
+ new

@@ -1,21 +1,23 @@ +# encoding: UTF-8 + module GoodData class ProjectMetadata - class << self - def keys ProjectMetadata[:all].keys end def [](key) if key == :all - res = GoodData.get("/gdc/projects/#{GoodData.project.pid}/dataload/metadata") - res["metadataItems"]["items"].reduce({}) {|memo, i| memo[i["metadataItem"]["key"]] = i["metadataItem"]["value"]; memo} - else - res = GoodData.get("/gdc/projects/#{GoodData.project.pid}/dataload/metadata/#{key}") - res["metadataItem"]["value"] + uri = "/gdc/projects/#{GoodData.project.pid}/dataload/metadata" + res = GoodData.get(uri) + res['metadataItems']['items'].reduce({}) { |memo, i| memo[i['metadataItem']['key']] = i['metadataItem']['value']; memo } + else + uri = "/gdc/projects/#{GoodData.project.pid}/dataload/metadata/#{key}" + res = GoodData.get(uri) + res['metadataItem']['value'] end end alias_method :get, :[] alias_method :get_key, :[] @@ -30,23 +32,21 @@ end def []=(key, val) data = { :metadataItem => { - :key => key, - :value => val - } + :key => key, + :value => val + } } uri = "/gdc/projects/#{GoodData.project.pid}/dataload/metadata/" update_uri = uri + key if has_key?(key) GoodData.put(update_uri, data) else GoodData.post(uri, data) end end - end - end end