lws 7.2.0 → 7.2.5

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: db2a5afb03078543a2c129a2eb447c9038032daba9b06ee4c7ce16e484fa356b
4
- data.tar.gz: 9bd4e6f9a94ac7e86ed1572617c99fd8330ce718516a847b9ef7aecc5d96380f
3
+ metadata.gz: d062091468c34f7dfcdefce30fc76940eac3f9350200029ca6474e63a3264314
4
+ data.tar.gz: 0a3669c523669251467f169ca2a70980fb3bcdb43fb0e86e26eb4ee1df5da2f5
5
5
  SHA512:
6
- metadata.gz: 34d875da7b9139b7115a15cc6b61ef7930956dae43858ff386da3738e8eedef3f9250f99fd0c62fb68a76725e9811fc9ab0ebd7c1c60847cf2d7a9479c1ef187
7
- data.tar.gz: 4f792cfef73be50479bd9dbf91814e66e46a2bc1612203eb40d91fded571fa1b5a57820c585560524a578a658faec0d151b462dfba33e297536d9484218ecc82
6
+ metadata.gz: 37b19c793a36fbc741e3b6242d31229dd394cc7f54e281acf6ad686d7bccf6d332b168bb65f54d9d5cdbe336dd7a16df65b440dca9bca570c2893c1ff11d3d94
7
+ data.tar.gz: 430f4a6cb0a4b0b5441edbb185fc840c5606caae8f258ae4c0272c609294ca49a31693e8aaea0d521f5cbb7d4b38ccafe1c487b032052e93acfd8b296a76fbcd
@@ -36,7 +36,7 @@ EOB
36
36
  @options[:debug] = debug
37
37
  end
38
38
  opts.on("-e", "--environment=ENV", "select the LWS environment (default: production)") do |env|
39
- @options[:environment] = env.to_sym
39
+ @options[:environment] = env
40
40
  end
41
41
  opts.on("-t", "--token=TOKEN", "the LWS API token necessary to gain access") do |token|
42
42
  @options[:token] = token
@@ -80,6 +80,7 @@ begin
80
80
  LWS.setup do |config|
81
81
  config.api_token = @options[:token] if @options[:token]
82
82
  config.endpoints = @endpoints
83
+ config.http_caching = true
83
84
  config.http_debug = @options[:debug]
84
85
  config.json_debug = @options[:debug]
85
86
  config.logger = logger
data/lib/lws.rb CHANGED
@@ -8,8 +8,8 @@
8
8
  # contact LeftClick B.V. at: Schootense Dreef 20A, 5708 HZ Helmond, The
9
9
  # Netherlands, info@leftclick.eu, +3185-4444-004.
10
10
 
11
-
12
11
  require "faraday_middleware"
12
+ require "faraday/http_cache"
13
13
  require "hashie"
14
14
  require "multi_json"
15
15
  require "spyke"
@@ -80,7 +80,7 @@ module LWS
80
80
 
81
81
  # Override the environment if needed
82
82
  if ENV["LC_LWS_ENV"].present?
83
- @@config.environment = ENV["LC_LWS_ENV"].to_sym
83
+ @@config.environment = ENV["LC_LWS_ENV"]
84
84
  end
85
85
 
86
86
  # Override the API token if needed (and no custom API token middleware
@@ -111,11 +111,17 @@ module LWS
111
111
  # @param api_url [String] The endpoint URL of the API
112
112
  # @return [Faraday::Connection] A Faraday connection that makes requests to the API
113
113
  def self.setup_api(api_url)
114
- api = Faraday.new(url: api_url) do |c|
114
+ api = Faraday.new(url: api_url, proxy: config.proxy) do |c|
115
115
  # Request
116
116
  if config.caching_object
117
117
  c.use FaradayMiddleware::Caching, config.caching_object
118
118
  end
119
+ if config.http_caching
120
+ logger = config.http_debug ? config.logger : nil
121
+ c.use Faraday::HttpCache, store: config.http_caching_object,
122
+ logger: logger,
123
+ shared_cache: false
124
+ end
119
125
  c.use RequestHeaders, config.api_token
120
126
  c.use config.api_token_middleware if config.api_token_middleware.present?
121
127
  c.request :json
@@ -14,18 +14,16 @@ module LWS::Auth
14
14
 
15
15
  # :nocov:
16
16
  unless defined? ENDPOINT
17
- # The API endpoint for the auth app
17
+ # @!method self.endpoint
18
+ # @return [String] the actual API endpoint used to reach the app
19
+
20
+ # The API endpoint environment mapping for the Auth app
18
21
  ENDPOINT = { production: "https://leftclick.cloud/" ,
19
22
  development: "https://dev.leftclick.cloud/" }
20
23
  end
21
24
  # :nocov:
22
25
 
23
- # @!visibility private
24
- class << self
25
- attr_accessor :api
26
- end
27
- @api = LWS.setup_api(LWS.config.endpoints[:auth] ||
28
- ENDPOINT[LWS.config.environment])
26
+ include LWS::Generic
29
27
 
30
28
  ### Generic classes
31
29
 
@@ -14,17 +14,16 @@ module LWS::CorporateWebsite
14
14
 
15
15
  # :nocov:
16
16
  unless defined? ENDPOINT
17
- # The API endpoint for the corporate website app
17
+ # @!method self.endpoint
18
+ # @return [String] the actual API endpoint used to reach the app
19
+
20
+ # The API endpoint environment mapping for the Corporate Website app
18
21
  ENDPOINT = { production: "https://www.leftclick.cloud/",
19
22
  development: "https://www-dev.leftclick.cloud/" }
20
23
  end
21
24
  # :nocov:
22
25
 
23
- # @!visibility private
24
- def self.api
25
- LWS.setup_api(LWS.config.endpoints[:corporate_website] ||
26
- ENDPOINT[LWS.config.environment])
27
- end
26
+ include LWS::Generic
28
27
 
29
28
  ### Generic classes
30
29
 
@@ -14,17 +14,16 @@ module LWS::DigitalSignage
14
14
 
15
15
  # :nocov:
16
16
  unless defined? ENDPOINT
17
- # The API endpoint for the digital signage app
17
+ # @!method self.endpoint
18
+ # @return [String] the actual endpoint used to reach the app
19
+
20
+ # The API endpoint environment mapping for the Digital Signage app
18
21
  ENDPOINT = { production: "https://cm.leftclick.cloud/" ,
19
22
  development: "https://cm-dev.leftclick.cloud/" }
20
23
  end
21
24
  # :nocov:
22
25
 
23
- # @!visibility private
24
- def self.api
25
- LWS.setup_api(LWS.config.endpoints[:digital_signage] ||
26
- ENDPOINT[LWS.config.environment])
27
- end
26
+ include LWS::Generic
28
27
 
29
28
  ### Generic classes
30
29
 
@@ -653,6 +652,12 @@ module LWS::DigitalSignage
653
652
  # of the layout element
654
653
  has_many :customizables, class_name: "LWS::DigitalSignage::Layout::Element::Customizable"
655
654
 
655
+ # @!attribute definition
656
+ # @note This attribute is only available if the token is of an account
657
+ # with sysadmin permissions
658
+ # @return [Hash] the (plugin) component definition of the layout element
659
+ attribute :definition
660
+
656
661
  # @!attribute index
657
662
  # @return [Integer, nil] the index of the element within the list of
658
663
  # layout elements of the associated layout version
@@ -768,8 +773,10 @@ module LWS::DigitalSignage
768
773
 
769
774
  # @!attribute archive_url
770
775
  # @note
771
- # To be able retrieve this, the token needs to be passed via +X-Token+
772
- # in the HTTP request headers!
776
+ # To be able retrieve the archive, the token needs to be passed via
777
+ # +X-Token+ in the HTTP request headers!
778
+ # @note This attribute is only available if the token is of an account
779
+ # with sysadmin permissions
773
780
  # @return [String, nil] the URL of the archive/layout pack of the layout
774
781
  # version (if accessible)
775
782
  attribute :archive_url
@@ -14,6 +14,26 @@
14
14
  # This module contains classes that are present in all applications.
15
15
  module LWS::Generic
16
16
 
17
+ def self.included(app_mod)
18
+ app_mod.module_eval do |mod|
19
+
20
+ # Set up the API using the configured or default endpoint for the current
21
+ # environment.
22
+ endpoints = mod.const_get(:ENDPOINT)
23
+ app_name = mod.name.demodulize.underscore.to_sym
24
+ @api = LWS.setup_api(LWS.config.endpoints[app_name] ||
25
+ endpoints[LWS.config.environment])
26
+
27
+ def self.api
28
+ @api
29
+ end
30
+
31
+ def self.endpoint
32
+ @api.url_prefix.to_s
33
+ end
34
+ end
35
+ end
36
+
17
37
  # = The generic model class
18
38
  #
19
39
  # This model forms the base for all LWS models.
@@ -157,7 +177,11 @@ module LWS::Generic
157
177
  # @return [Object, nil] the digged up value or +nil+
158
178
  def dig(*attrs)
159
179
  attr = attrs.shift
160
- value = send(attr)
180
+ value = begin
181
+ send(attr)
182
+ rescue NoMethodError
183
+ nil
184
+ end
161
185
  return nil if value.nil?
162
186
  return value if attrs.empty?
163
187
  raise TypeError, "#{value.class} does not have #dig method" unless value.respond_to? :dig
@@ -199,11 +223,13 @@ module LWS::Generic
199
223
  def self.use_api(api)
200
224
  config = LWS.config
201
225
 
202
- # A connection to Active Storage (with JSON request/response, but without
203
- # token authentication and caching).
204
- @as_connection = Faraday.new(url: api.url_prefix) do |c|
226
+ # An API connection to Active Storage (with JSON request/response, but
227
+ # without caching).
228
+ @as_connection = Faraday.new(url: api.url_prefix, proxy: config.proxy) do |c|
205
229
  # Request
206
230
  c.request :json
231
+ c.use LWS::Middleware::RequestHeaders, config.api_token
232
+ c.use config.api_token_middleware if config.api_token_middleware.present?
207
233
 
208
234
  # Response
209
235
  c.use LWS::JSONLogger, config.logger if config.json_debug
@@ -219,7 +245,7 @@ module LWS::Generic
219
245
 
220
246
  # A plain file connection to LWS (with token autnentication and caching but without
221
247
  # JSON request/response).
222
- @lws_connection = Faraday.new(url: api.url_prefix) do |c|
248
+ @lws_connection = Faraday.new(url: api.url_prefix, proxy: config.proxy) do |c|
223
249
  # Request
224
250
  if config.caching_object
225
251
  c.use FaradayMiddleware::Caching, config.caching_object
@@ -14,17 +14,16 @@ module LWS::Maps
14
14
 
15
15
  # :nocov:
16
16
  unless defined? ENDPOINT
17
- # The API endpoint for the map app
17
+ # @!method self.endpoint
18
+ # @return [String] the actual API endpoint used to reach the app
19
+
20
+ # The API endpoint environment mapping for the Maps app
18
21
  ENDPOINT = { production: "https://maps.leftclick.cloud/",
19
22
  development: "https://maps-dev.leftclick.cloud/" }
20
23
  end
21
24
  # :nocov:
22
25
 
23
- # @!visibility private
24
- def self.api
25
- LWS.setup_api(LWS.config.endpoints[:maps] ||
26
- ENDPOINT[LWS.config.environment])
27
- end
26
+ include LWS::Generic
28
27
 
29
28
  ### Generic classes
30
29
 
@@ -14,17 +14,16 @@ module LWS::Presence
14
14
 
15
15
  # :nocov:
16
16
  unless defined? ENDPOINT
17
- # The API endpoint for the presence app
17
+ # @!method self.endpoint
18
+ # @return [String] the actual API endpoint used to reach the app
19
+
20
+ # The API endpoint environment mapping for the Presence app
18
21
  ENDPOINT = { production: "https://presence.leftclick.cloud/",
19
22
  development: "https://presence-dev.leftclick.cloud/" }
20
23
  end
21
24
  # :nocov:
22
25
 
23
- # @!visibility private
24
- def self.api
25
- LWS.setup_api(LWS.config.endpoints[:presence] ||
26
- ENDPOINT[LWS.config.environment])
27
- end
26
+ include LWS::Generic
28
27
 
29
28
  ### Generic classes
30
29
 
@@ -84,7 +83,7 @@ module LWS::Presence
84
83
  attribute :title
85
84
 
86
85
  # @!attribute uuid
87
- # @return [String] the UUID of the location
86
+ # @return [String] the UUID of the appointment
88
87
  attribute :uuid
89
88
  end
90
89
 
@@ -174,11 +173,11 @@ module LWS::Presence
174
173
  attribute :checkin_status
175
174
 
176
175
  # @!attribute checkout_alter_status
177
- # @return ["available", "unavailable", "maintenance_cleaning",
178
- # "maintenance_technical", "permanent_available",
179
- # "permanent_unavailable", "permanent_maintenance_cleaning",
180
- # "permanent_maintenance_technical", nil] the status to set the
181
- # location to when someone checks out
176
+ # @return ["available", "maintenance_cleaning", "maintenance_technical",
177
+ # "reserved", "unavailable", "permanent_available",
178
+ # "permanent_maintenance_cleaning", "permanent_maintenance_technical",
179
+ # "permanent_reserved", "permanent_unavailable", nil] the status to set
180
+ # the location to when someone checks out
182
181
  attribute :checkout_alter_status
183
182
 
184
183
  # @!attribute checkout_location
@@ -216,6 +215,10 @@ module LWS::Presence
216
215
  # @return [String, nil] the URL of the image of the location
217
216
  attribute :image_url
218
217
 
218
+ # @!attribute import_ref
219
+ # @return [String, nil] reference of the location in the remote database
220
+ attribute :import_ref
221
+
219
222
  # @!attribute journals
220
223
  # @return [Array<Journal>] the journal (entries) associated with the location
221
224
  has_many :journals, class: "LWS::Presence::Journal"
@@ -285,10 +288,11 @@ module LWS::Presence
285
288
  has_many :readers
286
289
 
287
290
  # @!attribute status
288
- # @return ["available", "unavailable", "maintenance_cleaning",
289
- # "maintenance_technical", "permanent_available",
290
- # "permanent_unavailable", "permanent_maintenance_cleaning",
291
- # "permanent_maintenance_technical"] the status of the location
291
+ # @return ["available", "maintenance_cleaning",
292
+ # "maintenance_technical", "reserved", "unavailable",
293
+ # "permanent_available", "permanent_maintenance_cleaning",
294
+ # "permanent_maintenance_technical", "permanent_reserved",
295
+ # "permanent_unavailable" ] the status of the location
292
296
  attribute :status
293
297
 
294
298
  # @!attribute time_zone
@@ -503,8 +507,7 @@ module LWS::Presence
503
507
  attribute :extra_info
504
508
 
505
509
  # @!attribute import_ref
506
- # @return [String, nil] reference for storing the uid of the remote
507
- # database
510
+ # @return [String, nil] reference of the person in the remote database
508
511
  attribute :import_ref
509
512
 
510
513
  # @!attribute kind
@@ -14,17 +14,16 @@ module LWS::Resource
14
14
 
15
15
  # :nocov:
16
16
  unless defined? ENDPOINT
17
- # The API endpoint for the resource app
17
+ # @!method self.endpoint
18
+ # @return [String] the actual API endpoint used to reach the app
19
+
20
+ # The API endpoint environment mapping for the Resource app
18
21
  ENDPOINT = { production: "https://resource.leftclick.cloud/",
19
22
  development: "https://resource-dev.leftclick.cloud/" }
20
23
  end
21
24
  # :nocov:
22
25
 
23
- # @!visibility private
24
- def self.api
25
- LWS.setup_api(LWS.config.endpoints[:resource] ||
26
- ENDPOINT[LWS.config.environment])
27
- end
26
+ include LWS::Generic
28
27
 
29
28
  ### Generic classes
30
29
 
@@ -14,17 +14,16 @@ module LWS::Ticket
14
14
 
15
15
  # :nocov:
16
16
  unless defined? ENDPOINT
17
- # The API endpoint for the ticket app
17
+ # @!method self.endpoint
18
+ # @return [String] the actual API endpoint used to reach the app
19
+
20
+ # The API endpoint environment mapping for the Ticket app
18
21
  ENDPOINT = { production: "https://ticket.leftclick.cloud/",
19
22
  development: "https://ticket-dev.leftclick.cloud/" }
20
23
  end
21
24
  # :nocov:
22
25
 
23
- # @!visibility private
24
- def self.api
25
- LWS.setup_api(LWS.config.endpoints[:ticket] ||
26
- ENDPOINT[LWS.config.environment])
27
- end
26
+ include LWS::Generic
28
27
 
29
28
  ### Generic classes
30
29
 
@@ -8,7 +8,6 @@
8
8
  # contact LeftClick B.V. at: Schootense Dreef 20A, 5708 HZ Helmond, The
9
9
  # Netherlands, info@leftclick.eu, +3185-4444-004.
10
10
 
11
-
12
11
  module LWS
13
12
 
14
13
  # = The LWS API configuration class
@@ -20,7 +19,9 @@ module LWS
20
19
  # configured for the library to work properly!
21
20
  class Config < Hashie::Dash
22
21
  # The list of properties that can be set using a config file.
23
- VALID_FILE_PROPERTIES = [:api_token, :endpoints, :http_debug, :http_debug_headers, :json_debug]
22
+ VALID_FILE_PROPERTIES =
23
+ [:api_token, :endpoints, :environment, :http_debug, :http_debug_headers,
24
+ :json_debug, :proxy]
24
25
 
25
26
  #@!attribute api_token
26
27
  # @return [String, nil] the API token necessary to gain access
@@ -45,6 +46,15 @@ module LWS
45
46
  # (default: +:production+)
46
47
  property :environment, default: :production
47
48
 
49
+ #@!attribute http_caching
50
+ # @return [Boolean] whether HTTP caching is enabled
51
+ property :http_caching, default: false
52
+
53
+ #@!attribute http_caching_object
54
+ # @return [#read, #write, #delete] an object that caches results
55
+ # respecting HTTP expiration (instead of an in-memory hash)
56
+ property :http_caching_object, default: nil
57
+
48
58
  #@!attribute http_debug
49
59
  # @return [Boolean] whether to show HTTP debug messages (default: +false+)
50
60
  property :http_debug, default: false
@@ -67,13 +77,42 @@ module LWS
67
77
  # (Rails logger, Logger, etc.)
68
78
  property :logger
69
79
 
80
+ #@!attribute proxy
81
+ # When passing a Hash, it should at least contain +:uri+ as key with
82
+ # a String or URI as value and optionally the +:user+ and +:password+
83
+ # keys with appropriate values.
84
+ # @return [Hash, String, URI] the proxy configuration, either as URL or
85
+ # as a Hash
86
+ property :proxy
87
+
70
88
  #@!attribute stubbing
71
89
  # @return [String] the path to a directory with stubbing fixtures
72
90
  # (setting this enables the default stubs)
73
91
  property :stubbing
74
92
 
75
- # Supplements the configuration with settings from a config file.
93
+ # Sets the environment for the config.
94
+ #
95
+ # The provided environment can be a string in short and long format as well
96
+ # as a symbol.
97
+ #
98
+ # @param new_env [Symbol, String] the new environment to use
99
+ # @return [Symbol] the new environment
100
+ # @raise when an invalid environment is provided
101
+ def environment=(new_env)
102
+ real_env =
103
+ case new_env
104
+ when "prod", "production", :prod, :production
105
+ :production
106
+ when "dev", "development", :dev, :development
107
+ :development
108
+ else
109
+ raise "unsupported environment: #{new_env}"
110
+ end
111
+ self[:environment] = real_env
112
+ end
76
113
 
114
+ # Supplements the configuration with settings from a config file.
115
+ #
77
116
  # The configuration file has a section per environment that indicates
78
117
  # per property what to use if it is unset.
79
118
  #
@@ -91,9 +130,10 @@ module LWS
91
130
  # an environment key that selects the default environment (unless
92
131
  # overriden by the +LC_LWS_ENV+ environment variable).
93
132
  #
94
- # @example A elaborate configuration that sets the development environment as default, enables debugging and overrides an endpoint
133
+ # @example A elaborate configuration that sets the proxy and the development environment as default, enables debugging and overrides an endpoint
95
134
  # default:
96
135
  # environment: "development"
136
+ # proxy: "http://proxyserver:8080"
97
137
  #
98
138
  # production:
99
139
  # api_token: "my-prod-api-token"
@@ -114,12 +154,13 @@ module LWS
114
154
  def load_config_file(config_file, force_environment = nil)
115
155
  return false unless File.exist? config_file
116
156
  config_data = YAML.load_file(config_file)
117
- environment = force_environment ||
118
- ENV["LC_LWS_ENV"] ||
119
- config_data.dig("default", "environment") ||
120
- self.environment
121
- self.environment = environment.to_sym
122
- config = config_data[environment.to_s] || {}
157
+ default_config = config_data["default"] || {}
158
+
159
+ self.environment = force_environment ||
160
+ ENV["LC_LWS_ENV"] ||
161
+ config_data.dig("default", "environment") ||
162
+ self.environment
163
+ config = default_config.merge(config_data[self.environment.to_s] || {})
123
164
 
124
165
  config.each_pair do |key, value|
125
166
  unless VALID_FILE_PROPERTIES.include? key.to_sym
@@ -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.2.0".freeze
16
+ VERSION = "7.2.5".freeze
17
17
 
18
18
  end
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  default:
3
3
  environment: development
4
+ proxy: http://user:password@proxyserver:8080
4
5
 
5
6
  development:
6
7
  api_token: "dev-token"
@@ -0,0 +1,81 @@
1
+ #
2
+ # Copyright © 2016–2020 LeftClick B.V.
3
+ #
4
+ # This software is property of LeftClick B.V. and cannot be redistributed
5
+ # and/or modified without permission. The software or any of its parts
6
+ # cannot be used for any other purposes than the LeftClick services and
7
+ # only during a valid license subscription. For more information, please
8
+ # contact LeftClick B.V. at: Schootense Dreef 20A, 5708 HZ Helmond, The
9
+ # Netherlands, info@leftclick.eu, +3185-4444-004.
10
+
11
+
12
+ require "test_helper"
13
+
14
+ class TestHTTPCaching < MiniTest::Test
15
+
16
+ # Class used to check if data is read/written to or remove from the cache
17
+ class HTTPCacheTest
18
+
19
+ attr_reader :last_read_key
20
+ attr_reader :last_written_key, :last_written_value
21
+ attr_reader :last_deleted_key
22
+
23
+ def read(key)
24
+ @last_read_key = key
25
+ nil
26
+ end
27
+
28
+ def write(key, value)
29
+ @last_written_key = key
30
+ @last_written_value = value
31
+ nil
32
+ end
33
+
34
+ def delete(key)
35
+ @last_deleted_key = key
36
+ nil
37
+ end
38
+
39
+ end
40
+
41
+ def setup
42
+ @cache_mock = HTTPCacheTest.new
43
+
44
+ # Redo the LWS setup with an HTTP caching object
45
+ LWS.setup do |config|
46
+ config.api_token = ENV["LC_LWS_TEST_TOKEN"]
47
+ config.http_caching = true
48
+ config.http_caching_object = @cache_mock
49
+ if ENV["LC_LWS_TEST_DEBUG"].present?
50
+ config.http_debug = true
51
+ config.http_debug_headers = true
52
+ end
53
+ config.environment = :development
54
+ end
55
+ end
56
+
57
+ def teardown
58
+ # Restore the configuration
59
+ reconfigure
60
+ end
61
+
62
+ def test_working_cache
63
+ assert_nil(@cache_mock.last_read_key)
64
+ assert_nil(@cache_mock.last_written_key)
65
+ assert_nil(@cache_mock.last_written_value)
66
+ assert_nil(@cache_mock.last_deleted_key)
67
+
68
+ new_configuration = LWS::Auth::Configuration.create(key: "test", value: "some_value")
69
+ refute_nil(@cache_mock.last_deleted_key)
70
+
71
+ _configurations = LWS::Auth::Configuration.where(key: "test").to_a
72
+ refute_nil(@cache_mock.last_read_key)
73
+ assert_equal(@cache_mock.last_read_key, @cache_mock.last_written_key)
74
+ refute_nil(@cache_mock.last_written_value)
75
+
76
+ old_key = @cache_mock.last_deleted_key.dup
77
+ new_configuration.destroy
78
+ refute_equal(old_key, @cache_mock.last_deleted_key)
79
+ end
80
+
81
+ end
@@ -8,7 +8,6 @@
8
8
  # contact LeftClick B.V. at: Schootense Dreef 20A, 5708 HZ Helmond, The
9
9
  # Netherlands, info@leftclick.eu, +3185-4444-004.
10
10
 
11
-
12
11
  require "test_helper"
13
12
 
14
13
  class TestSetup < MiniTest::Test
@@ -47,6 +46,26 @@ class TestSetup < MiniTest::Test
47
46
  assert_equal("test-token", LWS.config.api_token)
48
47
  end
49
48
 
49
+ def test_environment_writer
50
+ LWS.config.environment = "prod"
51
+ assert_equal(:production, LWS.config.environment)
52
+ LWS.config.environment = "production"
53
+ assert_equal(:production, LWS.config.environment)
54
+ LWS.config.environment = :production
55
+ assert_equal(:production, LWS.config.environment)
56
+
57
+ LWS.config.environment = "dev"
58
+ assert_equal(:development, LWS.config.environment)
59
+ LWS.config.environment = "development"
60
+ assert_equal(:development, LWS.config.environment)
61
+ LWS.config.environment = :development
62
+ assert_equal(:development, LWS.config.environment)
63
+
64
+ assert_raises do
65
+ LWS.config.environment = "doesnotexist"
66
+ end
67
+ end
68
+
50
69
  def test_http_logging_without_logger
51
70
  reconfigure(logger: nil,
52
71
  http_debug: true,
@@ -112,6 +131,7 @@ class TestSetup < MiniTest::Test
112
131
  assert_equal(true, LWS.config.http_debug)
113
132
  assert_equal(true, LWS.config.http_debug_headers)
114
133
  assert_equal(true, LWS.config.json_debug)
134
+ assert_equal("http://user:password@proxyserver:8080", LWS.config.proxy)
115
135
 
116
136
  with_env("LC_LWS_ENV" => "production") do
117
137
  reconfigure do |config|
@@ -128,4 +148,29 @@ class TestSetup < MiniTest::Test
128
148
  assert_equal(:development, LWS.config.environment)
129
149
  end
130
150
 
151
+ def test_proxy
152
+ proxy_url = "http://user:password@proxyserver:8080"
153
+ reconfigure do |config|
154
+ config.proxy = proxy_url
155
+ end
156
+
157
+ assert_equal(proxy_url, LWS.config.proxy)
158
+ assert_equal("http://user:password@proxyserver:8080", LWS::Auth.api.proxy.uri.to_s)
159
+ assert_equal("user", LWS::Auth.api.proxy.user)
160
+ assert_equal("password", LWS::Auth.api.proxy.password)
161
+
162
+ proxy_options =
163
+ { uri: Addressable::URI.parse("http://proxyserver:8080"),
164
+ user: "user",
165
+ password: "password" }
166
+ reconfigure do |config|
167
+ config.proxy = proxy_options
168
+ end
169
+
170
+ assert_equal(proxy_options, LWS.config.proxy)
171
+ assert_equal("http://proxyserver:8080", LWS::Auth.api.proxy.uri.to_s)
172
+ assert_equal("user", LWS::Auth.api.proxy.user)
173
+ assert_equal("password", LWS::Auth.api.proxy.password)
174
+ end
175
+
131
176
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lws
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.2.0
4
+ version: 7.2.5
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-10-23 00:00:00.000000000 Z
11
+ date: 2021-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday-http-cache
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.2'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: faraday_middleware
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -19,7 +33,7 @@ dependencies:
19
33
  version: 0.10.0
20
34
  - - "<"
21
35
  - !ruby/object:Gem::Version
22
- version: '1.0'
36
+ version: '2.0'
23
37
  type: :runtime
24
38
  prerelease: false
25
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +43,7 @@ dependencies:
29
43
  version: 0.10.0
30
44
  - - "<"
31
45
  - !ruby/object:Gem::Version
32
- version: '1.0'
46
+ version: '2.0'
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: hashie
35
49
  requirement: !ruby/object:Gem::Requirement
@@ -126,14 +140,14 @@ dependencies:
126
140
  requirements:
127
141
  - - "~>"
128
142
  - !ruby/object:Gem::Version
129
- version: '1.16'
143
+ version: '2.1'
130
144
  type: :development
131
145
  prerelease: false
132
146
  version_requirements: !ruby/object:Gem::Requirement
133
147
  requirements:
134
148
  - - "~>"
135
149
  - !ruby/object:Gem::Version
136
- version: '1.16'
150
+ version: '2.1'
137
151
  - !ruby/object:Gem::Dependency
138
152
  name: minitest
139
153
  requirement: !ruby/object:Gem::Requirement
@@ -262,6 +276,7 @@ files:
262
276
  - test/fixtures/auth.yml
263
277
  - test/fixtures/permissions.yml
264
278
  - test/generic_test.rb
279
+ - test/http_caching_test.rb
265
280
  - test/json_parser_test.rb
266
281
  - test/logger_test.rb
267
282
  - test/maps_test.rb
@@ -295,6 +310,7 @@ signing_key:
295
310
  specification_version: 4
296
311
  summary: LeftClick web services library for Ruby
297
312
  test_files:
313
+ - test/http_caching_test.rb
298
314
  - test/generic_test.rb
299
315
  - test/caching_test.rb
300
316
  - test/api_token_middleware_test.rb