power-bi 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/power-bi/tenant.rb +21 -2
  3. metadata +44 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '053216118d9fed6cb0cb3dff7a8bbe03c64be8a80f2cf26205a1c1b2ee48699c'
4
- data.tar.gz: 29908d4c0d9c2c988073f42c7b1180e21863a755ee14c68858016a0d74f437b3
3
+ metadata.gz: 7bb58d4ad66517c0ab6a5c3b1e84d7166fb6a9765e7d64d68553aa42b2248d22
4
+ data.tar.gz: 73feddb290710dd570f0882a80beb342f390ac60892c0d4cd3fb929e638c5fce
5
5
  SHA512:
6
- metadata.gz: b466f3f6b3d67701d40635ac0035b4a94d5aa9a1908152e2f32e244cbfe9f27f8c35f7978ec47bb2a3bccc7e681f14247d76128074c6a93006c2fc2b0c7f8438
7
- data.tar.gz: b43176b8de6c021e9c2529aafa9f137fab06877d320b26acc9ea0d7e7edfaee5d37a03d81dbf9f2672beae4399e25a24958aad94f39cecbaaf4d4ecf29edeb4f
6
+ metadata.gz: 4930595660692b8fa729cedd7f37b4ff204f958743f6373ee75ed05f54ce54f0b95913756623c6a583289cc4fd0b27c26898b228c46d915c9efe19e814295676
7
+ data.tar.gz: e292be8cf4cfe313119626603c6aa694d1ea98a0e614e775efe068578b7646a64eedf48b63e9283559ce1dc6100023b930f511ec2f959f9fbd29d02d8ec9111c
@@ -2,10 +2,11 @@ module PowerBI
2
2
  class Tenant
3
3
  attr_reader :workspaces, :gateways
4
4
 
5
- def initialize(token_generator, retries: 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
+ @logger = logger
9
10
 
10
11
  ## WHY RETRIES? ##
11
12
  # 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 :-)
@@ -18,11 +19,18 @@ module PowerBI
18
19
  interval: 0.2,
19
20
  interval_randomness: 0,
20
21
  backoff_factor: 4,
21
- retry_block: -> (env, options, retries, exc) { puts "retrying...!! (@ #{Time.now.to_s}), exception: #{exc.to_s} ---- #{exc.message}" },
22
+ retry_block: -> (env, options, retries, exc) { self.log "retrying...!! exception: #{exc.to_s} ---- #{exc.message}, request URL: #{env.url}" },
22
23
  }
23
24
  end
24
25
 
26
+ def log(message, level: :info)
27
+ if @logger
28
+ @logger.send(level, message) # hence, the logger needs to implement the 'level' methods
29
+ end
30
+ end
31
+
25
32
  def get(url, params = {})
33
+ t0 = Time.now
26
34
  conn = Faraday.new do |f|
27
35
  f.request :retry, @retry_options
28
36
  end
@@ -35,12 +43,14 @@ module PowerBI
35
43
  unless [200, 202].include? response.status
36
44
  raise APIError.new("Error calling Power BI API (status #{response.status}): #{response.body}")
37
45
  end
46
+ log "Calling (GET) #{url} - took #{((Time.now - t0) * 1000).to_i} ms"
38
47
  unless response.body.empty?
39
48
  JSON.parse(response.body, symbolize_names: true)
40
49
  end
41
50
  end
42
51
 
43
52
  def get_raw(url, params = {})
53
+ t0 = Time.now
44
54
  conn = Faraday.new do |f|
45
55
  f.request :retry, @retry_options
46
56
  end
@@ -49,6 +59,7 @@ module PowerBI
49
59
  req.headers['authorization'] = "Bearer #{token}"
50
60
  yield req if block_given?
51
61
  end
62
+ log "Calling (GET - raw) #{url} - took #{((Time.now - t0) * 1000).to_i} ms"
52
63
  unless [200, 202].include? response.status
53
64
  raise APIError.new("Error calling Power BI API (status #{response.status}): #{response.body}")
54
65
  end
@@ -56,6 +67,7 @@ module PowerBI
56
67
  end
57
68
 
58
69
  def post(url, params = {})
70
+ t0 = Time.now
59
71
  conn = Faraday.new do |f|
60
72
  f.request :retry, @retry_options
61
73
  end
@@ -66,6 +78,7 @@ module PowerBI
66
78
  req.headers['authorization'] = "Bearer #{token}"
67
79
  yield req if block_given?
68
80
  end
81
+ log "Calling (POST) #{url} - took #{((Time.now - t0) * 1000).to_i} ms"
69
82
  unless [200, 201, 202].include? response.status
70
83
  raise APIError.new("Error calling Power BI API (status #{response.status}): #{response.body}")
71
84
  end
@@ -75,6 +88,7 @@ module PowerBI
75
88
  end
76
89
 
77
90
  def patch(url, params = {})
91
+ t0 = Time.now
78
92
  conn = Faraday.new do |f|
79
93
  f.request :retry, @retry_options
80
94
  end
@@ -85,6 +99,7 @@ module PowerBI
85
99
  req.headers['authorization'] = "Bearer #{token}"
86
100
  yield req if block_given?
87
101
  end
102
+ log "Calling (PATCH) #{url} - took #{((Time.now - t0) * 1000).to_i} ms"
88
103
  unless [200, 202].include? response.status
89
104
  raise APIError.new("Error calling Power BI API (status #{response.status}): #{response.body}")
90
105
  end
@@ -94,6 +109,7 @@ module PowerBI
94
109
  end
95
110
 
96
111
  def delete(url, params = {})
112
+ t0 = Time.now
97
113
  conn = Faraday.new do |f|
98
114
  f.request :retry, @retry_options
99
115
  end
@@ -103,6 +119,7 @@ module PowerBI
103
119
  req.headers['authorization'] = "Bearer #{token}"
104
120
  yield req if block_given?
105
121
  end
122
+ log "Calling (DELETE) #{url} - took #{((Time.now - t0) * 1000).to_i} ms"
106
123
  unless [200, 202].include? response.status
107
124
  raise APIError.new("Error calling Power BI API (status #{response.status}): #{response.body}")
108
125
  end
@@ -112,6 +129,7 @@ module PowerBI
112
129
  end
113
130
 
114
131
  def post_file(url, file, params = {})
132
+ t0 = Time.now
115
133
  conn = Faraday.new do |f|
116
134
  f.request :multipart
117
135
  f.request :retry, @retry_options
@@ -124,6 +142,7 @@ module PowerBI
124
142
  req.body = {value: Faraday::UploadIO.new(file, 'application/octet-stream')}
125
143
  req.options.timeout = 120 # default is 60 seconds Net::ReadTimeout
126
144
  end
145
+ log "Calling (POST - file) #{url} - took #{((Time.now - t0) * 1000).to_i} ms"
127
146
  if response.status != 202
128
147
  raise APIError.new("Error calling Power BI API (status #{response.status}): #{response.body}")
129
148
  end
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.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lode Cools
@@ -38,6 +38,48 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: oauth2
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
41
83
  description: Ruby wrapper for the Power BI API
42
84
  email: lode.cools1@gmail.com
43
85
  executables: []
@@ -78,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
120
  - !ruby/object:Gem::Version
79
121
  version: '0'
80
122
  requirements: []
81
- rubygems_version: 3.1.4
123
+ rubygems_version: 3.1.6
82
124
  signing_key:
83
125
  specification_version: 4
84
126
  summary: Ruby wrapper for the Power BI API