Method: GoodData::Mixin::MdObjectQuery#query

Defined in:
lib/gooddata/mixins/md_object_query.rb

#query(query_obj_type, klass, options = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Array<GoodData::MdObject> | Array<Hash>

Method intended to be called by individual classes in their all implementations. It abstracts the way interacting with query resources. It either returns the array of hashes from query. If asked it also goes and brings the full objects. Due to performance reasons :full => false is the default. This will most likely change

decide to pull in full objects. This is desirable from the usability POV but unfortunately has negative impact on performance so it is not the default.

Parameters:

  • query_obj_type (String)

    string used in URI to distinguish different query resources for different objects

  • klass (Class)

    A class used for instantiating the returned data

  • options (Hash) (defaults to: { :client => GoodData.connection, :project => GoodData.project })

    the options hash

Options Hash (options):

  • :full (Boolean)

    if passed true the subclass can

Returns:

  • (Array<GoodData::MdObject> | Array<Hash>)

    Return the appropriate metadata objects or their representation



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/gooddata/mixins/md_object_query.rb', line 38

def query(query_obj_type, klass, options = { :client => GoodData.connection, :project => GoodData.project })
  client = options[:client]
  fail ArgumentError, 'No :client specified' if client.nil?

  p = options[:project]
  fail ArgumentError, ERROR_MESSAGE_NO_PROJECT if p.nil?

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

  offset = 0
  page_limit = 50
  Enumerator.new do |y|
    loop do
      result = client.get(project.md['objects'] + '/query', params: { category: query_obj_type, limit: page_limit, offset: offset })
      result['objects']['items'].each do |item|
        y << (klass ? client.create(klass, item, project: project) : item)
      end
      break if result['objects']['paging']['count'] < page_limit

      offset += page_limit
    end
  end
end