lws 6.1.0.beta3 → 6.1.0.beta4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/lwsconsole +61 -15
- data/lib/lws/config.rb +69 -0
- data/lib/lws/middleware.rb +9 -0
- data/lib/lws/stubbing.rb +19 -12
- data/lib/lws/version.rb +1 -1
- data/lib/lws.rb +4 -53
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b58d4f19b39cd31f8eb39c19252248889bbcdc1
|
4
|
+
data.tar.gz: fe5430ca9566e47fce0585eb7dc5e9f3e06d1406
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9b8964fe328533bd15bcc54aaa2e9f44239bafd204f00b56fbfc9e8ecc0050fecf14a1d6c4363f432d06074267e80689f4f40465ffa5be8ffdd8040a355cc39
|
7
|
+
data.tar.gz: 4f8664f672916043a6aac86cb7175f7e001c4df14537e0b2c345bd6f03306610184519afe7dc5ab5ca4f309eee8aca62c3f6a55b068f6c465e46b9063fde0009
|
data/bin/lwsconsole
CHANGED
@@ -2,23 +2,59 @@
|
|
2
2
|
#
|
3
3
|
# lwsconsole - A command-line tool to access the LWS web services
|
4
4
|
#
|
5
|
-
# Usage: lwsconsole <
|
5
|
+
# Usage: lwsconsole [<option>...] [<app>:<endpoint>...]
|
6
6
|
|
7
7
|
require "logger"
|
8
8
|
require "lws"
|
9
|
+
require "optparse"
|
9
10
|
require "pp"
|
10
11
|
require "pry"
|
11
12
|
|
12
13
|
# Parse the command-line arguments
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
PROG_NAME = File.basename($0)
|
15
|
+
@options = {}
|
16
|
+
opt_parser = OptionParser.new do |opts|
|
17
|
+
opts.banner = <<EOB
|
18
|
+
Usage: #{PROG_NAME} [OPTION]... [APP]:[ENDPOINT]...
|
19
|
+
A command-line tool to access the LWS web services.
|
20
|
+
|
21
|
+
EOB
|
22
|
+
|
23
|
+
opts.separator("Optional arguments:")
|
24
|
+
opts.on("-a", "--app=APP-NAME", "switch to a specific app") do |app|
|
25
|
+
@options[:app] = app
|
26
|
+
end
|
27
|
+
opts.on("-d", "--[no-]debug", "show HTTP and JSON debug information") do |debug|
|
28
|
+
@options[:debug] = debug
|
29
|
+
end
|
30
|
+
opts.on("-e", "--environment=ENV", "select the LWS environment (default: production)") do |env|
|
31
|
+
@options[:environment] = env.to_sym
|
32
|
+
end
|
33
|
+
opts.on("-t", "--token=TOKEN", "the LWS API token necessary to gain access") do |token|
|
34
|
+
@options[:token] = token
|
35
|
+
end
|
36
|
+
opts.on("--help", "display this help and exit") do
|
37
|
+
puts opts
|
38
|
+
exit
|
39
|
+
end
|
40
|
+
opts.on("--version", "display the LWS library version and exit") do
|
41
|
+
puts LWS::VERSION
|
42
|
+
exit
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
begin
|
47
|
+
opt_parser.parse!
|
48
|
+
rescue OptionParser::ParseError => e
|
49
|
+
puts "#{PROG_NAME}: #{e}"
|
50
|
+
puts opt_parser
|
51
|
+
exit 2
|
16
52
|
end
|
17
|
-
|
18
|
-
endpoints = {}
|
53
|
+
|
54
|
+
@endpoints = {}
|
19
55
|
ARGV.each do |app_endpoint|
|
20
56
|
app,endpoint = app_endpoint.split(':', 2)
|
21
|
-
endpoints[app.to_sym] = endpoint
|
57
|
+
@endpoints[app.to_sym] = endpoint
|
22
58
|
end
|
23
59
|
|
24
60
|
# Set up the logger
|
@@ -32,12 +68,22 @@ logger.formatter =
|
|
32
68
|
end
|
33
69
|
|
34
70
|
# Set up the API
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
71
|
+
begin
|
72
|
+
LWS.setup do |config|
|
73
|
+
config.api_token = @options[:token] if @options[:token]
|
74
|
+
config.environment = @options[:environment] if @options[:environment]
|
75
|
+
config.endpoints = @endpoints
|
76
|
+
config.http_debug = @options[:debug]
|
77
|
+
config.json_debug = @options[:debug]
|
78
|
+
config.logger = logger
|
79
|
+
end
|
80
|
+
if @options[:app]
|
81
|
+
@app_module = LWS.app_module(@options[:app].downcase)
|
82
|
+
puts "#{PROG_NAME}: Cannot find app `#{@options[:app]}', ignoring it!" unless @app_module
|
83
|
+
end
|
84
|
+
rescue => e
|
85
|
+
puts "#{PROG_NAME}: Problem during LWS setup: #{e}"
|
86
|
+
exit 3
|
41
87
|
end
|
42
88
|
|
43
89
|
### Extra commands/methods
|
@@ -68,5 +114,5 @@ def reload!
|
|
68
114
|
LWS.load_app_modules
|
69
115
|
end
|
70
116
|
|
71
|
-
# Use the LWS module as the default namespace
|
72
|
-
LWS.pry
|
117
|
+
# Use the LWS module or the selected app module as the default namespace
|
118
|
+
(@app_module || LWS).pry
|
data/lib/lws/config.rb
ADDED
@@ -0,0 +1,69 @@
|
|
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
|
+
# = The LWS API configuration class
|
15
|
+
#
|
16
|
+
# This class represents the configuration that is used for connecting to
|
17
|
+
# LWS.
|
18
|
+
#
|
19
|
+
# @note Either the API token or API token middleware needs to be
|
20
|
+
# configured for the library to work properly!
|
21
|
+
class Config < Hashie::Dash
|
22
|
+
#@!attribute api_token
|
23
|
+
# @return [String, nil] the API token necessary to gain access
|
24
|
+
property :api_token
|
25
|
+
|
26
|
+
#@!attribute api_token_middleware
|
27
|
+
# @return [Faraday::Middleware, nil] the API token middleware that
|
28
|
+
# provides the API token to the request at runtime
|
29
|
+
property :api_token_middleware
|
30
|
+
|
31
|
+
#@!attribute caching_object
|
32
|
+
# @return [#read, #write] an object that can cache request results
|
33
|
+
property :caching_object, default: nil
|
34
|
+
|
35
|
+
#@!attribute endpoints
|
36
|
+
# @return [Hash{Symbol=>String}] a mapping of application endpoint
|
37
|
+
# overrides (default: +{}+)
|
38
|
+
property :endpoints, default: {}
|
39
|
+
|
40
|
+
#@!attribute environment
|
41
|
+
# @return [Symbol] the (default) API environment
|
42
|
+
# (default: +:production+)
|
43
|
+
property :environment, default: :production
|
44
|
+
|
45
|
+
#@!attribute http_debug
|
46
|
+
# @return [Boolean] whether to show HTTP debug messages (default: +false+)
|
47
|
+
property :http_debug, default: false
|
48
|
+
|
49
|
+
#@!attribute http_debug_headers
|
50
|
+
# @return [Boolean] whether to show HTTP headers in the debug messages
|
51
|
+
# (default: +false+)
|
52
|
+
property :http_debug_headers, default: false
|
53
|
+
|
54
|
+
#@!attribute json_debug
|
55
|
+
# @return [Boolean] whether to show JSON debug messages (default: +false+)
|
56
|
+
property :json_debug, default: false
|
57
|
+
|
58
|
+
#@!attribute logger
|
59
|
+
# @return [#fatal, #error, #warn, #info, #debug] the logger object
|
60
|
+
# (Rails logger, Logger, etc.)
|
61
|
+
property :logger
|
62
|
+
|
63
|
+
#@!attribute stubbing
|
64
|
+
# @return [String] the path to a directory with stubbing fixtures
|
65
|
+
# (setting this enables the default stubs)
|
66
|
+
property :stubbing
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
data/lib/lws/middleware.rb
CHANGED
@@ -9,6 +9,15 @@
|
|
9
9
|
# Netherlands, info@leftclick.eu, +31492-782120.
|
10
10
|
|
11
11
|
|
12
|
+
module LWS
|
13
|
+
|
14
|
+
# @private
|
15
|
+
# @!visibility private
|
16
|
+
module Middleware
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
12
21
|
require "lws/middleware/http_logger"
|
13
22
|
require "lws/middleware/json_logger"
|
14
23
|
require "lws/middleware/json_parser"
|
data/lib/lws/stubbing.rb
CHANGED
@@ -11,19 +11,23 @@
|
|
11
11
|
|
12
12
|
module LWS
|
13
13
|
|
14
|
-
# =
|
14
|
+
# = The LWS API stubbing class
|
15
15
|
#
|
16
|
-
#
|
17
|
-
#
|
16
|
+
# This class regulates request stubbing based on a tree of fixtures.
|
17
|
+
# It can be used for testing an application that uses this library.
|
18
18
|
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
19
|
+
#
|
20
|
+
# These fixtures are defined in files that should have the following
|
21
|
+
# form:
|
22
|
+
#
|
23
|
+
# app_name:
|
24
|
+
# /model/1:
|
25
|
+
# default:
|
26
|
+
# id: 1
|
27
|
+
# attr: value
|
28
|
+
# test:
|
29
|
+
# id: 1
|
30
|
+
# attr: other_value
|
27
31
|
#
|
28
32
|
# When initialized, for all apps, for all paths, the default stub is
|
29
33
|
# loaded if it exists.
|
@@ -72,6 +76,7 @@ module LWS
|
|
72
76
|
# Disables all request stubbing.
|
73
77
|
#
|
74
78
|
# This should be used when the stubbing is not used anymore.
|
79
|
+
# @return [void]
|
75
80
|
def disable!
|
76
81
|
WebMock.disable!
|
77
82
|
end
|
@@ -82,13 +87,14 @@ module LWS
|
|
82
87
|
# @note For the HTTP method +:delete+, the response status is set to 204.
|
83
88
|
#
|
84
89
|
# @param method [Symbol] the HTTP method (+:get+, +:put+, etc.)
|
85
|
-
# @param app_name [Symbol] the app name (see {::SUPPORTED_APPS})
|
90
|
+
# @param app_name [Symbol] the app name (see {LWS::SUPPORTED_APPS})
|
86
91
|
# @param path [String] the path part of the request URI
|
87
92
|
# @param fixture_name [Symbol, nil] the name of the fixture to use as stub
|
88
93
|
# response body (or +nil+ for an empty fixture)
|
89
94
|
# @param http_status [Fixnum] the HTTP status code to use
|
90
95
|
# @raise if the fixture name could not be found for the given app name
|
91
96
|
# and path
|
97
|
+
# @return [void]
|
92
98
|
def replace(method, app_name, path, fixture_name = :default, http_status = 200)
|
93
99
|
fixture = if fixture_name
|
94
100
|
@fixtures.dig(app_name.to_s, path, fixture_name.to_s)
|
@@ -123,6 +129,7 @@ module LWS
|
|
123
129
|
# @param path [String] the path part of the request URI
|
124
130
|
# @raise if there is not request stub for the given HTTP method,
|
125
131
|
# app name and path
|
132
|
+
# @return [void]
|
126
133
|
def remove(method, app_name, path)
|
127
134
|
request_stub = @stubs.delete([method, app_name, path])
|
128
135
|
raise "no such request stub" unless request_stub
|
data/lib/lws/version.rb
CHANGED
data/lib/lws.rb
CHANGED
@@ -16,6 +16,7 @@ require "spyke"
|
|
16
16
|
require "pp"
|
17
17
|
require "webmock"
|
18
18
|
|
19
|
+
require "lws/config"
|
19
20
|
require "lws/middleware"
|
20
21
|
require "lws/stubbing"
|
21
22
|
require "lws/version"
|
@@ -43,56 +44,6 @@ module LWS
|
|
43
44
|
# @return [Stubbing] the stubbing setup for the web service
|
44
45
|
mattr_reader :stubbing
|
45
46
|
|
46
|
-
# = The API configuration class
|
47
|
-
#
|
48
|
-
# @note Either the API token or API token middleware needs to be
|
49
|
-
# configured for LWS to work properly!
|
50
|
-
class Config < Hashie::Dash
|
51
|
-
#@!attribute api_token
|
52
|
-
# @return [String, nil] the API token necessary to gain access
|
53
|
-
property :api_token
|
54
|
-
|
55
|
-
#@!attribute api_token_middleware
|
56
|
-
# @return [Faraday::Middleware, nil] the API token middleware that
|
57
|
-
# provides the API token to the request at runtime
|
58
|
-
property :api_token_middleware
|
59
|
-
|
60
|
-
#@!attribute caching_object
|
61
|
-
# @return [#read, #write] an object that can cache request results
|
62
|
-
property :caching_object, default: nil
|
63
|
-
|
64
|
-
#@!attribute endpoints
|
65
|
-
# @return [Hash{Symbol=>String}] a mapping of application endpoint
|
66
|
-
# overrides
|
67
|
-
property :endpoints, default: {}
|
68
|
-
|
69
|
-
#@!attribute environment
|
70
|
-
# @return [Symbol] the (default) API environment
|
71
|
-
property :environment, default: :production
|
72
|
-
|
73
|
-
#@!attribute http_debug
|
74
|
-
# @return [Boolean] whether to show HTTP debug messages
|
75
|
-
property :http_debug, default: false
|
76
|
-
|
77
|
-
#@!attribute http_debug_headers
|
78
|
-
# @return [Boolean] whether to show HTTP headers in the debug messages
|
79
|
-
property :http_debug_headers, default: false
|
80
|
-
|
81
|
-
#@!attribute json_debug
|
82
|
-
# @return [Boolean] whether to show JSON debug messages
|
83
|
-
property :json_debug, default: false
|
84
|
-
|
85
|
-
#@!attribute logger
|
86
|
-
# @return [#fatal, #error, #warn, #info, #debug] the logger object
|
87
|
-
# (Rails logger, Logger, etc.)
|
88
|
-
property :logger
|
89
|
-
|
90
|
-
#@!attribute stubbing
|
91
|
-
# @return [String] the path to a directory with stubbing fixtures
|
92
|
-
# (setting this enables the default stubs)
|
93
|
-
property :stubbing
|
94
|
-
end
|
95
|
-
|
96
47
|
# Sets up the application API libraries using the provided
|
97
48
|
# configuration (see {Config}).
|
98
49
|
#
|
@@ -104,9 +55,9 @@ module LWS
|
|
104
55
|
# config.logger = Rails.logger
|
105
56
|
# end
|
106
57
|
#
|
107
|
-
#
|
108
|
-
#
|
109
|
-
#
|
58
|
+
# The API token can be overridden using the +LC_LWS_API_TOKEN+
|
59
|
+
# environment variable. The LWS environment can be overriden using the
|
60
|
+
# +LC_LWS_ENV+ environment variable.
|
110
61
|
#
|
111
62
|
# @yieldparam [Config] config an API configuration object that can be
|
112
63
|
# configured
|
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.1.0.
|
4
|
+
version: 6.1.0.beta4
|
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: 2018-01-
|
11
|
+
date: 2018-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday_middleware
|
@@ -243,6 +243,7 @@ files:
|
|
243
243
|
- lib/lws/apps/maps.rb
|
244
244
|
- lib/lws/apps/presence.rb
|
245
245
|
- lib/lws/apps/ticket.rb
|
246
|
+
- lib/lws/config.rb
|
246
247
|
- lib/lws/middleware.rb
|
247
248
|
- lib/lws/middleware/http_logger.rb
|
248
249
|
- lib/lws/middleware/json_logger.rb
|