Class: PowerBI::Workspace

Inherits:
Object
  • Object
show all
Defined in:
lib/power-bi/workspace.rb

Defined Under Namespace

Classes: UploadError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tenant, data) ⇒ Workspace

Returns a new instance of Workspace.



7
8
9
10
11
12
13
14
15
# File 'lib/power-bi/workspace.rb', line 7

def initialize(tenant, data)
  @id = data[:id]
  @is_read_only = data[:isReadOnly]
  @is_on_dedicated_capacity = data[:isOnDedicatedCapacity]
  @name = data[:name]
  @tenant = tenant
  @reports = ReportArray.new(@tenant, self)
  @datasets = DatasetArray.new(@tenant, self)
end

Instance Attribute Details

#datasetsObject (readonly)

Returns the value of attribute datasets.



3
4
5
# File 'lib/power-bi/workspace.rb', line 3

def datasets
  @datasets
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/power-bi/workspace.rb', line 3

def id
  @id
end

#is_on_dedicated_capacityObject (readonly)

Returns the value of attribute is_on_dedicated_capacity.



3
4
5
# File 'lib/power-bi/workspace.rb', line 3

def is_on_dedicated_capacity
  @is_on_dedicated_capacity
end

#is_read_onlyObject (readonly)

Returns the value of attribute is_read_only.



3
4
5
# File 'lib/power-bi/workspace.rb', line 3

def is_read_only
  @is_read_only
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/power-bi/workspace.rb', line 3

def name
  @name
end

#reportsObject (readonly)

Returns the value of attribute reports.



3
4
5
# File 'lib/power-bi/workspace.rb', line 3

def reports
  @reports
end

Instance Method Details

#add_user(email_address, access_right = 'Member') ⇒ Object

TODO LATER: the ‘Viewer’ acces right is currently not settable throught the API. Fix that later



47
48
49
50
51
52
53
54
55
# File 'lib/power-bi/workspace.rb', line 47

def add_user(email_address, access_right = 'Member')
  @tenant.post("/groups/#{id}/users") do |req|
    req.body = {
      emailAddress: email_address,
      groupUserAccessRight: access_right
    }.to_json
  end
  true
end

#deleteObject



40
41
42
43
44
# File 'lib/power-bi/workspace.rb', line 40

def delete
  @tenant.delete("/groups/#{@id}")
  @tenant.workspaces.reload
  true
end

#upload_pbix(file, dataset_name, timeout: 30) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/power-bi/workspace.rb', line 17

def upload_pbix(file, dataset_name, timeout: 30)
  data = @tenant.post_file("/groups/#{@id}/imports", file, {datasetDisplayName: dataset_name})
  import_id = data[:id]
  success = false
  iterations = 0
  status_history = ''
  old_status = ''
  while !success
    sleep 0.1
    iterations += 1
    raise UploadError.new("Upload did not succeed after #{timeout} seconds. Status history:#{status_history}") if iterations > (10 * timeout)
    new_status = @tenant.get("/groups/#{@id}/imports/#{import_id}")[:importState].to_s
    success = (new_status == "Succeeded")
    if new_status != old_status
      status_history += "\nStatus change after #{iterations/10.0}s: '#{old_status}' --> '#{new_status}'"
      old_status = new_status
    end
  end
  @reports.reload
  @datasets.reload
  true
end