power-bi 1.7.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2cdaf275d6377b0f772985c4e6b616030022652fd88201f7cc79b04cfe009d67
4
- data.tar.gz: 654d2e658ffbc996beb652976094eceecf95256897ad70ff59b461e46810ff82
3
+ metadata.gz: 8c07790a47531d65bb2852b54424770b8ada89c21990e1834a4a6df0a5145abf
4
+ data.tar.gz: eab66b74310e06fb6e4e46a33d785013323991ff26e03690d79f58bc517ccf96
5
5
  SHA512:
6
- metadata.gz: ccf88e40d284bc8e91e0bc683ed077a42a077a810e409346ac6dce508e8803b9313c7ccc1ec3ab0937c43d53169dfdbb04db64c3c73d55b52180a4f2d59a0dc0
7
- data.tar.gz: 221a648dbbc8e35ab2ed75834dfbe756e57f5583282a5f1224194489378c6c17d3c10f5f2578c50f377e1536b14bd9398b7a586ba89ec751bfa89eb15c0ca79e
6
+ metadata.gz: 0e2f5fc2425a071970fe1f8f0738b4eb94ebd0b63b9f01b2fa5dd610be967b6a7a398d648611bef4f6f56a373c3af1cf6f9d53c2301de397a2ec3d3d535992d0
7
+ data.tar.gz: 82a07144dc3de0b18e48fb603dd6528dddc3d4fd003d86d973f71662435d37ef4e986b73d8857391937211500d52d064728a295378187819726576217a430594
data/README.md CHANGED
@@ -12,9 +12,14 @@ pbi = PowerBI::Tenant.new(->{token = get_token(client, token) ; token.token})
12
12
 
13
13
  # Supported endpoints
14
14
 
15
+ Note: where possible we use _lazy evaluation_: we only call the REST API endpoint when really needed. For examples `pbi.workspaces` won't trigger a call, while `pbi.workspaces.count` will trigger a call. And `pbi.workspace('123')`, while `pbi.workspace('123').name` will trigger a call.
16
+
17
+ Note 2: to limit the number of API calls, it is best to directly use the _getters_ iso the index.
18
+
15
19
  ## Workspaces (aka Groups)
16
20
 
17
21
  * List workspaces: `pbi.workspaces`
22
+ * Get a specific workspace `pbi.workspace(id)`
18
23
  * Create workspace: `pbi.workspaces.create`
19
24
  * Upload PBIX to workspace: `ws.upload_pbix('./test.pbix', 'new_datasetname_in_the_service')`
20
25
  * Delete workspace: `workspace.delete`
@@ -23,6 +28,7 @@ pbi = PowerBI::Tenant.new(->{token = get_token(client, token) ; token.token})
23
28
  ## Reports
24
29
 
25
30
  * List reports in a workspace: `workspace.reports`
31
+ * Get report in a workspace: `workspace.report(id)`
26
32
  * Clone a report from one workspace to another: `report.clone(src_workspace, new_report_name)`
27
33
  * Rebind report to another dataset: `report.rebind(dataset)`
28
34
  * Export report to file: `report.export_to_file(filenam, format: 'PDF')`
@@ -40,6 +46,7 @@ pbi = PowerBI::Tenant.new(->{token = get_token(client, token) ; token.token})
40
46
  ## Datasets
41
47
 
42
48
  * List datasets in a workspace: `workspace.datasets`
49
+ * Get report in a workspace: `workspace.dataset(id)`
43
50
  * Update parameter in a dataset: `dataset.update_parameter(parameter_name, new_value)`
44
51
  * Get time of last refresh: `dataset.last_refresh`
45
52
  * Refresh the dataset: `dataset.refresh`
@@ -49,6 +56,7 @@ pbi = PowerBI::Tenant.new(->{token = get_token(client, token) ; token.token})
49
56
  ## Gateways
50
57
 
51
58
  * List gateways: `pbi.gateways`
59
+ * Get a specific gateway `pbi.gateway(id)`
52
60
 
53
61
  ## Gateway datasources
54
62
 
@@ -2,10 +2,11 @@ module PowerBI
2
2
 
3
3
  class Array
4
4
 
5
- def initialize(tenant)
5
+ def initialize(tenant, parent = nil)
6
6
  @fulfilled = false
7
7
  @content = nil
8
8
  @tenant = tenant
9
+ @parent = parent
9
10
  end
10
11
 
11
12
  def reload
@@ -19,7 +20,7 @@ module PowerBI
19
20
  def get_content
20
21
  unless @fulfilled
21
22
  klass = self.class.get_class
22
- @content = get_data.map { |d| klass.new(@tenant, d)}
23
+ @content = get_data.map { |d| klass.instantiate_from_data(@tenant, @parent, d) }
23
24
  @fulfilled = true
24
25
  end
25
26
  @content
@@ -1,26 +1,33 @@
1
1
  module PowerBI
2
- class Dataset
3
- attr_reader :id, :name, :add_rows_API_enabled, :configured_by, :is_refreshable, :is_effective_identity_required,
4
- :is_effective_identity_roles_required, :is_on_prem_gateway_required, :target_storage_mode, :workspace, :datasources,
5
- :parameters, :refresh_history
2
+ class Dataset < Object
3
+ attr_reader :workspace, :datasources, :parameters, :refresh_history
6
4
 
7
- def initialize(tenant, data)
8
- @id = data[:id]
9
- @name = data[:name]
10
- @add_rows_API_enabled = data[:addRowsAPIEnabled]
11
- @configured_by = data[:configuredBy]
12
- @is_refreshable = data[:isRefreshable]
13
- @is_effective_identity_required = data[:isEffectiveIdentityRequired]
14
- @is_effective_identity_roles_required = data[:isEffectiveIdentityRolesRequired]
15
- @is_on_prem_gateway_required = data[:isOnPremGatewayRequired]
16
- @target_storage_mode = data[:targetStorageMode]
17
- @workspace = data[:workspace]
18
- @tenant = tenant
5
+ def initialize(tenant, parent, id = nil)
6
+ super(tenant, id)
7
+ @workspace = parent
19
8
  @datasources = DatasourceArray.new(@tenant, self)
20
9
  @parameters = ParameterArray.new(@tenant, self)
21
10
  @refresh_history = RefreshArray.new(@tenant, self)
22
11
  end
23
12
 
13
+ def get_data(id)
14
+ @tenant.get("/groups/#{@workspace.id}/datasets/#{id}")
15
+ end
16
+
17
+ def data_to_attributes(data)
18
+ {
19
+ id: data[:id],
20
+ name: data[:name],
21
+ add_rows_API_enabled: data[:addRowsAPIEnabled],
22
+ configured_by: data[:configuredBy],
23
+ is_refreshable: data[:isRefreshable],
24
+ is_effective_identity_required: data[:isEffectiveIdentityRequired],
25
+ is_effective_identity_roles_required: data[:isEffectiveIdentityRolesRequired],
26
+ is_on_prem_gateway_required: data[:isOnPremGatewayRequired],
27
+ target_storage_mode: data[:targetStorageMode],
28
+ }
29
+ end
30
+
24
31
  def update_parameter(name, value)
25
32
  @tenant.post("/groups/#{workspace.id}/datasets/#{id}/Default.UpdateParameters") do |req|
26
33
  req.body = {
@@ -66,7 +73,7 @@ module PowerBI
66
73
  class DatasetArray < Array
67
74
 
68
75
  def initialize(tenant, workspace)
69
- super(tenant)
76
+ super(tenant, workspace)
70
77
  @workspace = workspace
71
78
  end
72
79
 
@@ -75,8 +82,7 @@ module PowerBI
75
82
  end
76
83
 
77
84
  def get_data
78
- data = @tenant.get("/groups/#{@workspace.id}/datasets")[:value]
79
- data.each { |d| d[:workspace] = @workspace }
85
+ @tenant.get("/groups/#{@workspace.id}/datasets")[:value]
80
86
  end
81
87
  end
82
88
  end
@@ -1,13 +1,19 @@
1
1
  module PowerBI
2
- class Datasource
3
- attr_reader :gateway_id, :datasource_id, :datasource_type, :connection_details
2
+ class Datasource < Object
3
+ attr_reader :dataset
4
4
 
5
- def initialize(tenant, data)
6
- @gateway_id = data[:gatewayId]
7
- @datasource_type = data[:datasourceType]
8
- @connection_details = data[:connectionDetails]
9
- @datasource_id = data[:datasourceId]
10
- @tenant = tenant
5
+ def initialize(tenant, parent, id = nil)
6
+ super(tenant, id)
7
+ @dataset = parent
8
+ end
9
+
10
+ def data_to_attributes(data)
11
+ {
12
+ gateway_id: data[:gatewayId],
13
+ datasource_type: data[:datasourceType],
14
+ connection_details: data[:connectionDetails],
15
+ datasource_id: data[:datasourceId],
16
+ }
11
17
  end
12
18
 
13
19
  end
@@ -15,7 +21,7 @@ module PowerBI
15
21
  class DatasourceArray < Array
16
22
 
17
23
  def initialize(tenant, dataset)
18
- super(tenant)
24
+ super(tenant, dataset)
19
25
  @dataset = dataset
20
26
  end
21
27
 
@@ -1,16 +1,29 @@
1
1
  module PowerBI
2
- class Gateway
3
- attr_reader :name, :id, :type, :public_key, :gateway_datasources
2
+ class Gateway < Object
3
+ attr_reader :gateway_datasources
4
4
 
5
- def initialize(tenant, data)
6
- @id = data[:id]
7
- @name = data[:name]
8
- @type = data[:type]
9
- @public_key = data[:publicKey]
10
- @tenant = tenant
5
+ def initialize(tenant, parent, id = nil)
6
+ super(tenant, id)
11
7
  @gateway_datasources = GatewayDatasourceArray.new(@tenant, self)
12
8
  end
13
9
 
10
+ def get_data(id)
11
+ @tenant.get("/gateways/#{id}")
12
+ end
13
+
14
+ def data_to_attributes(data)
15
+ {
16
+ id: data[:id],
17
+ name: data[:name],
18
+ type: data[:type],
19
+ public_key: data[:publicKey],
20
+ }
21
+ end
22
+
23
+ def gateway_datasource(id)
24
+ GatewayDatasource.new(@tenant, self, id)
25
+ end
26
+
14
27
  end
15
28
 
16
29
  class GatewayArray < Array
@@ -1,20 +1,30 @@
1
1
  module PowerBI
2
- class GatewayDatasource
3
- attr_reader :id, :gateway_id, :datasource_type, :connection_details, :credential_type, :datasource_name, :gateway
2
+ class GatewayDatasource < Object
3
+ attr_reader :gateway
4
4
 
5
- def initialize(tenant, data)
6
- @gateway_id = data[:gatewayId]
7
- @datasource_type = data[:datasourceType]
8
- @datasource_name = data[:datasourceName]
9
- @connection_details = data[:connectionDetails]
10
- @id = data[:id]
11
- @credential_type = data[:credentialType]
12
- @gateway = data[:gateway]
13
- @tenant = tenant
5
+ def initialize(tenant, parent, id = nil)
6
+ super(tenant, id)
7
+ @gateway = parent
8
+ end
9
+
10
+ def get_data(id)
11
+ @tenant.get("/gateways/#{@gateway.id}/datasources/#{id}")
12
+ end
13
+
14
+ def data_to_attributes(data)
15
+ {
16
+ gateway_id: data[:gatewayId],
17
+ datasource_type: data[:datasourceType],
18
+ datasource_name: data[:datasourceName],
19
+ connection_details: data[:connectionDetails],
20
+ id: data[:id],
21
+ credential_type: data[:credentialType],
22
+ gateway: data[:gateway],
23
+ }
14
24
  end
15
25
 
16
26
  def update_credentials(encrypted_credentials)
17
- response = @tenant.patch("/gateways/#{gateway.id}/datasources/#{id}") do |req|
27
+ @tenant.patch("/gateways/#{gateway.id}/datasources/#{id}") do |req|
18
28
  req.body = {
19
29
  credentialDetails: {
20
30
  credentialType: "Basic",
@@ -41,7 +51,7 @@ module PowerBI
41
51
  class GatewayDatasourceArray < Array
42
52
 
43
53
  def initialize(tenant, gateway)
44
- super(tenant)
54
+ super(tenant, gateway)
45
55
  @gateway = gateway
46
56
  end
47
57
 
@@ -68,12 +78,11 @@ module PowerBI
68
78
  }.to_json
69
79
  end
70
80
  self.reload
71
- GatewayDatasource.new(@tenant, data)
81
+ GatewayDatasource.instantiate_from_data(@tenant, @gateway, data)
72
82
  end
73
83
 
74
84
  def get_data
75
- data = @tenant.get("/gateways/#{@gateway.id}/datasources")[:value]
76
- data.each { |d| d[:gateway] = @gateway }
85
+ @tenant.get("/gateways/#{@gateway.id}/datasources")[:value]
77
86
  end
78
87
  end
79
88
  end
@@ -0,0 +1,59 @@
1
+ module PowerBI
2
+
3
+ class Object
4
+ attr_reader :id
5
+
6
+ class UnkownAttributeError < PowerBI::Error ; end
7
+ class UnspecifiedIdError < PowerBI::Error ; end
8
+
9
+ def initialize(tenant, id = nil)
10
+ @id = id
11
+ @fulfilled = false
12
+ @not_found = nil
13
+ @attributes = nil
14
+ @tenant = tenant
15
+ end
16
+
17
+ def set_attributes(data)
18
+ @fulfilled = true
19
+ @not_found = false
20
+ @id = data[:id]
21
+ @attributes = data_to_attributes(data)
22
+ end
23
+
24
+ def reload
25
+ @fulfilled = false
26
+ @attributes = nil
27
+ self
28
+ end
29
+
30
+ def self.instantiate_from_data(tenant, parent, data)
31
+ o = new(tenant, parent)
32
+ o.set_attributes(data)
33
+ o
34
+ end
35
+
36
+ private
37
+
38
+ def get_attributes
39
+ unless @fulfilled
40
+ raise UnspecifiedIdError unless @id
41
+ begin
42
+ set_attributes(get_data(@id))
43
+ rescue PowerBI::NotFoundError
44
+ @not_found = true
45
+ raise PowerBI::NotFoundError
46
+ end
47
+ end
48
+ @attributes
49
+ end
50
+
51
+ def method_missing(method, *args, &block)
52
+ get_attributes.fetch(method.to_sym) do
53
+ raise UnkownAttributeError.new "Unknown attribute #{method}"
54
+ end
55
+ end
56
+
57
+ end
58
+
59
+ end
data/lib/power-bi/page.rb CHANGED
@@ -1,20 +1,26 @@
1
1
  module PowerBI
2
- class Page
3
- attr_reader :display_name, :name, :order, :report
2
+ class Page < Object
3
+ attr_reader :report
4
4
 
5
- def initialize(tenant, data)
6
- @name = data[:name]
7
- @display_name = data[:displayName]
8
- @order = data[:order]
9
- @report = data[:report]
10
- @tenant = tenant
5
+ def initialize(tenant, parent, id = nil)
6
+ super(tenant, id)
7
+ @report = parent
11
8
  end
9
+
10
+ def data_to_attributes(data)
11
+ {
12
+ name: data[:name],
13
+ display_name: data[:displayName],
14
+ order: data[:order],
15
+ }
16
+ end
17
+
12
18
  end
13
19
 
14
20
  class PageArray < Array
15
21
 
16
22
  def initialize(tenant, report)
17
- super(tenant)
23
+ super(tenant, report)
18
24
  @report = report
19
25
  end
20
26
 
@@ -23,8 +29,7 @@ module PowerBI
23
29
  end
24
30
 
25
31
  def get_data
26
- data = @tenant.get("/groups/#{@report.workspace.id}/reports/#{@report.id}/pages")[:value]
27
- data.each { |d| d[:report] = @report }
32
+ @tenant.get("/groups/#{@report.workspace.id}/reports/#{@report.id}/pages")[:value]
28
33
  end
29
34
  end
30
35
  end
@@ -1,12 +1,19 @@
1
1
  module PowerBI
2
- class Parameter
3
- attr_reader :name, :type, :is_required, :current_value
2
+ class Parameter < Object
3
+ attr_reader :dataset
4
4
 
5
- def initialize(tenant, data)
6
- @name = data[:name]
7
- @type = data[:type]
8
- @is_required = data[:isRequired]
9
- @current_value = data[:currentValue]
5
+ def initialize(tenant, parent, id = nil)
6
+ super(tenant, id)
7
+ @dataset = parent
8
+ end
9
+
10
+ def data_to_attributes(data)
11
+ {
12
+ name: data[:name],
13
+ type: data[:type],
14
+ is_required: data[:isRequired],
15
+ current_value: data[:currentValue],
16
+ }
10
17
  end
11
18
 
12
19
  end
@@ -14,7 +21,7 @@ module PowerBI
14
21
  class ParameterArray < Array
15
22
 
16
23
  def initialize(tenant, dataset)
17
- super(tenant)
24
+ super(tenant, dataset)
18
25
  @dataset = dataset
19
26
  end
20
27
 
@@ -1,15 +1,22 @@
1
1
  module PowerBI
2
- class Refresh
3
- attr_reader :refresh_type, :start_time, :end_time, :service_exception_json, :status, :request_id
2
+ class Refresh < Object
3
+ attr_reader :dataset
4
4
 
5
- def initialize(tenant, data)
6
- @id = data[:id]
7
- @refresh_type = data[:refreshType]
8
- @start_time = DateTime.iso8601(data[:startTime])
9
- @end_time = DateTime.iso8601(data[:endTime]) if data[:endTime]
10
- @service_exception_json = data[:serviceExceptionJson]
11
- @status = data[:status]
12
- @request_id = data[:requestId]
5
+ def initialize(tenant, parent, id = nil)
6
+ super(tenant, id)
7
+ @dataset = parent
8
+ end
9
+
10
+ def data_to_attributes(data)
11
+ {
12
+ id: data[:id],
13
+ refresh_type: data[:refreshType],
14
+ start_time: DateTime.iso8601(data[:startTime]),
15
+ end_time: data[:endTime] ? DateTime.iso8601(data[:endTime]) : nil,
16
+ service_exception_json: data[:serviceExceptionJson],
17
+ status: data[:status],
18
+ request_id: data[:requestId],
19
+ }
13
20
  end
14
21
 
15
22
  end
@@ -17,7 +24,7 @@ module PowerBI
17
24
  class RefreshArray < Array
18
25
 
19
26
  def initialize(tenant, dataset)
20
- super(tenant)
27
+ super(tenant, dataset)
21
28
  @dataset = dataset
22
29
  end
23
30
 
@@ -26,7 +33,7 @@ module PowerBI
26
33
  end
27
34
 
28
35
  def get_data
29
- @tenant.get("/groups/#{@dataset.workspace.id}/datasets/#{@dataset.id}/refreshes", {'$top': '3'})[:value]
36
+ @tenant.get("/groups/#{@dataset.workspace.id}/datasets/#{@dataset.id}/refreshes", {'$top': '1'})[:value]
30
37
  end
31
38
  end
32
39
  end
@@ -1,23 +1,32 @@
1
1
  module PowerBI
2
- class Report
3
- attr_reader :name, :id, :report_type, :web_url, :embed_url, :is_from_pbix, :is_owned_by_me, :dataset_id, :workspace, :pages
2
+ class Report < Object
3
+ attr_reader :workspace, :pages
4
4
 
5
5
  class ExportToFileError < PowerBI::Error ; end
6
6
 
7
- def initialize(tenant, data)
8
- @id = data[:id]
9
- @report_type = data[:reportType]
10
- @name = data[:name]
11
- @web_url = data[:webUrl]
12
- @embed_url = data[:embedUrl]
13
- @is_from_pbix = data[:isFromPbix]
14
- @is_owned_by_me = data[:isOwnedByMe]
15
- @dataset_id = data[:datasetId]
16
- @workspace = data[:workspace]
17
- @tenant = tenant
7
+ def initialize(tenant, parent, id = nil)
8
+ super(tenant, id)
9
+ @workspace = parent
18
10
  @pages = PageArray.new(@tenant, self)
19
11
  end
20
12
 
13
+ def get_data(id)
14
+ @tenant.get("/groups/#{@workspace.id}/reports/#{id}")
15
+ end
16
+
17
+ def data_to_attributes(data)
18
+ {
19
+ id: data[:id],
20
+ report_type: data[:reportType],
21
+ name: data[:name],
22
+ web_url: data[:webUrl],
23
+ embed_url: data[:embedUrl],
24
+ is_from_pbix: data[:isFromPbix],
25
+ is_owned_by_me: data[:isOwnedByMe],
26
+ dataset_id: data[:datasetId],
27
+ }
28
+ end
29
+
21
30
  def clone(target_workspace, new_report_name)
22
31
  data = @tenant.post("/reports/#{@id}/Clone") do |req|
23
32
  req.body = {
@@ -75,7 +84,7 @@ module PowerBI
75
84
  class ReportArray < Array
76
85
 
77
86
  def initialize(tenant, workspace)
78
- super(tenant)
87
+ super(tenant, workspace)
79
88
  @workspace = workspace
80
89
  end
81
90
 
@@ -84,8 +93,7 @@ module PowerBI
84
93
  end
85
94
 
86
95
  def get_data
87
- data = @tenant.get("/groups/#{@workspace.id}/reports")[:value]
88
- data.each { |d| d[:workspace] = @workspace }
96
+ @tenant.get("/groups/#{@workspace.id}/reports")[:value]
89
97
  end
90
98
  end
91
99
  end
@@ -29,6 +29,14 @@ module PowerBI
29
29
  end
30
30
  end
31
31
 
32
+ def workspace(id)
33
+ Workspace.new(self, nil, id)
34
+ end
35
+
36
+ def gateway(id)
37
+ Gateway.new(self, nil, id)
38
+ end
39
+
32
40
  def get(url, params = {})
33
41
  t0 = Time.now
34
42
  conn = Faraday.new do |f|
@@ -40,10 +48,13 @@ module PowerBI
40
48
  req.headers['authorization'] = "Bearer #{token}"
41
49
  yield req if block_given?
42
50
  end
51
+ if response.status == 400
52
+ raise NotFoundError
53
+ end
43
54
  unless [200, 202].include? response.status
44
55
  raise APIError.new("Error calling Power BI API (status #{response.status}): #{response.body}")
45
56
  end
46
- log "Calling (GET) #{url} - took #{((Time.now - t0) * 1000).to_i} ms"
57
+ log "Calling (GET) #{response.env.url.to_s} - took #{((Time.now - t0) * 1000).to_i} ms"
47
58
  unless response.body.empty?
48
59
  JSON.parse(response.body, symbolize_names: true)
49
60
  end
@@ -59,7 +70,7 @@ module PowerBI
59
70
  req.headers['authorization'] = "Bearer #{token}"
60
71
  yield req if block_given?
61
72
  end
62
- log "Calling (GET - raw) #{url} - took #{((Time.now - t0) * 1000).to_i} ms"
73
+ log "Calling (GET - raw) #{response.env.url.to_s} - took #{((Time.now - t0) * 1000).to_i} ms"
63
74
  unless [200, 202].include? response.status
64
75
  raise APIError.new("Error calling Power BI API (status #{response.status}): #{response.body}")
65
76
  end
@@ -78,7 +89,7 @@ module PowerBI
78
89
  req.headers['authorization'] = "Bearer #{token}"
79
90
  yield req if block_given?
80
91
  end
81
- log "Calling (POST) #{url} - took #{((Time.now - t0) * 1000).to_i} ms"
92
+ log "Calling (POST) #{response.env.url.to_s} - took #{((Time.now - t0) * 1000).to_i} ms"
82
93
  unless [200, 201, 202].include? response.status
83
94
  raise APIError.new("Error calling Power BI API (status #{response.status}): #{response.body}")
84
95
  end
@@ -99,7 +110,7 @@ module PowerBI
99
110
  req.headers['authorization'] = "Bearer #{token}"
100
111
  yield req if block_given?
101
112
  end
102
- log "Calling (PATCH) #{url} - took #{((Time.now - t0) * 1000).to_i} ms"
113
+ log "Calling (PATCH) #{response.env.url.to_s} - took #{((Time.now - t0) * 1000).to_i} ms"
103
114
  unless [200, 202].include? response.status
104
115
  raise APIError.new("Error calling Power BI API (status #{response.status}): #{response.body}")
105
116
  end
@@ -119,7 +130,10 @@ module PowerBI
119
130
  req.headers['authorization'] = "Bearer #{token}"
120
131
  yield req if block_given?
121
132
  end
122
- log "Calling (DELETE) #{url} - took #{((Time.now - t0) * 1000).to_i} ms"
133
+ log "Calling (DELETE) #{response.env.url.to_s} - took #{((Time.now - t0) * 1000).to_i} ms"
134
+ if [400, 401, 404].include? response.status
135
+ raise NotFoundError
136
+ end
123
137
  unless [200, 202].include? response.status
124
138
  raise APIError.new("Error calling Power BI API (status #{response.status}): #{response.body}")
125
139
  end
@@ -142,7 +156,7 @@ module PowerBI
142
156
  req.body = {value: Faraday::UploadIO.new(file, 'application/octet-stream')}
143
157
  req.options.timeout = 120 # default is 60 seconds Net::ReadTimeout
144
158
  end
145
- log "Calling (POST - file) #{url} - took #{((Time.now - t0) * 1000).to_i} ms"
159
+ log "Calling (POST - file) #{response.env.url.to_s} - took #{((Time.now - t0) * 1000).to_i} ms"
146
160
  if response.status != 202
147
161
  raise APIError.new("Error calling Power BI API (status #{response.status}): #{response.body}")
148
162
  end
data/lib/power-bi/user.rb CHANGED
@@ -1,15 +1,20 @@
1
1
  module PowerBI
2
- class User
3
- attr_reader :email_address, :group_user_access_right, :display_name, :identifier, :principal_type
4
-
5
- def initialize(tenant, data)
6
- @email_address = data[:emailAddress]
7
- @group_user_access_right = data[:groupUserAccessRight]
8
- @display_name = data[:displayName]
9
- @identifier = data[:identifier]
10
- @principal_type = data[:principalType]
11
- @workspace = data[:workspace]
12
- @tenant = tenant
2
+ class User < Object
3
+ attr_reader :workspace
4
+
5
+ def initialize(tenant, parent, id = nil)
6
+ super(tenant, id)
7
+ @workspace = parent
8
+ end
9
+
10
+ def data_to_attributes(data)
11
+ {
12
+ email_address: data[:emailAddress],
13
+ group_user_access_right: data[:groupUserAccessRight],
14
+ display_name: data[:displayName],
15
+ identifier: data[:identifier],
16
+ principal_type: data[:principalType],
17
+ }
13
18
  end
14
19
 
15
20
  def delete
@@ -22,7 +27,7 @@ module PowerBI
22
27
  class UserArray < Array
23
28
 
24
29
  def initialize(tenant, workspace)
25
- super(tenant)
30
+ super(tenant, workspace)
26
31
  @workspace = workspace
27
32
  end
28
33
 
@@ -41,8 +46,7 @@ module PowerBI
41
46
  end
42
47
 
43
48
  def get_data
44
- data = @tenant.get("/groups/#{@workspace.id}/users")[:value]
45
- data.each { |d| d[:workspace] = @workspace }
49
+ @tenant.get("/groups/#{@workspace.id}/users")[:value]
46
50
  end
47
51
  end
48
52
  end
@@ -1,20 +1,29 @@
1
1
  module PowerBI
2
- class Workspace
3
- attr_reader :name, :is_read_only, :is_on_dedicated_capacity, :id, :reports, :datasets, :users
2
+ class Workspace < Object
3
+ attr_reader :reports, :datasets, :users
4
4
 
5
5
  class UploadError < PowerBI::Error ; end
6
6
 
7
- def initialize(tenant, data)
8
- @id = data[:id]
9
- @is_read_only = data[:isReadOnly]
10
- @is_on_dedicated_capacity = data[:isOnDedicatedCapacity]
11
- @name = data[:name]
12
- @tenant = tenant
7
+ def initialize(tenant, parent, id = nil)
8
+ super(tenant, id)
13
9
  @reports = ReportArray.new(@tenant, self)
14
10
  @datasets = DatasetArray.new(@tenant, self)
15
11
  @users = UserArray.new(@tenant, self)
16
12
  end
17
13
 
14
+ def get_data(id)
15
+ @tenant.get("/groups", {'$filter': "id eq #{id}"})[:value].first
16
+ end
17
+
18
+ def data_to_attributes(data)
19
+ {
20
+ id: data[:id],
21
+ is_read_only: data[:isReadOnly],
22
+ is_on_dedicated_capacity: data[:isOnDedicatedCapacity],
23
+ name: data[:name],
24
+ }
25
+ end
26
+
18
27
  def upload_pbix(file, dataset_name, timeout: 30)
19
28
  data = @tenant.post_file("/groups/#{@id}/imports", file, {datasetDisplayName: dataset_name})
20
29
  import_id = data[:id]
@@ -44,6 +53,14 @@ module PowerBI
44
53
  true
45
54
  end
46
55
 
56
+ def report(id)
57
+ Report.new(@tenant, self, id)
58
+ end
59
+
60
+ def dataset(id)
61
+ Dataset.new(@tenant, self, id)
62
+ end
63
+
47
64
  end
48
65
 
49
66
  class WorkspaceArray < Array
@@ -56,7 +73,7 @@ module PowerBI
56
73
  req.body = {name: name}.to_json
57
74
  end
58
75
  self.reload
59
- Workspace.new(@tenant, data)
76
+ Workspace.instantiate_from_data(@tenant, nil, data)
60
77
  end
61
78
 
62
79
  def get_data
data/lib/power-bi.rb CHANGED
@@ -8,9 +8,11 @@ module PowerBI
8
8
 
9
9
  class Error < StandardError ; end
10
10
  class APIError < Error ; end
11
+ class NotFoundError < Error; end
11
12
  end
12
13
 
13
14
  require_relative "power-bi/tenant"
15
+ require_relative "power-bi/object"
14
16
  require_relative "power-bi/array"
15
17
  require_relative "power-bi/workspace"
16
18
  require_relative "power-bi/report"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: power-bi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lode Cools
@@ -94,6 +94,7 @@ files:
94
94
  - lib/power-bi/datasource.rb
95
95
  - lib/power-bi/gateway.rb
96
96
  - lib/power-bi/gateway_datasource.rb
97
+ - lib/power-bi/object.rb
97
98
  - lib/power-bi/page.rb
98
99
  - lib/power-bi/parameter.rb
99
100
  - lib/power-bi/refresh.rb