lws 7.0.2 → 7.0.4

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: 2baebac6cb99dc5b7106f8cb9eeff4953f623ed1c7a2465ef165e9bf48c0330a
4
- data.tar.gz: 58833b0704e57635dcf70f06391f45276723efadac02ed05106efb23ce82f70d
3
+ metadata.gz: cd64c620eb066a25ef746caf1dbd624ce627cf476b90d531b910cf5dda7c804f
4
+ data.tar.gz: 934a7a8a804eb74a7ed954b1db917531cab5dfc03cd5c2daa98846ca7c0aa4f3
5
5
  SHA512:
6
- metadata.gz: 1430d0b1e0927121be013e60191be69e41b3fcc8a388ac6f707d6c39471fcf540776cf82c674f50104fa200e0c43f28f7c6662b3e1787116205e8b5f04357d51
7
- data.tar.gz: 98e60f674fc4b39ab09805accb562f6080c87573930dff4c660f42b8ef0c806c44460fdc191aa6bad86636374cc7619cedbb84ae90fbfdcab2dfeb50f7d6c832
6
+ metadata.gz: 56945d4070e3f193ed6245371cb054a0f2526e25254d66c27c295f1bb466952fbd1d3d8424257f25d9d463458a4636343bbb972b18c1ac7a95e000b984dc7c9b
7
+ data.tar.gz: 2a6f40cd0b12ff0ce11f6009e38e162e16deafcf5b8db086e5b1632234ee087225f8d6f6d7c660c1e063e1d605242e404185bc2c538eab59f85d6a2295719bad
@@ -180,9 +180,11 @@ module LWS::Generic
180
180
  class Storage
181
181
  # @!visibility private
182
182
  def self.use_api(api)
183
- @connection = Faraday.new(url: api.url_prefix) do |c|
184
- config = LWS.config
183
+ config = LWS.config
185
184
 
185
+ # A connection to Active Storage (with JSON request/response, but without
186
+ # token authentication and caching).
187
+ @as_connection = Faraday.new(url: api.url_prefix) do |c|
186
188
  # Request
187
189
  c.request :json
188
190
 
@@ -197,6 +199,36 @@ module LWS::Generic
197
199
  c.adapter Faraday.default_adapter
198
200
  end
199
201
  end
202
+
203
+ # A plain file connection to LWS (with token autnentication and caching but without
204
+ # JSON request/response).
205
+ @lws_connection = Faraday.new(url: api.url_prefix) do |c|
206
+ # Request
207
+ if config.caching_object
208
+ c.use FaradayMiddleware::Caching, config.caching_object
209
+ end
210
+ c.use LWS::Middleware::RequestHeaders, config.api_token
211
+ c.use config.api_token_middleware if config.api_token_middleware.present?
212
+
213
+ # Response
214
+ c.use FaradayMiddleware::FollowRedirects, limit: 3
215
+ c.use LWS::HTTPLogger, config.logger, config.http_debug_headers if config.http_debug
216
+
217
+ # Adapter
218
+ if config.http_persistent
219
+ c.adapter :net_http_persistent
220
+ else
221
+ c.adapter Faraday.default_adapter
222
+ end
223
+ end
224
+ end
225
+
226
+ # (see .upload)
227
+ # @deprecated
228
+ # To have a consistent upload/download naming counterpart, this
229
+ # method has been deprecated. Use {.upload} instead.
230
+ def self.create(file_or_io, filename, content_type = "application/octet-stream")
231
+ upload(file_or_io, filename, content_type)
200
232
  end
201
233
 
202
234
  # Uploads a file (or IO object) to the storage of the app module.
@@ -208,7 +240,7 @@ module LWS::Generic
208
240
  # @param filename [String] the filename to use for the uploaded file/IO object
209
241
  # @param content_type [String] the content type of the uploaded file/IO object
210
242
  # @return [String, nil] the storage ID (if successful)
211
- def self.create(file_or_io, filename, content_type = "application/octet-stream")
243
+ def self.upload(file_or_io, filename, content_type = "application/octet-stream")
212
244
  return nil if file_or_io.closed?
213
245
 
214
246
  data = file_or_io.read
@@ -217,7 +249,7 @@ module LWS::Generic
217
249
  content_type: content_type,
218
250
  byte_size: data.length,
219
251
  checksum: checksum } }
220
- res = @connection.post do |req|
252
+ res = @as_connection.post do |req|
221
253
  req.url "rails/active_storage/direct_uploads"
222
254
  req.headers["Accept"] = "application/json"
223
255
  req.headers["Content-Type"] = "application/json"
@@ -226,7 +258,7 @@ module LWS::Generic
226
258
 
227
259
  if res.success?
228
260
  result = JSON.parse(res.body)
229
- res = @connection.put do |req|
261
+ res = @as_connection.put do |req|
230
262
  req.url result.dig("direct_upload", "url")
231
263
  result.dig("direct_upload", "headers").each do |hdr, val|
232
264
  req.headers[hdr] = val
@@ -240,6 +272,24 @@ module LWS::Generic
240
272
  nil
241
273
  end
242
274
  end
243
- end
244
275
 
276
+ # Downloads a file at the provided URL from the storage using the
277
+ # appropriate API tokens.
278
+ #
279
+ # This method can be used to download images/assets/etc. from LWS using
280
+ # URLs provided by attributes that end with +_url+.
281
+ # @param url [String] the URL to download the file from
282
+ # @return [String] the contents of the file
283
+ def self.download(url)
284
+ return nil if url.nil?
285
+
286
+ unless url.start_with? @lws_connection.url_prefix.to_s
287
+ raise ArgumentError,
288
+ "URL does not belong to this LWS app (endpoint: #{@lws_connection.url_prefix})"
289
+ end
290
+
291
+ res = @lws_connection.get(url)
292
+ res.body
293
+ end
294
+ end
245
295
  end
@@ -157,13 +157,24 @@ module LWS::Presence
157
157
  # @return [Array<Integer>] the IDs of the underlying locations of the location
158
158
  attribute :descendant_ids
159
159
 
160
+ # @!attribute image_storage_id
161
+ # @return [String, nil] the storage ID of the image of the location
162
+ attribute :image_storage_id
163
+
164
+ # @!attribute image_url
165
+ # @note
166
+ # To be able retrieve this, the token needs to be passed via +X-Token+
167
+ # in the HTTP request headers!
168
+ # @return [String, nil] the URL of the image of the location
169
+ attribute :image_url
170
+
160
171
  # @!attribute lat
161
172
  # @return [Float] the latitude of the location
162
173
  attribute :lat
163
174
 
164
175
  # @!attribute logoff_time
165
- # The format of the time is +HH:MM+ and should be interpreted in the time zone
166
- # of the location (see also {#time_zone}).
176
+ # The format of the time is +HH:MM+ and should be interpreted in the time zone
177
+ # of the location (see also {#time_zone}).
167
178
  # @return [String] the time everybody is automatically logged off
168
179
  attribute :logoff_time
169
180
 
@@ -238,6 +249,17 @@ module LWS::Presence
238
249
  use_api LWS::Presence.api
239
250
  uri "locations/:location_id/maps(/:id)"
240
251
 
252
+ # @!attribute image_storage_id
253
+ # @return [String, nil] the storage ID of the image of the map
254
+ attribute :image_storage_id
255
+
256
+ # @!attribute image_url
257
+ # @note
258
+ # To be able retrieve this, the token needs to be passed via +X-Token+
259
+ # in the HTTP request headers!
260
+ # @return [String, nil] the URL of the image of the map
261
+ attribute :image_url
262
+
241
263
  # @!attribute location
242
264
  # @return [Location] the location the map belongs to
243
265
  belongs_to :location
@@ -251,6 +273,9 @@ module LWS::Presence
251
273
  attribute :name
252
274
 
253
275
  # @!attribute picture_url
276
+ # @deprecated
277
+ # Unauthenticated retrieval of the picture will not longer be supported
278
+ # in upcoming releases of LWS. Use {#image_url} instead!
254
279
  # @return [String, nil] the URL of the picture of the map
255
280
  attribute :picture_url
256
281
 
@@ -359,6 +384,17 @@ module LWS::Presence
359
384
  # @return [Array<Appointment>] the appointments involving the person
360
385
  has_many :appointments
361
386
 
387
+ # @!attribute avatar_storage_id
388
+ # @return [String, nil] the storage ID of the avatar of the person
389
+ attribute :avatar_storage_id
390
+
391
+ # @!attribute avatar_url
392
+ # @note
393
+ # To be able retrieve this, the token needs to be passed via +X-Token+
394
+ # in the HTTP request headers!
395
+ # @return [String, nil] the URL of the avatar of the person
396
+ attribute :avatar_url
397
+
362
398
  # @!attribute company
363
399
  # @return [LWS::Auth::Company] the company the person belongs to
364
400
  belongs_to :company, class_name: "LWS::Auth::Company"
@@ -457,6 +493,9 @@ module LWS::Presence
457
493
  attribute :phone_mobile
458
494
 
459
495
  # @!attribute picture_url
496
+ # @deprecated
497
+ # Unauthenticated retrieval of the picture will not longer be supported
498
+ # in upcoming releases of LWS. Use {#avatar_url} instead!
460
499
  # @return [String, nil] the URL of the picture of the person
461
500
  attribute :picture_url
462
501
 
@@ -512,4 +551,9 @@ module LWS::Presence
512
551
  attribute :node
513
552
  end
514
553
 
554
+ # (see Generic::Storage)
555
+ class Storage < LWS::Generic::Storage
556
+ use_api LWS::Presence.api
557
+ end
558
+
515
559
  end
data/lib/lws/version.rb CHANGED
@@ -13,6 +13,6 @@ module LWS
13
13
 
14
14
  # The LWS library version.
15
15
  # @note The major and minor version parts match the LWS API version!
16
- VERSION = "7.0.2".freeze
16
+ VERSION = "7.0.4".freeze
17
17
 
18
18
  end
data/test/generic_test.rb CHANGED
@@ -128,15 +128,37 @@ end
128
128
  class TestGenericStorage < MiniTest::Test
129
129
 
130
130
  # Generic class needs to be accessed under some kind of app
131
- include LWS::Resource
131
+ include LWS::Presence
132
132
 
133
133
  def test_upload
134
134
  data = StringIO.new("some file contents\n")
135
+ refute_nil(Storage.upload(data, "test.txt", "text/plain"))
136
+
137
+ # Test the deprecated method (for now)
135
138
  refute_nil(Storage.create(data, "test.txt", "text/plain"))
136
139
 
137
140
  # Also test using the default HTTP adapter.
138
141
  reconfigure(http_persistent: false)
139
142
  data = StringIO.new("some more file contents\n")
140
- refute_nil(Storage.create(data, "test2.txt", "text/plain"))
143
+ refute_nil(Storage.upload(data, "test2.txt", "text/plain"))
144
+ end
145
+
146
+ def test_download
147
+ location = Location.find(1)
148
+ refute_nil(location.image_url)
149
+
150
+ data = Storage.download(location.image_url)
151
+ assert(data.size > 0)
152
+
153
+ assert_nil(Storage.download(nil))
154
+
155
+ assert_raises(ArgumentError) do
156
+ Storage.download("https://doesnot.exist.tld/some/file")
157
+ end
158
+
159
+ # Also test using the default HTTP adapter.
160
+ reconfigure(http_persistent: false)
161
+ data = Storage.download(location.image_url)
162
+ assert(data.size > 0)
141
163
  end
142
164
  end
data/test/test_helper.rb CHANGED
@@ -23,7 +23,7 @@ SimpleCov.at_exit do
23
23
  result.format!
24
24
  simplecov_test_suites = ['minitest']
25
25
  parallel_offset = ENV['PARALLEL_TEST_GROUPS'] ? ENV['PARALLEL_TEST_GROUPS'].to_i - 1 : 0
26
- minimum_coverage = 97
26
+ minimum_coverage = 95
27
27
  # Count the number of commas in the command name to figure out how many result groups were combined into this result
28
28
  if result.command_name.scan(/,/).size + 1 >= simplecov_test_suites.size + (parallel_offset * 2) # two parallel suites
29
29
  # We only want to enforce minimum coverage after all test suites finish
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lws
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.2
4
+ version: 7.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - LeftClick B.V.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-19 00:00:00.000000000 Z
11
+ date: 2020-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday_middleware
@@ -296,27 +296,27 @@ signing_key:
296
296
  specification_version: 4
297
297
  summary: LeftClick web services library for Ruby
298
298
  test_files:
299
- - test/fixtures/auth.yml
299
+ - test/presence_test.rb
300
300
  - test/fixtures/permissions.yml
301
- - test/json_parser_test.rb
302
- - test/test_helper.rb
303
- - test/setup_test.rb
304
- - test/auth_test.rb
301
+ - test/fixtures/auth.yml
302
+ - test/corporate_website_test.rb
303
+ - test/logger_test.rb
304
+ - test/support/with_env.rb
305
305
  - test/stubbing_test.rb
306
+ - test/ticket_test.rb
306
307
  - test/digital_signage_test.rb
307
- - test/api_token_middleware_test.rb
308
- - test/config/full.yml
308
+ - test/caching_test.rb
309
+ - test/auth_test.rb
310
+ - test/maps_test.rb
311
+ - test/json_parser_test.rb
312
+ - test/resource_test.rb
313
+ - test/config/endpoints.yml
309
314
  - test/config/switch_env.yml
310
315
  - test/config/invalid.yml
311
- - test/config/tokens.yml
312
316
  - test/config/empty.yml
313
- - test/config/endpoints.yml
314
- - test/maps_test.rb
315
- - test/logger_test.rb
316
- - test/ticket_test.rb
317
- - test/support/with_env.rb
318
- - test/caching_test.rb
319
- - test/presence_test.rb
320
- - test/corporate_website_test.rb
321
- - test/resource_test.rb
317
+ - test/config/tokens.yml
318
+ - test/config/full.yml
319
+ - test/setup_test.rb
320
+ - test/api_token_middleware_test.rb
322
321
  - test/generic_test.rb
322
+ - test/test_helper.rb