power-bi 2.0.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -3
- data/lib/power-bi/capacity.rb +35 -0
- data/lib/power-bi/report.rb +13 -0
- data/lib/power-bi/tenant.rb +8 -3
- data/lib/power-bi/user.rb +1 -1
- data/lib/power-bi/workspace.rb +36 -0
- data/lib/power-bi.rb +2 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5aaadec6cec57b22f4780dd2e1f4c64c55872d49f5a17a59326fcff099844dd
|
4
|
+
data.tar.gz: 1a6bf8c48a1d17333f58519c5ee23ee9a85025c63110c6cc2f2fe9243566f7ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 570af0ad49001778d237e4ce712a8120d879cc83d53a9b4a877d2d51ee6fcc3dde4e913cc8a3c42273ce5de45d31d7922308fee03c895fb6fcbce46332b06288
|
7
|
+
data.tar.gz: 760813b41e3318fc52871f3adc61f4efcf518f9333f93fcf9295c15b9e61d094518cbd3adbbf7fec0c3c7921239d2082460099fc2adffcd4b60c15067e5946e1
|
data/README.md
CHANGED
@@ -12,9 +12,9 @@ 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')
|
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')` won't trigger a call, while `pbi.workspace('123').name` will trigger a call.
|
16
16
|
|
17
|
-
Note 2: to limit the number of API calls, it is best to directly use the _getters_ iso the
|
17
|
+
Note 2: to limit the number of API calls, it is best to directly use the _getters_ iso the _lists_.
|
18
18
|
|
19
19
|
## Workspaces (aka Groups)
|
20
20
|
|
@@ -24,6 +24,8 @@ Note 2: to limit the number of API calls, it is best to directly use the _getter
|
|
24
24
|
* Upload PBIX to workspace: `ws.upload_pbix('./test.pbix', 'new_datasetname_in_the_service')`
|
25
25
|
* Delete workspace: `workspace.delete`
|
26
26
|
* Add a user to a wokspace: `workspace.add_user('company_0001@fabrikam.com')`
|
27
|
+
* Assign a workspace to a capacity: `workspace.assign_to_capacity(capacity)`
|
28
|
+
* Unassign a workspace from a capacity: `workspace.unassign_from_capacity`
|
27
29
|
|
28
30
|
## Reports
|
29
31
|
|
@@ -31,7 +33,8 @@ Note 2: to limit the number of API calls, it is best to directly use the _getter
|
|
31
33
|
* Get report in a workspace: `workspace.report(id)`
|
32
34
|
* Clone a report from one workspace to another: `report.clone(src_workspace, new_report_name)`
|
33
35
|
* Rebind report to another dataset: `report.rebind(dataset)`
|
34
|
-
* Export report to file: `report.export_to_file(
|
36
|
+
* Export report to file: `report.export_to_file(filename, format: 'PDF')`
|
37
|
+
* Get embed token: `report.embed_token(access_level: 'View', lifetime_in_minutes: 60)`
|
35
38
|
|
36
39
|
## Pages
|
37
40
|
|
@@ -65,6 +68,13 @@ Note 2: to limit the number of API calls, it is best to directly use the _getter
|
|
65
68
|
* Create a new gateway datasource: `gateway.gateway_datasource.create(name, credentials, db_server, db_name)`
|
66
69
|
* Delete a new gateway datasource: `gateway_datasource.delete`
|
67
70
|
|
71
|
+
## Capacities
|
72
|
+
|
73
|
+
Note: Capacities are Azure creatures, you can't create them in Power BI.
|
74
|
+
|
75
|
+
* List capacities: `pbi.capacities`
|
76
|
+
* Get a capacity: `pbi.capacity(id)`
|
77
|
+
|
68
78
|
# Note about gateway credentials
|
69
79
|
|
70
80
|
Power BI uses an obscure mechanism to encrypt credential exchange between the service and the gateway. The encryption must be done outside this module on a Windows machine based on th public key of the gateway. This is an example C# script:
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module PowerBI
|
2
|
+
class Capacity < Object
|
3
|
+
|
4
|
+
def initialize(tenant, parent, id = nil)
|
5
|
+
super(tenant, id)
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_data(id)
|
9
|
+
@tenant.get("/capacities", {'$filter': "id eq #{id}"})[:value].first
|
10
|
+
end
|
11
|
+
|
12
|
+
def data_to_attributes(data)
|
13
|
+
{
|
14
|
+
id: data[:id],
|
15
|
+
display_name: data[:displayName],
|
16
|
+
sku: data[:sku],
|
17
|
+
state: data[:state],
|
18
|
+
region: data[:region],
|
19
|
+
capacity_user_access_right: data[:capacityUserAccessRight],
|
20
|
+
admins: data[:admins],
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
class CapacityArray < Array
|
27
|
+
def self.get_class
|
28
|
+
Capacity
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_data
|
32
|
+
@tenant.get("/capacities")[:value]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/power-bi/report.rb
CHANGED
@@ -79,6 +79,19 @@ module PowerBI
|
|
79
79
|
File.open(filename, "wb") { |f| f.write(data) }
|
80
80
|
end
|
81
81
|
|
82
|
+
def embed_token(access_level: 'View', lifetime_in_minutes: 60)
|
83
|
+
data = @tenant.post("/groups/#{workspace.id}/reports/#{id}/GenerateToken") do |req|
|
84
|
+
req.body = {
|
85
|
+
accessLevel: access_level,
|
86
|
+
lifetimeInMinutes: lifetime_in_minutes
|
87
|
+
}.to_json
|
88
|
+
end
|
89
|
+
{
|
90
|
+
token: data[:token],
|
91
|
+
expiration: Time.parse(data[:expiration])
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
82
95
|
end
|
83
96
|
|
84
97
|
class ReportArray < Array
|
data/lib/power-bi/tenant.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
module PowerBI
|
2
2
|
class Tenant
|
3
|
-
attr_reader :workspaces, :gateways
|
3
|
+
attr_reader :workspaces, :gateways, :capacities
|
4
4
|
|
5
5
|
def initialize(token_generator, retries: 5, logger: nil)
|
6
6
|
@token_generator = token_generator
|
7
7
|
@workspaces = WorkspaceArray.new(self)
|
8
8
|
@gateways = GatewayArray.new(self)
|
9
|
+
@capacities = CapacityArray.new(self)
|
9
10
|
@logger = logger
|
10
11
|
|
11
12
|
## WHY RETRIES? ##
|
12
|
-
# It is noticed that once in a while (~0.1% API calls), the Power BI server returns a 500 (internal server error)
|
13
|
+
# It is noticed that once in a while (~0.1% API calls), the Power BI server returns a 500 (internal server error) without apparent reason, just retrying works :-)
|
13
14
|
##################
|
14
15
|
@retry_options = {
|
15
16
|
max: retries,
|
16
|
-
exceptions: [Errno::ETIMEDOUT, Timeout::Error, Faraday::TimeoutError, Faraday::RetriableResponse],
|
17
|
+
exceptions: [Errno::ETIMEDOUT, Timeout::Error, Faraday::TimeoutError, Faraday::RetriableResponse, Faraday::ConnectionFailed],
|
17
18
|
methods: [:get, :post, :patch, :delete],
|
18
19
|
retry_statuses: [500], # internal server error
|
19
20
|
interval: 0.2,
|
@@ -37,6 +38,10 @@ module PowerBI
|
|
37
38
|
Gateway.new(self, nil, id)
|
38
39
|
end
|
39
40
|
|
41
|
+
def capacity(id)
|
42
|
+
Capacity.new(self, nil, id)
|
43
|
+
end
|
44
|
+
|
40
45
|
def get(url, params = {})
|
41
46
|
t0 = Time.now
|
42
47
|
conn = Faraday.new do |f|
|
data/lib/power-bi/user.rb
CHANGED
data/lib/power-bi/workspace.rb
CHANGED
@@ -3,6 +3,7 @@ module PowerBI
|
|
3
3
|
attr_reader :reports, :datasets, :users
|
4
4
|
|
5
5
|
class UploadError < PowerBI::Error ; end
|
6
|
+
class CapacityAssignmentError < PowerBI::Error ; end
|
6
7
|
|
7
8
|
def initialize(tenant, parent, id = nil)
|
8
9
|
super(tenant, id)
|
@@ -61,6 +62,41 @@ module PowerBI
|
|
61
62
|
Dataset.new(@tenant, self, id)
|
62
63
|
end
|
63
64
|
|
65
|
+
def assign_to_capacity(capacity, timeout: 30)
|
66
|
+
_assign_to_capacity(capacity.id, timeout: timeout)
|
67
|
+
end
|
68
|
+
|
69
|
+
def unassign_from_capacity(timeout: 30)
|
70
|
+
_assign_to_capacity('00000000-0000-0000-0000-000000000000', timeout: timeout)
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def _assign_to_capacity(capacity_id, timeout: 30)
|
76
|
+
@tenant.post("/groups/#{@id}/AssignToCapacity") do |req|
|
77
|
+
req.body = {
|
78
|
+
capacityId: capacity_id,
|
79
|
+
}.to_json
|
80
|
+
end
|
81
|
+
|
82
|
+
success = false
|
83
|
+
iterations = 0
|
84
|
+
status_history = ''
|
85
|
+
old_status = ''
|
86
|
+
while !success
|
87
|
+
sleep 0.5
|
88
|
+
iterations += 1
|
89
|
+
raise CapacityAssignmentError.new("(Un)assignment did not succeed after #{timeout} seconds. Status history:#{status_history}") if iterations > (2 * timeout)
|
90
|
+
new_status = @tenant.get("/groups/#{@id}/CapacityAssignmentStatus")[:status].to_s
|
91
|
+
success = (new_status == "CompletedSuccessfully")
|
92
|
+
if new_status != old_status
|
93
|
+
status_history += "\nStatus change after #{iterations/2}s: '#{old_status}' --> '#{new_status}'"
|
94
|
+
old_status = new_status
|
95
|
+
end
|
96
|
+
end
|
97
|
+
self.reload
|
98
|
+
end
|
99
|
+
|
64
100
|
end
|
65
101
|
|
66
102
|
class WorkspaceArray < Array
|
data/lib/power-bi.rb
CHANGED
@@ -23,4 +23,5 @@ require_relative "power-bi/refresh"
|
|
23
23
|
require_relative "power-bi/gateway"
|
24
24
|
require_relative "power-bi/gateway_datasource"
|
25
25
|
require_relative "power-bi/page"
|
26
|
-
require_relative "power-bi/user"
|
26
|
+
require_relative "power-bi/user"
|
27
|
+
require_relative "power-bi/capacity"
|
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: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lode Cools
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- README.md
|
91
91
|
- lib/power-bi.rb
|
92
92
|
- lib/power-bi/array.rb
|
93
|
+
- lib/power-bi/capacity.rb
|
93
94
|
- lib/power-bi/dataset.rb
|
94
95
|
- lib/power-bi/datasource.rb
|
95
96
|
- lib/power-bi/gateway.rb
|
@@ -121,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
122
|
- !ruby/object:Gem::Version
|
122
123
|
version: '0'
|
123
124
|
requirements: []
|
124
|
-
rubygems_version: 3.
|
125
|
+
rubygems_version: 3.4.6
|
125
126
|
signing_key:
|
126
127
|
specification_version: 4
|
127
128
|
summary: Ruby wrapper for the Power BI API
|