Class: PowerBI::Report
- Inherits:
-
Object
- Object
- PowerBI::Report
- Defined in:
- lib/power-bi/report.rb
Defined Under Namespace
Classes: ExportToFileError
Instance Attribute Summary collapse
-
#dataset_id ⇒ Object
readonly
Returns the value of attribute dataset_id.
-
#embed_url ⇒ Object
readonly
Returns the value of attribute embed_url.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#is_from_pbix ⇒ Object
readonly
Returns the value of attribute is_from_pbix.
-
#is_owned_by_me ⇒ Object
readonly
Returns the value of attribute is_owned_by_me.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#report_type ⇒ Object
readonly
Returns the value of attribute report_type.
-
#web_url ⇒ Object
readonly
Returns the value of attribute web_url.
-
#workspace ⇒ Object
readonly
Returns the value of attribute workspace.
Instance Method Summary collapse
- #clone(target_workspace, new_report_name) ⇒ Object
- #export_to_file(filename, format: 'PDF', timeout: 300) ⇒ Object
-
#initialize(tenant, data) ⇒ Report
constructor
A new instance of Report.
- #rebind(target_dataset) ⇒ Object
Constructor Details
#initialize(tenant, data) ⇒ Report
Returns a new instance of Report.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/power-bi/report.rb', line 7 def initialize(tenant, data) @id = data[:id] @report_type = data[:reportType] @name = data[:name] @web_url = data[:webUrl] @embed_url = data[:embedUrl] @is_from_pbix = data[:isFromPbix] @is_owned_by_me = data[:isOwnedByMe] @dataset_id = data[:datasetId] @workspace = data[:workspace] @tenant = tenant end |
Instance Attribute Details
#dataset_id ⇒ Object (readonly)
Returns the value of attribute dataset_id.
3 4 5 |
# File 'lib/power-bi/report.rb', line 3 def dataset_id @dataset_id end |
#embed_url ⇒ Object (readonly)
Returns the value of attribute embed_url.
3 4 5 |
# File 'lib/power-bi/report.rb', line 3 def @embed_url end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/power-bi/report.rb', line 3 def id @id end |
#is_from_pbix ⇒ Object (readonly)
Returns the value of attribute is_from_pbix.
3 4 5 |
# File 'lib/power-bi/report.rb', line 3 def is_from_pbix @is_from_pbix end |
#is_owned_by_me ⇒ Object (readonly)
Returns the value of attribute is_owned_by_me.
3 4 5 |
# File 'lib/power-bi/report.rb', line 3 def is_owned_by_me @is_owned_by_me end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/power-bi/report.rb', line 3 def name @name end |
#report_type ⇒ Object (readonly)
Returns the value of attribute report_type.
3 4 5 |
# File 'lib/power-bi/report.rb', line 3 def report_type @report_type end |
#web_url ⇒ Object (readonly)
Returns the value of attribute web_url.
3 4 5 |
# File 'lib/power-bi/report.rb', line 3 def web_url @web_url end |
#workspace ⇒ Object (readonly)
Returns the value of attribute workspace.
3 4 5 |
# File 'lib/power-bi/report.rb', line 3 def workspace @workspace end |
Instance Method Details
#clone(target_workspace, new_report_name) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/power-bi/report.rb', line 20 def clone(target_workspace, new_report_name) data = @tenant.post("/reports/#{@id}/Clone") do |req| req.body = { name: new_report_name, targetWorkspaceId: target_workspace.id }.to_json end target_workspace.reports.reload data[:workspace] = target_workspace Report.new(@tenant, data) end |
#export_to_file(filename, format: 'PDF', timeout: 300) ⇒ Object
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/power-bi/report.rb', line 41 def export_to_file(filename, format: 'PDF', timeout: 300) # post data = @tenant.post("/groups/#{workspace.id}/reports/#{id}/ExportTo") do |req| req.body = { format: format }.to_json end export_id = data[:id] # poll success = false iterations = 0 status_history = '' old_status = '' while !success sleep 0.1 iterations += 1 raise ExportToFileError.new("Report export to file did not succeed after #{timeout} seconds. Status history:#{status_history}") if iterations > (10 * timeout) new_status = @tenant.get("/groups/#{workspace.id}/reports/#{id}/exports/#{export_id}")[:status].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 # get and write file data = @tenant.get_raw("/groups/#{workspace.id}/reports/#{id}/exports/#{export_id}/file") File.open(filename, "wb") { |f| f.write(data) } end |
#rebind(target_dataset) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/power-bi/report.rb', line 32 def rebind(target_dataset) @tenant.post("/groups/#{workspace.id}/reports/#{id}/Rebind") do |req| req.body = { datasetId: target_dataset.id }.to_json end true end |