lws 6.2.1 → 6.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/lws.rb +5 -1
- data/lib/lws/apps/generic.rb +51 -0
- data/lib/lws/apps/presence.rb +32 -2
- data/lib/lws/config.rb +4 -0
- data/lib/lws/version.rb +1 -1
- data/test/generic_test.rb +49 -8
- data/test/json_parser_test.rb +6 -3
- data/test/stubbing_test.rb +4 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b91a46e1cd07d2abdbe4d45e4d634725177bd993926e617a0eb0bf79b78a038
|
4
|
+
data.tar.gz: a5a570895842b2d7d7bfe6f40326a34b84c2d3a484668832588091d84ffb7b0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 214b724cd2c734cdb95e50be7b74d0cfbd5f8766a6cb3d665e17f21fa0202f80abddbe968d9f150583fd82e00c9a31ead72e5ff62e6aeb40539868d8b3ed0b38
|
7
|
+
data.tar.gz: 491e70649040f36afdb496accf6c0e41ed640649606d313a375d5b7cfc2cd8b967673d0752037e21bde5e92d7a411d6a367f692cea0ee76a7b1496ddfb353f0e
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,15 @@ Up until v6.1.0, we used the standard Gem version numbering starting at v0.0.1.
|
|
4
4
|
From v6.1.0 on the version will follow the API version of LWS in the major/minor
|
5
5
|
part of te version.
|
6
6
|
|
7
|
+
## v6.2.2
|
8
|
+
|
9
|
+
* Add some more attributes to the Presence app
|
10
|
+
* Use persistent HTTP connections from now on (#12101)
|
11
|
+
* Add a configuration option for enabling/disabling persistent HTTP
|
12
|
+
connections
|
13
|
+
* Add support for dirtiness checking for all models (#12100)
|
14
|
+
* Only save models using the HTTP if dirty
|
15
|
+
|
7
16
|
## v6.2.1
|
8
17
|
|
9
18
|
* Add new models and attributes to the Presence app (#12098, #12099)
|
data/lib/lws.rb
CHANGED
@@ -126,7 +126,11 @@ module LWS
|
|
126
126
|
c.use HTTPLogger, config.logger, config.http_debug_headers if config.http_debug
|
127
127
|
|
128
128
|
# Adapter
|
129
|
-
|
129
|
+
if config.http_persistent
|
130
|
+
c.adapter :net_http_persistent
|
131
|
+
else
|
132
|
+
c.adapter Faraday.default_adapter
|
133
|
+
end
|
130
134
|
end
|
131
135
|
|
132
136
|
return api
|
data/lib/lws/apps/generic.rb
CHANGED
@@ -18,6 +18,8 @@ module LWS::Generic
|
|
18
18
|
#
|
19
19
|
# This model forms the base for all LWS models.
|
20
20
|
class Model < Spyke::Base
|
21
|
+
include ActiveModel::Dirty
|
22
|
+
|
21
23
|
include_root_in_json true
|
22
24
|
|
23
25
|
# @private
|
@@ -50,7 +52,12 @@ module LWS::Generic
|
|
50
52
|
# @param [Symbol] name the name of the attribute to add
|
51
53
|
# @return [void]
|
52
54
|
def self.attribute(name)
|
55
|
+
define_attribute_methods(name)
|
53
56
|
attributes(name)
|
57
|
+
define_method(:"#{name}=") do |value|
|
58
|
+
send(:"#{name}_will_change!") unless value == attribute(name)
|
59
|
+
super(value)
|
60
|
+
end
|
54
61
|
end
|
55
62
|
|
56
63
|
# @private
|
@@ -79,6 +86,50 @@ module LWS::Generic
|
|
79
86
|
self.include_root_in_json self.name.split("::").last.underscore.to_sym
|
80
87
|
api
|
81
88
|
end
|
89
|
+
|
90
|
+
# @private
|
91
|
+
# @!visibility private
|
92
|
+
#
|
93
|
+
# Sets up the object/model and then clears any changes information as
|
94
|
+
# a result of loading and processing the JSON from LWS.
|
95
|
+
#
|
96
|
+
# return [Model] a new instance of the generic model
|
97
|
+
def initialize(*args)
|
98
|
+
super
|
99
|
+
clear_changes_information if persisted?
|
100
|
+
end
|
101
|
+
|
102
|
+
# Reloads the attributes of this model by retrieving it from LWS
|
103
|
+
# via HTTP.
|
104
|
+
#
|
105
|
+
# This also clears information about tracked changes to attribute
|
106
|
+
# values!
|
107
|
+
#
|
108
|
+
# @return [Hash] a mapping of retrieved attribute names to values
|
109
|
+
def reload
|
110
|
+
result = super
|
111
|
+
clear_changes_information if result
|
112
|
+
result
|
113
|
+
end
|
114
|
+
|
115
|
+
# Restore the attributes of this model to the previous (original) values.
|
116
|
+
#
|
117
|
+
# @return [Array<String>] list of attribute names that were rolled back
|
118
|
+
def rollback
|
119
|
+
restore_attributes
|
120
|
+
end
|
121
|
+
|
122
|
+
# Saves the model to LWS via HTTP if there are any changes.
|
123
|
+
#
|
124
|
+
# @return [Hash, Trueclass] a mapping of attributes names to values,
|
125
|
+
# or +true+ if no save action was necessary.
|
126
|
+
def save
|
127
|
+
return true unless changed?
|
128
|
+
result = super
|
129
|
+
changes_applied if result
|
130
|
+
result
|
131
|
+
end
|
132
|
+
|
82
133
|
end
|
83
134
|
|
84
135
|
# = The configuration class
|
data/lib/lws/apps/presence.rb
CHANGED
@@ -113,8 +113,8 @@ module LWS::Presence
|
|
113
113
|
attribute :long
|
114
114
|
|
115
115
|
# @!attribute map_positions
|
116
|
-
# @return [Array<Location::Map::Position>] the positions
|
117
|
-
# that
|
116
|
+
# @return [Array<Location::Map::Position>] the location map positions
|
117
|
+
# that track this location
|
118
118
|
has_many :map_positions, class_name: "LWS::Presence::Location::Map::Position"
|
119
119
|
|
120
120
|
# @attribute maps
|
@@ -295,6 +295,10 @@ module LWS::Presence
|
|
295
295
|
# @return [String, nil] the customer specific reference for the person
|
296
296
|
attribute :customer_reference
|
297
297
|
|
298
|
+
# @!attribute email
|
299
|
+
# @return [String, nil] the email address of the person
|
300
|
+
attribute :email
|
301
|
+
|
298
302
|
# @!attribute ero
|
299
303
|
# @return [Boolean] whether the person is emergency response
|
300
304
|
# ceritified
|
@@ -304,6 +308,10 @@ module LWS::Presence
|
|
304
308
|
# @return [String, nil] some extra info for the person
|
305
309
|
attribute :extra_info
|
306
310
|
|
311
|
+
# @!attribute import_ref
|
312
|
+
# @return [String, nil] reference for storing the uid of the remote database
|
313
|
+
attribute :import_ref
|
314
|
+
|
307
315
|
# @!attribute last_sync
|
308
316
|
# @return [String, nil] the last date/time the status was updated via a
|
309
317
|
# device or RFID tag
|
@@ -334,10 +342,28 @@ module LWS::Presence
|
|
334
342
|
# @return [String] the name of the person
|
335
343
|
attribute :name
|
336
344
|
|
345
|
+
# @!attribute phone_fixed
|
346
|
+
# @return [String] the fixed phonenumber of the person
|
347
|
+
attribute :phone_fixed
|
348
|
+
|
349
|
+
# @!attribute phone_mobile
|
350
|
+
# @return [String] the mobile phonenumber of the person
|
351
|
+
attribute :phone_moblie
|
352
|
+
|
353
|
+
# @!attribute phone_extension
|
354
|
+
# @return [String] the fixed phonenumber extension of the person
|
355
|
+
attribute :phone_extension
|
356
|
+
|
337
357
|
# @!attribute picture_url
|
338
358
|
# @return [String, nil] the URL of the picture of the person
|
339
359
|
attribute :picture_url
|
340
360
|
|
361
|
+
# @!attribute present
|
362
|
+
# @return [Boolean] if a person is present at a location. It looks
|
363
|
+
# at the state of a person so that local state checking is not
|
364
|
+
# needed.
|
365
|
+
attribute :present
|
366
|
+
|
341
367
|
# @!attribute rfid
|
342
368
|
# @return [String, nil] the RFID tag ID linked to the person
|
343
369
|
attribute :rfid
|
@@ -352,6 +378,10 @@ module LWS::Presence
|
|
352
378
|
# linked to the person
|
353
379
|
attribute :udid
|
354
380
|
|
381
|
+
# @!attribute vehicle_registration_plate
|
382
|
+
# @return [String, nil] The vehicle registration plate of the persons transport
|
383
|
+
attribute :vehicle_registration_plate
|
384
|
+
|
355
385
|
# @!attribute visibility
|
356
386
|
# @return ["public", "private"] if a person should be protected by not showing critical information
|
357
387
|
attribute :visibility
|
data/lib/lws/config.rb
CHANGED
@@ -54,6 +54,10 @@ module LWS
|
|
54
54
|
# (default: +false+)
|
55
55
|
property :http_debug_headers, default: false
|
56
56
|
|
57
|
+
#@!attribute http_persistent
|
58
|
+
# @return [Boolean] whether persistent HTTP connections are used
|
59
|
+
property :http_persistent, default: true
|
60
|
+
|
57
61
|
#@!attribute json_debug
|
58
62
|
# @return [Boolean] whether to show JSON debug messages (default: +false+)
|
59
63
|
property :json_debug, default: false
|
data/lib/lws/version.rb
CHANGED
data/test/generic_test.rb
CHANGED
@@ -11,21 +11,15 @@
|
|
11
11
|
|
12
12
|
require "test_helper"
|
13
13
|
|
14
|
-
class
|
14
|
+
class TestGenericModel < MiniTest::Test
|
15
15
|
|
16
|
-
# Generic
|
16
|
+
# Generic models needs to be accessed as under some kind of app
|
17
17
|
include LWS::Auth
|
18
18
|
|
19
19
|
def setup
|
20
20
|
@configuration = Configuration.all.first
|
21
21
|
end
|
22
22
|
|
23
|
-
def test_valid
|
24
|
-
refute_nil(@configuration)
|
25
|
-
assert_instance_of(Configuration, @configuration)
|
26
|
-
refute_nil(@configuration.id)
|
27
|
-
end
|
28
|
-
|
29
23
|
def test_her_compatibility
|
30
24
|
@configuration.assign_attributes("value" => "other_value")
|
31
25
|
assert_equal("other_value", @configuration.value)
|
@@ -58,4 +52,51 @@ class TestGenericConfiguration < MiniTest::Test
|
|
58
52
|
end
|
59
53
|
end
|
60
54
|
|
55
|
+
def test_dirty
|
56
|
+
# No changes for a just found instance
|
57
|
+
configuration = Configuration.find(@configuration.id)
|
58
|
+
refute(configuration.changed?)
|
59
|
+
assert_equal({}, configuration.changes)
|
60
|
+
|
61
|
+
# Changes when an attribute is changed
|
62
|
+
configuration.value = "other_value"
|
63
|
+
assert(configuration.changed?)
|
64
|
+
assert_equal({ "value" => ["test_value", "other_value"] },
|
65
|
+
configuration.changes)
|
66
|
+
|
67
|
+
# Changes reverted when rolled back
|
68
|
+
configuration.rollback
|
69
|
+
refute(configuration.changed?)
|
70
|
+
assert_equal({}, configuration.changes)
|
71
|
+
|
72
|
+
# Changes overwritten when reloaded
|
73
|
+
configuration.value = "other_value"
|
74
|
+
assert(configuration.changed?)
|
75
|
+
configuration.reload
|
76
|
+
refute(configuration.changed?)
|
77
|
+
assert_equal({}, configuration.changes)
|
78
|
+
|
79
|
+
# Not committed to the API if not changed
|
80
|
+
refute(configuration.changed?)
|
81
|
+
result = configuration.save
|
82
|
+
assert_equal(true, result)
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
class TestGenericConfiguration < MiniTest::Test
|
88
|
+
|
89
|
+
# Generic class needs to be accessed under some kind of app
|
90
|
+
include LWS::Auth
|
91
|
+
|
92
|
+
def setup
|
93
|
+
@configuration = Configuration.all.first
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_valid
|
97
|
+
refute_nil(@configuration)
|
98
|
+
assert_instance_of(Configuration, @configuration)
|
99
|
+
refute_nil(@configuration.id)
|
100
|
+
end
|
101
|
+
|
61
102
|
end
|
data/test/json_parser_test.rb
CHANGED
@@ -16,6 +16,8 @@ class TestJSONParser < MiniTest::Test
|
|
16
16
|
include WebMock::API
|
17
17
|
|
18
18
|
def setup
|
19
|
+
# Redo LWS setup with persistent HTTP connections disabled.
|
20
|
+
reconfigure(http_persistent: false)
|
19
21
|
WebMock.enable!
|
20
22
|
company = { id: "correct",
|
21
23
|
country: "NL",
|
@@ -31,7 +33,7 @@ class TestJSONParser < MiniTest::Test
|
|
31
33
|
stub_request(:get, full_uri.to_s)
|
32
34
|
.to_return(body: MultiJson.dump(company))
|
33
35
|
stub_request(:put, full_uri.to_s)
|
34
|
-
.to_return(body: MultiJson.dump(company.merge(errors: {
|
36
|
+
.to_return(body: MultiJson.dump(company.merge(errors: { contact_person_id: ["can't be blank"] })))
|
35
37
|
full_uri.path = "/companies"
|
36
38
|
stub_request(:post, full_uri.to_s)
|
37
39
|
.to_return(body: "", status: 204)
|
@@ -39,6 +41,7 @@ class TestJSONParser < MiniTest::Test
|
|
39
41
|
|
40
42
|
def teardown
|
41
43
|
WebMock.disable!
|
44
|
+
reconfigure
|
42
45
|
end
|
43
46
|
|
44
47
|
def test_broken_json
|
@@ -59,9 +62,9 @@ class TestJSONParser < MiniTest::Test
|
|
59
62
|
|
60
63
|
def test_correct_json_with_errors
|
61
64
|
company = LWS::Auth::Company.find("correct")
|
62
|
-
company.
|
65
|
+
company.contact_person_id = ""
|
63
66
|
company.save
|
64
|
-
assert_equal ["
|
67
|
+
assert_equal ["Contact person can't be blank"], company.errors.to_a
|
65
68
|
end
|
66
69
|
|
67
70
|
end
|
data/test/stubbing_test.rb
CHANGED
@@ -14,8 +14,10 @@ require "test_helper"
|
|
14
14
|
class TestStubbing < MiniTest::Test
|
15
15
|
|
16
16
|
def setup
|
17
|
-
# Redo
|
18
|
-
|
17
|
+
# Redo LWS setup with stubbing enabled and persistent HTTP connections
|
18
|
+
# disabled.
|
19
|
+
reconfigure(http_persistent: false,
|
20
|
+
stubbing: File.expand_path("../fixtures", __FILE__))
|
19
21
|
end
|
20
22
|
|
21
23
|
def teardown
|
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: 6.2.
|
4
|
+
version: 6.2.2
|
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: 2019-
|
11
|
+
date: 2019-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday_middleware
|