lws 0.1.4 → 0.1.5
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.
- data/README.rdoc +14 -3
- data/lib/lws/auth.rb +3 -1
- data/lib/lws/maps.rb +3 -1
- data/lib/lws/presence.rb +4 -1
- data/lib/lws/version.rb +1 -1
- data/lib/lws.rb +11 -8
- data/test/test_api_token_middleware.rb +61 -0
- metadata +17 -17
- data/test/test_proc_token.rb +0 -35
data/README.rdoc
CHANGED
@@ -36,13 +36,13 @@ ORM's:
|
|
36
36
|
|
37
37
|
loc = Presence::Location.where(name: "Test")
|
38
38
|
loc.destroy
|
39
|
-
|
39
|
+
|
40
40
|
== Configuration
|
41
41
|
|
42
42
|
The following example uses a much more elaborate setup:
|
43
43
|
|
44
44
|
LWS.setup do |config|
|
45
|
-
config.
|
45
|
+
config.api_token_middleware = TokenAuthenticator
|
46
46
|
config.caching_object = MyRedisCache.new
|
47
47
|
config.environment = :development
|
48
48
|
config.endponts = { maps: "https://maps.leftclick.eu" }
|
@@ -54,7 +54,18 @@ In this setup, a caching object is used that follows the
|
|
54
54
|
+FaradayMiddleWare::Caching+ API. It uses all development API endpoints,
|
55
55
|
except for maps, which is overriden to use the production endpoint. Also
|
56
56
|
HTTP request and JSON data debug logging is enabled.
|
57
|
-
Also
|
57
|
+
Also a custom API token authenticator class is used that should implement
|
58
|
+
the +Faraday::Middleware+ interface and set the +X-Token+ header with the
|
59
|
+
runtime determined API token as value, for example:
|
60
|
+
|
61
|
+
class TokenAuthenticator < Faraday::Middleware
|
62
|
+
|
63
|
+
def call(env)
|
64
|
+
env[:request_headers]["X-Token"] = … # Some calculated token
|
65
|
+
@app.call(env)
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
58
69
|
|
59
70
|
The +LC_LWS_ENV+ is supported to override the LWS environment.
|
60
71
|
Allowed values are "production" (default) and "development".
|
data/lib/lws/auth.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# = The auth app module
|
2
2
|
module LWS::Auth
|
3
3
|
|
4
|
-
# The API endpoint for the auth app
|
5
4
|
unless defined? ENDPOINT
|
5
|
+
# The API endpoint for the auth app
|
6
6
|
ENDPOINT = { production: "https://auth.leftclick.eu/" ,
|
7
7
|
development: "https://auth-dev.leftclick.eu/" }
|
8
8
|
end
|
@@ -15,10 +15,12 @@ module LWS::Auth
|
|
15
15
|
|
16
16
|
### Generic classes
|
17
17
|
|
18
|
+
# (see Generic::Configuration)
|
18
19
|
class Configuration < LWS::Generic::Configuration
|
19
20
|
use_api LWS::Auth.api
|
20
21
|
end
|
21
22
|
|
23
|
+
# (see Generic::Task)
|
22
24
|
class Task < LWS::Generic::Task
|
23
25
|
use_api LWS::Auth.api
|
24
26
|
end
|
data/lib/lws/maps.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# = The maps app module
|
2
2
|
module LWS::Maps
|
3
3
|
|
4
|
-
# The API endpoint for the map app
|
5
4
|
unless defined? ENDPOINT
|
5
|
+
# The API endpoint for the map app
|
6
6
|
ENDPOINT = { production: "https://maps.leftclick.eu/",
|
7
7
|
development: "https://maps-dev.leftclick.eu/" }
|
8
8
|
end
|
@@ -15,10 +15,12 @@ module LWS::Maps
|
|
15
15
|
|
16
16
|
### Generic classes
|
17
17
|
|
18
|
+
# (see Generic::Configuration)
|
18
19
|
class Configuration < LWS::Generic::Configuration
|
19
20
|
use_api LWS::Maps.api
|
20
21
|
end
|
21
22
|
|
23
|
+
# (see Generic::Task)
|
22
24
|
class Task < LWS::Generic::Task
|
23
25
|
use_api LWS::Maps.api
|
24
26
|
end
|
data/lib/lws/presence.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# = The presence app module
|
2
2
|
module LWS::Presence
|
3
3
|
|
4
|
-
# The API endpoint for the presence app
|
5
4
|
unless defined? ENDPOINT
|
5
|
+
# The API endpoint for the presence app
|
6
6
|
ENDPOINT = { production: "https://presence.leftclick.eu/",
|
7
7
|
development: "https://presence-dev.leftclick.eu/" }
|
8
8
|
end
|
@@ -15,10 +15,12 @@ module LWS::Presence
|
|
15
15
|
|
16
16
|
### Generic classes
|
17
17
|
|
18
|
+
# (see Generic::Configuration)
|
18
19
|
class Configuration < LWS::Generic::Configuration
|
19
20
|
use_api LWS::Presence.api
|
20
21
|
end
|
21
22
|
|
23
|
+
# (see Generic::Task)
|
22
24
|
class Task < LWS::Generic::Task
|
23
25
|
use_api LWS::Presence.api
|
24
26
|
end
|
@@ -70,6 +72,7 @@ module LWS::Presence
|
|
70
72
|
end
|
71
73
|
end
|
72
74
|
|
75
|
+
# = The person class
|
73
76
|
class Person < LWS::Generic::Model
|
74
77
|
use_api LWS::Presence.api
|
75
78
|
|
data/lib/lws/version.rb
CHANGED
data/lib/lws.rb
CHANGED
@@ -59,11 +59,7 @@ module LWS
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def call(env)
|
62
|
-
env[:request_headers]["X-Token"] = if @token
|
63
|
-
@token.call
|
64
|
-
else
|
65
|
-
@token
|
66
|
-
end.to_s
|
62
|
+
env[:request_headers]["X-Token"] = @token if @token
|
67
63
|
env[:request_headers]["Accept"] = "application/json"
|
68
64
|
@app.call(env)
|
69
65
|
end
|
@@ -76,10 +72,14 @@ module LWS
|
|
76
72
|
# = The API configuration class
|
77
73
|
class Config < Hashie::Dash
|
78
74
|
#@!attribute api_token
|
79
|
-
# @return [String,
|
80
|
-
# a proc block that returns it
|
75
|
+
# @return [String, nil] the API token necessary to gain access
|
81
76
|
property :api_token
|
82
77
|
|
78
|
+
#@!attribute api_token_middleware
|
79
|
+
# @return [Fardaday::Middleware, nil] the API token middleware that
|
80
|
+
# provides the API token to the request at runtime
|
81
|
+
property :api_token_middleware
|
82
|
+
|
83
83
|
#@!attribute caching_object
|
84
84
|
# @return [#read, #write] an object that can cache request results
|
85
85
|
property :caching_object, default: nil
|
@@ -120,7 +120,9 @@ module LWS
|
|
120
120
|
@@config = Config.new
|
121
121
|
yield @@config
|
122
122
|
|
123
|
-
|
123
|
+
if config.api_token.blank? and config.api_token_middleware.blank?
|
124
|
+
raise "API token or API token middleware is required"
|
125
|
+
end
|
124
126
|
|
125
127
|
# Override the environment if needed
|
126
128
|
if ENV["LC_LWS_ENV"].present?
|
@@ -141,6 +143,7 @@ module LWS
|
|
141
143
|
c.use FaradayMiddleware::Caching, config.caching_object
|
142
144
|
end
|
143
145
|
c.use RequestHeaders, config.api_token
|
146
|
+
c.use config.api_token_middleware if config.api_token_middleware.present?
|
144
147
|
c.use Faraday::Request::UrlEncoded
|
145
148
|
|
146
149
|
# Response
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class WorkingTokenAuthenticator < Faraday::Middleware
|
4
|
+
|
5
|
+
def call(env)
|
6
|
+
env[:request_headers]["X-Token"] = ENV["LC_LWS_TEST_TOKEN"]
|
7
|
+
@app.call(env)
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
class BrokenTokenAuthenticator < Faraday::Middleware
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
env[:request_headers]["X-Token"] = ""
|
16
|
+
@app.call(env)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
class TestAPITokenMiddleware < MiniTest::Unit::TestCase
|
22
|
+
|
23
|
+
def test_working_token_authenticator
|
24
|
+
LWS.setup do |config|
|
25
|
+
config.api_token = nil
|
26
|
+
config.api_token_middleware = WorkingTokenAuthenticator
|
27
|
+
if ENV["LC_LWS_TEST_DEBUG"].present?
|
28
|
+
config.http_debug = true
|
29
|
+
config.json_debug = true
|
30
|
+
end
|
31
|
+
config.environment = :development
|
32
|
+
end
|
33
|
+
|
34
|
+
task = LWS::Auth::Task.all.first
|
35
|
+
refute_nil(task)
|
36
|
+
|
37
|
+
# Restore the token
|
38
|
+
LWS.config.api_token = ENV["LC_LWS_TEST_TOKEN"]
|
39
|
+
LWS.config.api_token_middleware = nil
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_broken_token_authenticator
|
43
|
+
LWS.setup do |config|
|
44
|
+
config.api_token = nil
|
45
|
+
config.api_token_middleware = BrokenTokenAuthenticator
|
46
|
+
if ENV["LC_LWS_TEST_DEBUG"].present?
|
47
|
+
config.http_debug = true
|
48
|
+
config.json_debug = true
|
49
|
+
end
|
50
|
+
config.environment = :development
|
51
|
+
end
|
52
|
+
|
53
|
+
task = LWS::Auth::Task.all.first
|
54
|
+
assert_nil(task)
|
55
|
+
|
56
|
+
# Restore the token
|
57
|
+
LWS.config.api_token = ENV["LC_LWS_TEST_TOKEN"]
|
58
|
+
LWS.config.api_token_middleware = nil
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
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: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2016-03-09 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday_middleware
|
16
|
-
requirement: &
|
16
|
+
requirement: &14765880 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -24,10 +24,10 @@ dependencies:
|
|
24
24
|
version: '1.0'
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
|
-
version_requirements: *
|
27
|
+
version_requirements: *14765880
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: hashie
|
30
|
-
requirement: &
|
30
|
+
requirement: &14764980 !ruby/object:Gem::Requirement
|
31
31
|
none: false
|
32
32
|
requirements:
|
33
33
|
- - ! '>='
|
@@ -35,10 +35,10 @@ dependencies:
|
|
35
35
|
version: '0'
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
|
-
version_requirements: *
|
38
|
+
version_requirements: *14764980
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
40
|
name: her
|
41
|
-
requirement: &
|
41
|
+
requirement: &14764260 !ruby/object:Gem::Requirement
|
42
42
|
none: false
|
43
43
|
requirements:
|
44
44
|
- - ~>
|
@@ -46,10 +46,10 @@ dependencies:
|
|
46
46
|
version: 0.8.1
|
47
47
|
type: :runtime
|
48
48
|
prerelease: false
|
49
|
-
version_requirements: *
|
49
|
+
version_requirements: *14764260
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
51
|
name: hashie
|
52
|
-
requirement: &
|
52
|
+
requirement: &14763660 !ruby/object:Gem::Requirement
|
53
53
|
none: false
|
54
54
|
requirements:
|
55
55
|
- - ! '>='
|
@@ -57,10 +57,10 @@ dependencies:
|
|
57
57
|
version: '0'
|
58
58
|
type: :development
|
59
59
|
prerelease: false
|
60
|
-
version_requirements: *
|
60
|
+
version_requirements: *14763660
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: her
|
63
|
-
requirement: &
|
63
|
+
requirement: &14762960 !ruby/object:Gem::Requirement
|
64
64
|
none: false
|
65
65
|
requirements:
|
66
66
|
- - ~>
|
@@ -68,10 +68,10 @@ dependencies:
|
|
68
68
|
version: 0.8.1
|
69
69
|
type: :development
|
70
70
|
prerelease: false
|
71
|
-
version_requirements: *
|
71
|
+
version_requirements: *14762960
|
72
72
|
- !ruby/object:Gem::Dependency
|
73
73
|
name: minitest
|
74
|
-
requirement: &
|
74
|
+
requirement: &14762380 !ruby/object:Gem::Requirement
|
75
75
|
none: false
|
76
76
|
requirements:
|
77
77
|
- - ! '>='
|
@@ -79,10 +79,10 @@ dependencies:
|
|
79
79
|
version: '0'
|
80
80
|
type: :development
|
81
81
|
prerelease: false
|
82
|
-
version_requirements: *
|
82
|
+
version_requirements: *14762380
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rake
|
85
|
-
requirement: &
|
85
|
+
requirement: &14778140 !ruby/object:Gem::Requirement
|
86
86
|
none: false
|
87
87
|
requirements:
|
88
88
|
- - ~>
|
@@ -90,7 +90,7 @@ dependencies:
|
|
90
90
|
version: 0.9.2
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
|
-
version_requirements: *
|
93
|
+
version_requirements: *14778140
|
94
94
|
description: ! "This library for Ruby provides access to the LeftClick\n web services/applications
|
95
95
|
using a model-based structure that abstracts from API calls\n using the available
|
96
96
|
REST interfaces."
|
@@ -113,13 +113,13 @@ files:
|
|
113
113
|
- lib/lws/presence.rb
|
114
114
|
- lib/lws/version.rb
|
115
115
|
- lws.gemspec
|
116
|
+
- test/test_api_token_middleware.rb
|
116
117
|
- test/test_auth.rb
|
117
118
|
- test/test_caching.rb
|
118
119
|
- test/test_generic.rb
|
119
120
|
- test/test_helper.rb
|
120
121
|
- test/test_maps.rb
|
121
122
|
- test/test_presence.rb
|
122
|
-
- test/test_proc_token.rb
|
123
123
|
homepage: https://leftclick.eu/
|
124
124
|
licenses: []
|
125
125
|
post_install_message:
|
@@ -145,11 +145,11 @@ signing_key:
|
|
145
145
|
specification_version: 3
|
146
146
|
summary: LeftClick web services library for Ruby
|
147
147
|
test_files:
|
148
|
+
- test/test_api_token_middleware.rb
|
148
149
|
- test/test_auth.rb
|
149
150
|
- test/test_caching.rb
|
150
151
|
- test/test_generic.rb
|
151
152
|
- test/test_helper.rb
|
152
153
|
- test/test_maps.rb
|
153
154
|
- test/test_presence.rb
|
154
|
-
- test/test_proc_token.rb
|
155
155
|
has_rdoc:
|
data/test/test_proc_token.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class TestProcToken < MiniTest::Unit::TestCase
|
4
|
-
|
5
|
-
def test_working_proc_token
|
6
|
-
# Redo the LWS setup with a proc block as token
|
7
|
-
LWS.setup do |config|
|
8
|
-
config.api_token = proc { ENV["LC_LWS_TEST_TOKEN"] }
|
9
|
-
if ENV["LC_LWS_TEST_DEBUG"].present?
|
10
|
-
config.http_debug = true
|
11
|
-
config.json_debug = true
|
12
|
-
end
|
13
|
-
config.environment = :development
|
14
|
-
end
|
15
|
-
|
16
|
-
task = LWS::Auth::Task.all.first
|
17
|
-
refute_nil(task)
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_failing_proc
|
21
|
-
# Redo the LWS setup with a proc block as token
|
22
|
-
LWS.setup do |config|
|
23
|
-
config.api_token = proc { nil }
|
24
|
-
if ENV["LC_LWS_TEST_DEBUG"].present?
|
25
|
-
config.http_debug = true
|
26
|
-
config.json_debug = true
|
27
|
-
end
|
28
|
-
config.environment = :development
|
29
|
-
end
|
30
|
-
|
31
|
-
task = LWS::Auth::Task.all.first
|
32
|
-
assert_nil(task)
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|