power-bi 2.0.0 → 2.1.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 +12 -3
- data/lib/power-bi/capacity.rb +35 -0
- data/lib/power-bi/tenant.rb +7 -2
- 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: 349bd7851001e6e16d1d14f50f6abdbd473038ed3ec9665d5cd009a74db365f2
|
4
|
+
data.tar.gz: fe96607cd040b4fd034336865e7f78ceb35b297526242c4bc1f8ea3419dc95a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efc0967cf34f597d99b17a25272ba8546c9200d7e7d85ab8ffbf2ff36f99861560799cefa280f2efb787135bb4afd5bd6588fc3d147b867bd97794803d128637
|
7
|
+
data.tar.gz: eff9aeb3c7609cd54cf7d9888bb0b6ebc2cddc9cd9996e614d3dffdd8d61f77fc40480fa71baebbfc775044dedc0bd40cf83e36236c512d6808ff8ea3dcb293b
|
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,7 @@ 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')`
|
35
37
|
|
36
38
|
## Pages
|
37
39
|
|
@@ -65,6 +67,13 @@ Note 2: to limit the number of API calls, it is best to directly use the _getter
|
|
65
67
|
* Create a new gateway datasource: `gateway.gateway_datasource.create(name, credentials, db_server, db_name)`
|
66
68
|
* Delete a new gateway datasource: `gateway_datasource.delete`
|
67
69
|
|
70
|
+
## Capacities
|
71
|
+
|
72
|
+
Note: Capacities are Azure creatures, you can't create them in Power BI.
|
73
|
+
|
74
|
+
* List capacities: `pbi.capacities`
|
75
|
+
* Get a capacity: `pbi.capacity(id)`
|
76
|
+
|
68
77
|
# Note about gateway credentials
|
69
78
|
|
70
79
|
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/tenant.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
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,
|
@@ -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/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.1.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
|