Class: GoodData::DataWarehouse

Inherits:
Rest::Resource show all
Defined in:
lib/gooddata/models/datawarehouse.rb

Constant Summary collapse

CREATE_URL =
'/gdc/datawarehouse/instances'

Instance Attribute Summary

Attributes inherited from Rest::Object

#client, #json, #project

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixin::ObjId

#obj_id

Methods inherited from Rest::Object

client, default_client, #saved?

Methods included from Mixin::DataPropertyReader

#data_property_reader

Methods included from Mixin::DataPropertyWriter

#data_property_writer

Methods included from Mixin::MetaPropertyReader

#metadata_property_reader

Methods included from Mixin::MetaPropertyWriter

#metadata_property_writer

Methods included from Mixin::MetaGetter

#meta

Methods included from Mixin::DataGetter

#data

Methods included from Mixin::RootKeyGetter

#root_key

Methods included from Mixin::ContentGetter

#content

Constructor Details

#initialize(json) ⇒ DataWarehouse

Returns a new instance of DataWarehouse.



73
74
75
76
# File 'lib/gooddata/models/datawarehouse.rb', line 73

def initialize(json)
  super
  @json = json
end

Class Method Details

.[](id = :all, options = { client: GoodData.client }) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gooddata/models/datawarehouse.rb', line 14

def [](id = :all, options = { client: GoodData.client })
  c = GoodData.get_client(options)

  if id == :all
    data = c.get(CREATE_URL)
    data['instances']['items'].map do |ads_data|
      c.create(DataWarehouse, ads_data)
    end
  else
    c.create(DataWarehouse, c.get("#{CREATE_URL}/#{id}"))
  end
end

.all(options = { client: GoodData.client }) ⇒ Object



27
28
29
# File 'lib/gooddata/models/datawarehouse.rb', line 27

def all(options = { client: GoodData.client })
  DataWarehouse[:all, options]
end

.create(opts) ⇒ Object

Create a data warehouse from given attributes Expected keys:

  • :title (mandatory)
  • :auth_token (mandatory)
  • :summary


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/gooddata/models/datawarehouse.rb', line 36

def create(opts)
  GoodData.logger.info "Creating warehouse #{opts[:title]}"

  c = GoodData.get_client(opts)

  opts = { :auth_token => Helpers::AuthHelper.read_token }.merge(opts)
  auth_token = opts[:auth_token] || opts[:token]
  fail ArgumentError, 'You have to provide your token for creating projects as :auth_token parameter' if auth_token.nil? || auth_token.empty?

  title = opts[:title]
  fail ArgumentError, 'You have to provide a title for creating warehouse as :title parameter' if title.nil? || title.empty?

  json = {
    'instance' => {
      'title' => title,
      'description' => opts[:description] || opts[:summary] || 'No summary',
      'authorizationToken' => auth_token
    }
  }
  json['instance']['environment'] = opts[:environment] if opts[:environment]

  # do the first post
  res = c.post(CREATE_URL, json)

  # wait until the instance is created
  final_res = c.poll_on_response(res['asyncTask']['links']['poll'], opts.merge(sleep_interval: 3)) do |r|
    r['asyncTask']['links']['instance'].nil?
  end

  # get the json of the created instance
  final_json = c.get(final_res['asyncTask']['links']['instance'])

  # create the public facing object
  c.create(DataWarehouse, final_json)
end

Instance Method Details

#deleteObject



98
99
100
101
102
103
# File 'lib/gooddata/models/datawarehouse.rb', line 98

def delete
  if state == 'DELETED'
    fail "Warehouse '#{title}' with id #{uri} is already deleted"
  end
  client.delete(uri)
end

#idObject



94
95
96
# File 'lib/gooddata/models/datawarehouse.rb', line 94

def id
  uri.split('/')[-1]
end

#schemasObject



110
111
112
# File 'lib/gooddata/models/datawarehouse.rb', line 110

def schemas
  json['instance']['links']['schemas']
end

#statusObject Also known as: state



86
87
88
# File 'lib/gooddata/models/datawarehouse.rb', line 86

def status
  json['instance']['status']
end

#summaryObject Also known as: description



82
83
84
# File 'lib/gooddata/models/datawarehouse.rb', line 82

def summary
  json['instance']['description']
end

#titleObject



78
79
80
# File 'lib/gooddata/models/datawarehouse.rb', line 78

def title
  json['instance']['title']
end

#uriObject



90
91
92
# File 'lib/gooddata/models/datawarehouse.rb', line 90

def uri
  json['instance']['links']['self']
end