lws 6.1.0.beta2 → 6.1.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +4 -4
- data/lib/lws.rb +4 -87
- data/lib/lws/{auth.rb → apps/auth.rb} +0 -0
- data/lib/lws/{corporate_website.rb → apps/corporate_website.rb} +0 -0
- data/lib/lws/{digital_signage.rb → apps/digital_signage.rb} +0 -0
- data/lib/lws/{generic.rb → apps/generic.rb} +0 -0
- data/lib/lws/{maps.rb → apps/maps.rb} +0 -0
- data/lib/lws/{presence.rb → apps/presence.rb} +0 -0
- data/lib/lws/{ticket.rb → apps/ticket.rb} +0 -0
- data/lib/lws/middleware.rb +15 -0
- data/lib/lws/middleware/http_logger.rb +53 -0
- data/lib/lws/middleware/json_logger.rb +36 -0
- data/lib/lws/middleware/json_parser.rb +46 -0
- data/lib/lws/middleware/request_headers.rb +35 -0
- data/lib/lws/version.rb +1 -1
- data/test/auth_test.rb +1 -1
- metadata +13 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ce4acf9c7e03325ea30484df6033d9629e5b529
|
4
|
+
data.tar.gz: f389cb4a66d55a2ac983009e14b8ae78e8f5429e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cda7314094b11b9f564c360ab04f358f5fad616004d81159caabdf072421d472053240523068d4c1c8692be1d108121807d343197d61acec0fdfc25bea9f7bfb
|
7
|
+
data.tar.gz: fda0ae24f5cd2383bcddda99555321a68d118e6bee0cc19694ee96ec6dafe28175f6032299e9e3b1680c7f28b2c2dd1c4d528c868df57327deddf7ff268212da
|
data/README.rdoc
CHANGED
@@ -23,9 +23,9 @@ would create a new +config/initializers/lws.rb+ file with these lines:
|
|
23
23
|
config.api_token = "…" # Get it from someplace
|
24
24
|
end
|
25
25
|
|
26
|
-
After that, due to the fact that LWS is based on
|
27
|
-
|
28
|
-
ORM's:
|
26
|
+
After that, due to the fact that LWS is based on
|
27
|
+
[Spyke](https://github.com/balvig/spyke), you can access the objects in the
|
28
|
+
LeftClick Web Services similary to many ActiveRecord-like ORM's:
|
29
29
|
|
30
30
|
map = Maps::Map.all.first
|
31
31
|
markers = map.markers
|
@@ -72,4 +72,4 @@ runtime determined API token as value, for example:
|
|
72
72
|
The +LC_LWS_ENV+ environment variable is supported to override the LWS
|
73
73
|
environment. Allowed values are "production" (default) and "development".
|
74
74
|
The +LC_LWS_API_TOKEN+ is supported to set the LWS API token default.
|
75
|
-
This only works if
|
75
|
+
This only works if a custom API token middleware is not used.
|
data/lib/lws.rb
CHANGED
@@ -16,6 +16,7 @@ require "spyke"
|
|
16
16
|
require "pp"
|
17
17
|
require "webmock"
|
18
18
|
|
19
|
+
require "lws/middleware"
|
19
20
|
require "lws/stubbing"
|
20
21
|
require "lws/version"
|
21
22
|
|
@@ -29,97 +30,13 @@ WebMock.disable!
|
|
29
30
|
# libraries.
|
30
31
|
module LWS
|
31
32
|
|
33
|
+
include Middleware
|
34
|
+
|
32
35
|
# The list of supported apps (web service libraries) loaded by
|
33
36
|
# {.setup}.
|
34
37
|
SUPPORTED_APPS = [:generic, :auth, :corporate_website, :digital_signage,
|
35
38
|
:maps, :presence, :ticket]
|
36
39
|
|
37
|
-
# @private
|
38
|
-
# @!visibility private
|
39
|
-
class JSONParser < Faraday::Response::Middleware
|
40
|
-
def parse(body)
|
41
|
-
data = MultiJson.load(body, symbolize_keys: true)
|
42
|
-
metadata = data.delete(:metadata)
|
43
|
-
errors = data.delete(:errors)
|
44
|
-
|
45
|
-
# If there are errors, discard the data.
|
46
|
-
data = nil if errors.present?
|
47
|
-
|
48
|
-
{ data: data,
|
49
|
-
metadata: metadata,
|
50
|
-
errors: errors }
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# @private
|
55
|
-
# @!visibility private
|
56
|
-
class HTTPLogger < Faraday::Response::Middleware
|
57
|
-
|
58
|
-
def initialize(app, logger, show_headers)
|
59
|
-
raise "cannot log HTTP requests without a logger" if logger.nil?
|
60
|
-
@logger = logger
|
61
|
-
@show_headers = show_headers
|
62
|
-
super(app)
|
63
|
-
end
|
64
|
-
|
65
|
-
def call(env)
|
66
|
-
@logger.debug ">>> #{env[:method].upcase} #{env[:url].to_s}"
|
67
|
-
if @show_headers
|
68
|
-
env[:request_headers].each do |hdr, val|
|
69
|
-
@logger.debug " #{hdr}: #{val}"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
@logger.debug ">>> #{env[:body] || "nil"}"
|
73
|
-
super
|
74
|
-
end
|
75
|
-
|
76
|
-
def on_complete(env)
|
77
|
-
super
|
78
|
-
@logger.debug "<<< HTTP #{env[:status].to_s}"
|
79
|
-
if @show_headers
|
80
|
-
env[:response_headers].each do |hdr, val|
|
81
|
-
@logger.debug " #{hdr}: #{val}"
|
82
|
-
end
|
83
|
-
end
|
84
|
-
@logger.debug "<<< #{env[:body] || "nil"}"
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
# @private
|
90
|
-
# @!visibility private
|
91
|
-
class JSONLogger < Faraday::Response::Middleware
|
92
|
-
|
93
|
-
def initialize(app, logger)
|
94
|
-
raise "cannot log JSON data without a logger" if logger.nil?
|
95
|
-
@logger = logger
|
96
|
-
super(app)
|
97
|
-
end
|
98
|
-
|
99
|
-
def on_complete(env)
|
100
|
-
dump = JSON.pretty_generate(env[:body])
|
101
|
-
dump.split("\n").each { |line| @logger.debug "||| #{line}" }
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
105
|
-
|
106
|
-
# @private
|
107
|
-
# @!visibility private
|
108
|
-
class RequestHeaders < Faraday::Middleware
|
109
|
-
|
110
|
-
def initialize(app, token)
|
111
|
-
super(app)
|
112
|
-
@token = token
|
113
|
-
end
|
114
|
-
|
115
|
-
def call(env)
|
116
|
-
env[:request_headers]["X-Token"] = @token if @token
|
117
|
-
env[:request_headers]["Accept"] = "application/json"
|
118
|
-
@app.call(env)
|
119
|
-
end
|
120
|
-
|
121
|
-
end
|
122
|
-
|
123
40
|
# @return [Config] the API configuration for the web services
|
124
41
|
mattr_reader :config
|
125
42
|
|
@@ -267,7 +184,7 @@ module LWS
|
|
267
184
|
@app_modules = {}
|
268
185
|
app_module_path = File.dirname(__FILE__)
|
269
186
|
SUPPORTED_APPS.each do |app_name|
|
270
|
-
load "#{app_module_path}/lws/#{app_name}.rb"
|
187
|
+
load "#{app_module_path}/lws/apps/#{app_name}.rb"
|
271
188
|
@app_modules[app_name] = LWS.const_get(app_name.to_s.camelize)
|
272
189
|
end
|
273
190
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#
|
2
|
+
# Copyright © 2016 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: Geldropseweg 8B, 5731 SG Mierlo, The
|
9
|
+
# Netherlands, info@leftclick.eu, +31492-782120.
|
10
|
+
|
11
|
+
|
12
|
+
require "lws/middleware/http_logger"
|
13
|
+
require "lws/middleware/json_logger"
|
14
|
+
require "lws/middleware/json_parser"
|
15
|
+
require "lws/middleware/request_headers"
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#
|
2
|
+
# Copyright © 2016 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: Geldropseweg 8B, 5731 SG Mierlo, The
|
9
|
+
# Netherlands, info@leftclick.eu, +31492-782120.
|
10
|
+
|
11
|
+
|
12
|
+
module LWS
|
13
|
+
|
14
|
+
module Middleware
|
15
|
+
|
16
|
+
# @private
|
17
|
+
# @!visibility private
|
18
|
+
class HTTPLogger < Faraday::Response::Middleware
|
19
|
+
|
20
|
+
def initialize(app, logger, show_headers)
|
21
|
+
raise "cannot log HTTP requests without a logger" if logger.nil?
|
22
|
+
@logger = logger
|
23
|
+
@show_headers = show_headers
|
24
|
+
super(app)
|
25
|
+
end
|
26
|
+
|
27
|
+
def call(env)
|
28
|
+
@logger.debug ">>> #{env[:method].upcase} #{env[:url].to_s}"
|
29
|
+
if @show_headers
|
30
|
+
env[:request_headers].each do |hdr, val|
|
31
|
+
@logger.debug " #{hdr}: #{val}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
@logger.debug ">>> #{env[:body] || "nil"}"
|
35
|
+
super
|
36
|
+
end
|
37
|
+
|
38
|
+
def on_complete(env)
|
39
|
+
super
|
40
|
+
@logger.debug "<<< HTTP #{env[:status].to_s}"
|
41
|
+
if @show_headers
|
42
|
+
env[:response_headers].each do |hdr, val|
|
43
|
+
@logger.debug " #{hdr}: #{val}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
@logger.debug "<<< #{env[:body] || "nil"}"
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#
|
2
|
+
# Copyright © 2016 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: Geldropseweg 8B, 5731 SG Mierlo, The
|
9
|
+
# Netherlands, info@leftclick.eu, +31492-782120.
|
10
|
+
|
11
|
+
|
12
|
+
module LWS
|
13
|
+
|
14
|
+
module Middleware
|
15
|
+
|
16
|
+
# @private
|
17
|
+
# @!visibility private
|
18
|
+
class JSONLogger < Faraday::Response::Middleware
|
19
|
+
|
20
|
+
def initialize(app, logger)
|
21
|
+
raise "cannot log JSON data without a logger" if logger.nil?
|
22
|
+
@logger = logger
|
23
|
+
super(app)
|
24
|
+
end
|
25
|
+
|
26
|
+
def on_complete(env)
|
27
|
+
return if env[:body].blank?
|
28
|
+
dump = JSON.pretty_generate(env[:body])
|
29
|
+
dump.split("\n").each { |line| @logger.debug "||| #{line}" }
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#
|
2
|
+
# Copyright © 2016 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: Geldropseweg 8B, 5731 SG Mierlo, The
|
9
|
+
# Netherlands, info@leftclick.eu, +31492-782120.
|
10
|
+
|
11
|
+
|
12
|
+
module LWS
|
13
|
+
|
14
|
+
module Middleware
|
15
|
+
|
16
|
+
# @private
|
17
|
+
# @!visibility private
|
18
|
+
class JSONParser < Faraday::Response::Middleware
|
19
|
+
|
20
|
+
def parse(body)
|
21
|
+
data = MultiJson.load(body, symbolize_keys: true)
|
22
|
+
metadata = data.delete(:metadata)
|
23
|
+
errors = data.delete(:errors)
|
24
|
+
|
25
|
+
# If there are errors, discard the data.
|
26
|
+
data = nil if errors.present?
|
27
|
+
|
28
|
+
{ data: data,
|
29
|
+
metadata: metadata,
|
30
|
+
errors: errors }
|
31
|
+
end
|
32
|
+
|
33
|
+
def on_complete(env)
|
34
|
+
env[:body] = case env[:status]
|
35
|
+
when 204, 304
|
36
|
+
parse('{}')
|
37
|
+
else
|
38
|
+
parse(env[:body])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#
|
2
|
+
# Copyright © 2016 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: Geldropseweg 8B, 5731 SG Mierlo, The
|
9
|
+
# Netherlands, info@leftclick.eu, +31492-782120.
|
10
|
+
|
11
|
+
|
12
|
+
module LWS
|
13
|
+
|
14
|
+
module Middleware
|
15
|
+
|
16
|
+
# @private
|
17
|
+
# @!visibility private
|
18
|
+
class RequestHeaders < Faraday::Middleware
|
19
|
+
|
20
|
+
def initialize(app, token)
|
21
|
+
super(app)
|
22
|
+
@token = token
|
23
|
+
end
|
24
|
+
|
25
|
+
def call(env)
|
26
|
+
env[:request_headers]["X-Token"] = @token if @token
|
27
|
+
env[:request_headers]["Accept"] = "application/json"
|
28
|
+
@app.call(env)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/lib/lws/version.rb
CHANGED
data/test/auth_test.rb
CHANGED
@@ -156,7 +156,7 @@ class TestAuthToken < MiniTest::Test
|
|
156
156
|
end
|
157
157
|
|
158
158
|
def test_valid_associations
|
159
|
-
|
159
|
+
assert_instance_of(Account, @token.account)
|
160
160
|
if @token.user.present?
|
161
161
|
assert_instance_of(User, @token.user)
|
162
162
|
assert_equal(@token.user.account.id, @token.account.id)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.1.0.
|
4
|
+
version: 6.1.0.beta3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LeftClick B.V.
|
@@ -236,14 +236,19 @@ files:
|
|
236
236
|
- bin/lwsconsole
|
237
237
|
- copyright.txt
|
238
238
|
- lib/lws.rb
|
239
|
-
- lib/lws/auth.rb
|
240
|
-
- lib/lws/corporate_website.rb
|
241
|
-
- lib/lws/digital_signage.rb
|
242
|
-
- lib/lws/generic.rb
|
243
|
-
- lib/lws/maps.rb
|
244
|
-
- lib/lws/presence.rb
|
239
|
+
- lib/lws/apps/auth.rb
|
240
|
+
- lib/lws/apps/corporate_website.rb
|
241
|
+
- lib/lws/apps/digital_signage.rb
|
242
|
+
- lib/lws/apps/generic.rb
|
243
|
+
- lib/lws/apps/maps.rb
|
244
|
+
- lib/lws/apps/presence.rb
|
245
|
+
- lib/lws/apps/ticket.rb
|
246
|
+
- lib/lws/middleware.rb
|
247
|
+
- lib/lws/middleware/http_logger.rb
|
248
|
+
- lib/lws/middleware/json_logger.rb
|
249
|
+
- lib/lws/middleware/json_parser.rb
|
250
|
+
- lib/lws/middleware/request_headers.rb
|
245
251
|
- lib/lws/stubbing.rb
|
246
|
-
- lib/lws/ticket.rb
|
247
252
|
- lib/lws/version.rb
|
248
253
|
- lws.gemspec
|
249
254
|
- test/api_token_middleware_test.rb
|