Sha256: 3d4c95df42acba742644aa62f85990d61f559b7dd53ce2b752d511936953f601

Contents?: true

Size: 1.06 KB

Versions: 13

Compression:

Stored size: 1.06 KB

Contents

# encoding: UTF-8

module GoodData
  module Mixin
    module MdIdToUri
      IDENTIFIERS_CFG = 'instance-identifiers'

      # TODO: Add test
      def identifier_to_uri(opts = { :client => GoodData.connection, :project => GoodData.project }, *ids)
        client = opts[:client]
        fail ArgumentError, 'No :client specified' if client.nil?

        p = opts[:project]
        fail ArgumentError, 'No :project specified' if p.nil?

        project = GoodData::Project[p, opts]
        fail ArgumentError, 'Wrong :project specified' if project.nil?

        uri = project.md[IDENTIFIERS_CFG]
        response = client.post uri, 'identifierToUri' => ids
        if response['identifiers'].empty?
          nil
        else
          identifiers = response['identifiers']
          ids_lookup = identifiers.reduce({}) do |a, e|
            a[e['identifier']] = e['uri']
            a
          end
          uris = ids.map { |x| ids_lookup[x] }
          uris.count == 1 ? uris.first : uris
        end
      end

      alias_method :id_to_uri, :identifier_to_uri
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
gooddata-0.6.20 lib/gooddata/mixins/md_id_to_uri.rb
gooddata-0.6.19 lib/gooddata/mixins/md_id_to_uri.rb
gooddata-0.6.18 lib/gooddata/mixins/md_id_to_uri.rb
gooddata-0.6.17 lib/gooddata/mixins/md_id_to_uri.rb
gooddata-0.6.16 lib/gooddata/mixins/md_id_to_uri.rb
gooddata-0.6.15 lib/gooddata/mixins/md_id_to_uri.rb
gooddata-0.6.14 lib/gooddata/mixins/md_id_to_uri.rb
gooddata-0.6.13 lib/gooddata/mixins/md_id_to_uri.rb
gooddata-0.6.12 lib/gooddata/mixins/md_id_to_uri.rb
gooddata-0.6.11 lib/gooddata/mixins/md_id_to_uri.rb
gooddata-0.6.10 lib/gooddata/mixins/md_id_to_uri.rb
gooddata-0.6.9 lib/gooddata/mixins/md_id_to_uri.rb
gooddata-0.6.8 lib/gooddata/mixins/md_id_to_uri.rb