Class: PowerBI::Workspace
Defined Under Namespace
Classes: UploadError
Instance Attribute Summary collapse
-
#datasets ⇒ Object
readonly
Returns the value of attribute datasets.
-
#reports ⇒ Object
readonly
Returns the value of attribute reports.
-
#users ⇒ Object
readonly
Returns the value of attribute users.
Attributes inherited from Object
Instance Method Summary collapse
- #data_to_attributes(data) ⇒ Object
- #dataset(id) ⇒ Object
- #delete ⇒ Object
- #get_data(id) ⇒ Object
-
#initialize(tenant, parent, id = nil) ⇒ Workspace
constructor
A new instance of Workspace.
- #report(id) ⇒ Object
- #upload_pbix(file, dataset_name, timeout: 30) ⇒ Object
Methods inherited from Object
instantiate_from_data, #reload, #set_attributes
Constructor Details
#initialize(tenant, parent, id = nil) ⇒ Workspace
Returns a new instance of Workspace.
7 8 9 10 11 12 |
# File 'lib/power-bi/workspace.rb', line 7 def initialize(tenant, parent, id = nil) super(tenant, id) @reports = ReportArray.new(@tenant, self) @datasets = DatasetArray.new(@tenant, self) @users = UserArray.new(@tenant, self) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class PowerBI::Object
Instance Attribute Details
#datasets ⇒ Object (readonly)
Returns the value of attribute datasets.
3 4 5 |
# File 'lib/power-bi/workspace.rb', line 3 def datasets @datasets end |
#reports ⇒ Object (readonly)
Returns the value of attribute reports.
3 4 5 |
# File 'lib/power-bi/workspace.rb', line 3 def reports @reports end |
#users ⇒ Object (readonly)
Returns the value of attribute users.
3 4 5 |
# File 'lib/power-bi/workspace.rb', line 3 def users @users end |
Instance Method Details
#data_to_attributes(data) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/power-bi/workspace.rb', line 18 def data_to_attributes(data) { id: data[:id], is_read_only: data[:isReadOnly], is_on_dedicated_capacity: data[:isOnDedicatedCapacity], name: data[:name], } end |
#dataset(id) ⇒ Object
60 61 62 |
# File 'lib/power-bi/workspace.rb', line 60 def dataset(id) Dataset.new(@tenant, self, id) end |
#delete ⇒ Object
50 51 52 53 54 |
# File 'lib/power-bi/workspace.rb', line 50 def delete @tenant.delete("/groups/#{@id}") @tenant.workspaces.reload true end |
#get_data(id) ⇒ Object
14 15 16 |
# File 'lib/power-bi/workspace.rb', line 14 def get_data(id) @tenant.get("/groups", {'$filter': "id eq #{id}"})[:value].first end |
#report(id) ⇒ Object
56 57 58 |
# File 'lib/power-bi/workspace.rb', line 56 def report(id) Report.new(@tenant, self, id) end |
#upload_pbix(file, dataset_name, timeout: 30) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/power-bi/workspace.rb', line 27 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.5 iterations += 1 raise UploadError.new("Upload did not succeed after #{timeout} seconds. Status history:#{status_history}") if iterations > (2 * 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/2}s: '#{old_status}' --> '#{new_status}'" old_status = new_status end end @reports.reload @datasets.reload true end |