Class: CDD::Search

Inherits:
Base
  • Object
show all
Defined in:
lib/cdd/search.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#client, #id

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from CDD::Base

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/cdd/search.rb', line 3

def name
  @name
end

#vaultObject

Returns the value of attribute vault.



4
5
6
# File 'lib/cdd/search.rb', line 4

def vault
  @vault
end

Instance Method Details

#export(projects = [], data_sets = [], format = "csv", &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cdd/search.rb', line 14

def export(projects=[], data_sets=[], format="csv", &block)
  e = start_export(projects, data_sets, format)
  state = e.poll
  while ["new", "started", "starting"].include?(state["status"]) do
    state = e.poll
  end
  data = e.data
  if block
    return block.call(data)
  else
    return data
  end
end

#start_export(projects = [], data_sets = [], format = "csv") ⇒ Object



6
7
8
9
10
11
12
# File 'lib/cdd/search.rb', line 6

def start_export(projects=[], data_sets=[], format="csv")
  project_ids = projects.collect { |p| p.id }
  data_set_ids = data_sets.collect { |ds| ds.id }
  params = { :search => self.id, :projects => project_ids.join(","), :data_sets => data_set_ids.join(",") }
  result = JSON.parse(RestClient.post("#{client.url}#{vault.export_url(format)}", params, { "X-CDD-Token" => client.token }))
  CDD::Export.new(client, { :search => self, :vault => vault, :format => format }.merge(result))
end