Sha256: f49907824b3800611088fdec40a1f889354d3a594afc0945608d2eb3826e51bb

Contents?: true

Size: 825 Bytes

Versions: 3

Compression:

Stored size: 825 Bytes

Contents

# encoding: UTF-8

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

      # TODO: Add test
      def identifier_to_uri(*ids)
        fail(NoProjectError, 'Connect to a project before searching for an object') unless GoodData.project
        uri = GoodData.project.md[IDENTIFIERS_CFG]
        response = GoodData.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

3 entries across 3 versions & 1 rubygems

Version Path
gooddata-0.6.7 lib/gooddata/mixins/md_id_to_uri.rb
gooddata-0.6.6 lib/gooddata/mixins/md_id_to_uri.rb
gooddata-0.6.5 lib/gooddata/mixins/md_id_to_uri.rb