power-bi 1.1.0 → 1.5.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: 51692748675ef99ea93d0bec573cca8372d76af0ef0056d04a2d71e8e19bd33e
4
- data.tar.gz: 5c01631bac9bedd768445a0c3824c45ea2b020c47233f7862bf8d2b22f3c7a53
3
+ metadata.gz: '053216118d9fed6cb0cb3dff7a8bbe03c64be8a80f2cf26205a1c1b2ee48699c'
4
+ data.tar.gz: 29908d4c0d9c2c988073f42c7b1180e21863a755ee14c68858016a0d74f437b3
5
5
  SHA512:
6
- metadata.gz: 99d109e441b215576e0e8c04c7af685f3ff0ffb57bdbf3190b09530479d716dce4b3c134588a1bd059e59bfb5e1ddbb61bcd928de7537da27494f229426f0a8c
7
- data.tar.gz: c7a55c72ea6be93d8cdf531e8ad880f0bc34c646f98f6e425f36991aff9bfda323b1ff02f612e6f75598fe28d2073f073ae6e78cebb55dc72d9cdb5500857cd7
6
+ metadata.gz: b466f3f6b3d67701d40635ac0035b4a94d5aa9a1908152e2f32e244cbfe9f27f8c35f7978ec47bb2a3bccc7e681f14247d76128074c6a93006c2fc2b0c7f8438
7
+ data.tar.gz: b43176b8de6c021e9c2529aafa9f137fab06877d320b26acc9ea0d7e7edfaee5d37a03d81dbf9f2672beae4399e25a24958aad94f39cecbaaf4d4ecf29edeb4f
data/README.md CHANGED
@@ -27,6 +27,16 @@ pbi = PowerBI::Tenant.new(->{token = get_token(client, token) ; token.token})
27
27
  * Rebind report to another dataset: `report.rebind(dataset)`
28
28
  * Export report to file: `report.export_to_file(filenam, format: 'PDF')`
29
29
 
30
+ ## Pages
31
+
32
+ * List pages in a report: `report.pages`
33
+
34
+ ## Users
35
+
36
+ * List users in a workspace: `workspace.pages`
37
+ * Delete a user from a workspace: `user.delete`
38
+ * Add a user to a workspace: `workspace.create(email_address, access_right: "Viewer")`
39
+
30
40
  ## Datasets
31
41
 
32
42
  * List datasets in a workspace: `workspace.datasets`
data/lib/power-bi.rb CHANGED
@@ -20,3 +20,5 @@ require_relative "power-bi/parameter"
20
20
  require_relative "power-bi/refresh"
21
21
  require_relative "power-bi/gateway"
22
22
  require_relative "power-bi/gateway_datasource"
23
+ require_relative "power-bi/page"
24
+ require_relative "power-bi/user"
@@ -47,6 +47,7 @@ module PowerBI
47
47
 
48
48
  def delete
49
49
  @tenant.delete("/groups/#{workspace.id}/datasets/#{id}")
50
+ @workspace.datasets.reload
50
51
  true
51
52
  end
52
53
 
@@ -32,7 +32,7 @@ module PowerBI
32
32
 
33
33
  def delete
34
34
  @tenant.delete("/gateways/#{gateway.id}/datasources/#{id}")
35
- @tenant.workspaces.reload
35
+ @gateway.gateway_datasources.reload
36
36
  true
37
37
  end
38
38
 
@@ -0,0 +1,30 @@
1
+ module PowerBI
2
+ class Page
3
+ attr_reader :display_name, :name, :order, :report
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
11
+ end
12
+ end
13
+
14
+ class PageArray < Array
15
+
16
+ def initialize(tenant, report)
17
+ super(tenant)
18
+ @report = report
19
+ end
20
+
21
+ def self.get_class
22
+ Page
23
+ end
24
+
25
+ def get_data
26
+ data = @tenant.get("/groups/#{@report.workspace.id}/reports/#{@report.id}/pages")[:value]
27
+ data.each { |d| d[:report] = @report }
28
+ end
29
+ end
30
+ end
@@ -1,6 +1,6 @@
1
1
  module PowerBI
2
2
  class Report
3
- attr_reader :name, :id, :report_type, :web_url, :embed_url, :is_from_pbix, :is_owned_by_me, :dataset_id, :workspace
3
+ attr_reader :name, :id, :report_type, :web_url, :embed_url, :is_from_pbix, :is_owned_by_me, :dataset_id, :workspace, :pages
4
4
 
5
5
  class ExportToFileError < PowerBI::Error ; end
6
6
 
@@ -15,6 +15,7 @@ module PowerBI
15
15
  @dataset_id = data[:datasetId]
16
16
  @workspace = data[:workspace]
17
17
  @tenant = tenant
18
+ @pages = PageArray.new(@tenant, self)
18
19
  end
19
20
 
20
21
  def clone(target_workspace, new_report_name)
@@ -2,14 +2,31 @@ module PowerBI
2
2
  class Tenant
3
3
  attr_reader :workspaces, :gateways
4
4
 
5
- def initialize(token_generator)
5
+ def initialize(token_generator, retries: 5)
6
6
  @token_generator = token_generator
7
7
  @workspaces = WorkspaceArray.new(self)
8
8
  @gateways = GatewayArray.new(self)
9
+
10
+ ## WHY RETRIES? ##
11
+ # It is noticed that once in a while (~0.1% API calls), the Power BI server returns a 500 (internal server error) withou apparent reason, just retrying works :-)
12
+ ##################
13
+ @retry_options = {
14
+ max: retries,
15
+ exceptions: [Errno::ETIMEDOUT, Timeout::Error, Faraday::TimeoutError, Faraday::RetriableResponse],
16
+ methods: [:get, :post, :patch, :delete],
17
+ retry_statuses: [500], # internal server error
18
+ interval: 0.2,
19
+ interval_randomness: 0,
20
+ backoff_factor: 4,
21
+ retry_block: -> (env, options, retries, exc) { puts "retrying...!! (@ #{Time.now.to_s}), exception: #{exc.to_s} ---- #{exc.message}" },
22
+ }
9
23
  end
10
24
 
11
25
  def get(url, params = {})
12
- response = Faraday.get(PowerBI::BASE_URL + url) do |req|
26
+ conn = Faraday.new do |f|
27
+ f.request :retry, @retry_options
28
+ end
29
+ response = conn.get(PowerBI::BASE_URL + url) do |req|
13
30
  req.params = params
14
31
  req.headers['Accept'] = 'application/json'
15
32
  req.headers['authorization'] = "Bearer #{token}"
@@ -24,7 +41,10 @@ module PowerBI
24
41
  end
25
42
 
26
43
  def get_raw(url, params = {})
27
- response = Faraday.get(PowerBI::BASE_URL + url) do |req|
44
+ conn = Faraday.new do |f|
45
+ f.request :retry, @retry_options
46
+ end
47
+ response = conn.get(PowerBI::BASE_URL + url) do |req|
28
48
  req.params = params
29
49
  req.headers['authorization'] = "Bearer #{token}"
30
50
  yield req if block_given?
@@ -36,7 +56,10 @@ module PowerBI
36
56
  end
37
57
 
38
58
  def post(url, params = {})
39
- response = Faraday.post(PowerBI::BASE_URL + url) do |req|
59
+ conn = Faraday.new do |f|
60
+ f.request :retry, @retry_options
61
+ end
62
+ response = conn.post(PowerBI::BASE_URL + url) do |req|
40
63
  req.params = params
41
64
  req.headers['Accept'] = 'application/json'
42
65
  req.headers['Content-Type'] = 'application/json'
@@ -52,7 +75,10 @@ module PowerBI
52
75
  end
53
76
 
54
77
  def patch(url, params = {})
55
- response = Faraday.patch(PowerBI::BASE_URL + url) do |req|
78
+ conn = Faraday.new do |f|
79
+ f.request :retry, @retry_options
80
+ end
81
+ response = conn.patch(PowerBI::BASE_URL + url) do |req|
56
82
  req.params = params
57
83
  req.headers['Accept'] = 'application/json'
58
84
  req.headers['Content-Type'] = 'application/json'
@@ -68,7 +94,10 @@ module PowerBI
68
94
  end
69
95
 
70
96
  def delete(url, params = {})
71
- response = Faraday.delete(PowerBI::BASE_URL + url) do |req|
97
+ conn = Faraday.new do |f|
98
+ f.request :retry, @retry_options
99
+ end
100
+ response = conn.delete(PowerBI::BASE_URL + url) do |req|
72
101
  req.params = params
73
102
  req.headers['Accept'] = 'application/json'
74
103
  req.headers['authorization'] = "Bearer #{token}"
@@ -85,6 +114,7 @@ module PowerBI
85
114
  def post_file(url, file, params = {})
86
115
  conn = Faraday.new do |f|
87
116
  f.request :multipart
117
+ f.request :retry, @retry_options
88
118
  end
89
119
  response = conn.post(PowerBI::BASE_URL + url) do |req|
90
120
  req.params = params
@@ -92,6 +122,7 @@ module PowerBI
92
122
  req.headers['Content-Type'] = 'multipart/form-data'
93
123
  req.headers['authorization'] = "Bearer #{token}"
94
124
  req.body = {value: Faraday::UploadIO.new(file, 'application/octet-stream')}
125
+ req.options.timeout = 120 # default is 60 seconds Net::ReadTimeout
95
126
  end
96
127
  if response.status != 202
97
128
  raise APIError.new("Error calling Power BI API (status #{response.status}): #{response.body}")
@@ -0,0 +1,48 @@
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
13
+ end
14
+
15
+ def delete
16
+ @tenant.delete("/groups/#{@workspace.id}/users/#{@email_address}")
17
+ @workspace.users.reload
18
+ end
19
+
20
+ end
21
+
22
+ class UserArray < Array
23
+
24
+ def initialize(tenant, workspace)
25
+ super(tenant)
26
+ @workspace = workspace
27
+ end
28
+
29
+ def self.get_class
30
+ User
31
+ end
32
+
33
+ def create(email_address, access_right: "Viewer")
34
+ @tenant.post("/groups/#{@workspace.id}/users") do |req|
35
+ req.body = {
36
+ emailAddress: email_address,
37
+ groupUserAccessRight: access_right
38
+ }.to_json
39
+ end
40
+ self.reload
41
+ end
42
+
43
+ def get_data
44
+ data = @tenant.get("/groups/#{@workspace.id}/users")[:value]
45
+ data.each { |d| d[:workspace] = @workspace }
46
+ end
47
+ end
48
+ end
@@ -1,6 +1,6 @@
1
1
  module PowerBI
2
2
  class Workspace
3
- attr_reader :name, :is_read_only, :is_on_dedicated_capacity, :id, :reports, :datasets
3
+ attr_reader :name, :is_read_only, :is_on_dedicated_capacity, :id, :reports, :datasets, :users
4
4
 
5
5
  class UploadError < PowerBI::Error ; end
6
6
 
@@ -12,6 +12,7 @@ module PowerBI
12
12
  @tenant = tenant
13
13
  @reports = ReportArray.new(@tenant, self)
14
14
  @datasets = DatasetArray.new(@tenant, self)
15
+ @users = UserArray.new(@tenant, self)
15
16
  end
16
17
 
17
18
  def upload_pbix(file, dataset_name, timeout: 30)
@@ -43,17 +44,6 @@ module PowerBI
43
44
  true
44
45
  end
45
46
 
46
- # TODO LATER: the 'Viewer' acces right is currently not settable throught the API. Fix that later
47
- def add_user(email_address, access_right = 'Member')
48
- @tenant.post("/groups/#{id}/users") do |req|
49
- req.body = {
50
- emailAddress: email_address,
51
- groupUserAccessRight: access_right
52
- }.to_json
53
- end
54
- true
55
- end
56
-
57
47
  end
58
48
 
59
49
  class WorkspaceArray < Array
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.1.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lode Cools
@@ -52,10 +52,12 @@ files:
52
52
  - lib/power-bi/datasource.rb
53
53
  - lib/power-bi/gateway.rb
54
54
  - lib/power-bi/gateway_datasource.rb
55
+ - lib/power-bi/page.rb
55
56
  - lib/power-bi/parameter.rb
56
57
  - lib/power-bi/refresh.rb
57
58
  - lib/power-bi/report.rb
58
59
  - lib/power-bi/tenant.rb
60
+ - lib/power-bi/user.rb
59
61
  - lib/power-bi/workspace.rb
60
62
  homepage: https://github.com/piloos/power-bi
61
63
  licenses: