lws 0.4.2 → 6.1.0.beta1
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/README.rdoc +4 -2
- data/bin/lwsconsole +32 -35
- data/lib/lws/auth.rb +425 -152
- data/lib/lws/corporate_website.rb +186 -68
- data/lib/lws/digital_signage.rb +1796 -0
- data/lib/lws/generic.rb +46 -50
- data/lib/lws/maps.rb +84 -38
- data/lib/lws/presence.rb +93 -73
- data/lib/lws/stubbing.rb +2 -2
- data/lib/lws/ticket.rb +230 -177
- data/lib/lws/version.rb +2 -2
- data/lib/lws.rb +66 -25
- data/lws.gemspec +3 -2
- data/test/api_token_middleware_test.rb +4 -4
- data/test/auth_test.rb +95 -8
- data/test/corporate_website_test.rb +44 -2
- data/test/digital_signage_test.rb +829 -0
- data/test/fixtures/auth.yml +4 -1
- data/test/fixtures/permissions.yml +0 -4
- data/test/generic_test.rb +0 -17
- data/test/json_parser_test.rb +57 -0
- data/test/logger_test.rb +2 -1
- data/test/maps_test.rb +22 -1
- data/test/presence_test.rb +18 -18
- data/test/setup_test.rb +5 -0
- data/test/stubbing_test.rb +4 -2
- data/test/test_helper.rb +3 -2
- data/test/ticket_test.rb +59 -44
- metadata +43 -24
data/lib/lws/ticket.rb
CHANGED
@@ -20,7 +20,7 @@ module LWS::Ticket
|
|
20
20
|
end
|
21
21
|
# :nocov:
|
22
22
|
|
23
|
-
|
23
|
+
# @!visibility private
|
24
24
|
def self.api
|
25
25
|
LWS.setup_api(LWS.config.endpoints[:ticket] ||
|
26
26
|
ENDPOINT[LWS.config.environment])
|
@@ -33,244 +33,297 @@ module LWS::Ticket
|
|
33
33
|
use_api LWS::Ticket.api
|
34
34
|
end
|
35
35
|
|
36
|
-
# (see Generic::Task)
|
37
|
-
class Task < LWS::Generic::Task
|
38
|
-
use_api LWS::Ticket.api
|
39
|
-
end
|
40
|
-
|
41
36
|
### App specific classes
|
42
37
|
|
43
|
-
# = The ticket class
|
44
|
-
class
|
38
|
+
# = The ticket message attachment class
|
39
|
+
class Attachment < LWS::Generic::Model
|
45
40
|
use_api LWS::Ticket.api
|
46
41
|
|
47
|
-
|
48
|
-
#
|
49
|
-
|
50
|
-
#@!attribute account
|
51
|
-
# @return [LWS::Auth::Account] the account of the user that created the
|
52
|
-
# ticket
|
53
|
-
belongs_to :account, class_name: "LWS::Auth::Account"
|
54
|
-
|
55
|
-
#@!attribute account_id
|
56
|
-
# @return [Fixnum] the ID of the account of the user that created the
|
57
|
-
# ticket
|
58
|
-
|
59
|
-
#@!attribute assignee
|
60
|
-
# @return [LWS::Auth::Account] the account of the user that the ticket
|
61
|
-
# is assigned to
|
62
|
-
belongs_to :assignee, class_name: "LWS::Auth::Account"
|
63
|
-
|
64
|
-
#@!attribute assignee_id
|
65
|
-
# @return [Fixnum] the ID of the account of the user that the ticket
|
66
|
-
# is assigned to
|
67
|
-
|
68
|
-
#@!attribute company
|
69
|
-
# @return [LWS::Auth::Company] the company of the user that created
|
70
|
-
# the ticket
|
71
|
-
belongs_to :company, class_name: "LWS::Auth::Company"
|
72
|
-
|
73
|
-
#@!attribute company_id
|
74
|
-
# @return [Fixnum] the ID of the company of the user that created the
|
75
|
-
# ticket
|
76
|
-
|
77
|
-
#@!attribute description
|
78
|
-
# @return [String] the description (body) of the ticket
|
42
|
+
# @!attribute id [r]
|
43
|
+
# @return [Fixnum] the (unique) ID of the ticket message attachment
|
44
|
+
attribute :id
|
79
45
|
|
80
|
-
|
81
|
-
#
|
46
|
+
# @!attribute av_scanned_at
|
47
|
+
# @return [String, nil] the timestamp of when an anti-virus scan on the
|
48
|
+
# attached file was performed
|
49
|
+
attribute :av_scanned_at
|
82
50
|
|
83
|
-
|
84
|
-
#
|
85
|
-
|
86
|
-
#@!attribute group
|
87
|
-
# @return [String] the group (e.g. department/ticket type) the ticket
|
88
|
-
# belongs to
|
89
|
-
belongs_to :group
|
51
|
+
# @!attribute file_object
|
52
|
+
# @return [String] the URL of the attachment file object
|
53
|
+
attribute :file_object
|
90
54
|
|
91
|
-
|
92
|
-
#
|
93
|
-
|
94
|
-
#@!attribute messages
|
95
|
-
# @return [Array<Message>] the messages associated with the ticket
|
96
|
-
has_many :messages
|
55
|
+
# @!attribute message
|
56
|
+
# @return [Message] the ticket message associated with the attachment
|
57
|
+
belongs_to :message
|
97
58
|
|
98
|
-
|
99
|
-
#
|
100
|
-
#
|
101
|
-
|
59
|
+
# @!attribute message_id
|
60
|
+
# @return [Fixnum] the ID of the ticket message associated with the
|
61
|
+
# attachment
|
62
|
+
attribute :message_id
|
63
|
+
|
64
|
+
# @!attribute name
|
65
|
+
# @return [String] the name of the attachment
|
66
|
+
attribute :name
|
67
|
+
|
68
|
+
# @!attribute size
|
69
|
+
# @return [Fixnum] the size of the attachment (bytes)
|
70
|
+
attribute :size
|
71
|
+
|
72
|
+
# @!attribute url
|
73
|
+
# @return [String] the URL to the attachment that can be used to
|
74
|
+
# download it
|
75
|
+
attribute :url
|
76
|
+
|
77
|
+
# @!attribute created_at [r]
|
78
|
+
# @return [String] the timestamp of when the ticket message attachment
|
79
|
+
# was created
|
80
|
+
attribute :created_at
|
81
|
+
|
82
|
+
# @!attribute updated_at [r]
|
83
|
+
# @return [String] the timestamp of when the ticket message attachment
|
84
|
+
# was last updated
|
85
|
+
attribute :updated_at
|
86
|
+
end
|
102
87
|
|
103
|
-
|
104
|
-
|
105
|
-
|
88
|
+
# = The ticket group class
|
89
|
+
class Group < LWS::Generic::Model
|
90
|
+
use_api LWS::Ticket.api
|
106
91
|
|
107
|
-
|
108
|
-
#
|
92
|
+
# @!attribute id [r]
|
93
|
+
# @return [Fixnum] the (unique) ID of the ticket group
|
94
|
+
attribute :id
|
109
95
|
|
110
|
-
|
111
|
-
#
|
112
|
-
|
113
|
-
#@!attribute tags
|
114
|
-
# @return [Array<Tag>] the tags associated with the ticket
|
115
|
-
has_many :tags
|
96
|
+
# @!attribute name
|
97
|
+
# @return [String] the name of the ticket group
|
98
|
+
attribute :name
|
116
99
|
|
117
|
-
|
118
|
-
#
|
119
|
-
|
120
|
-
# by the model ID. This can be resolved into the object the ticket
|
121
|
-
# is created for/on.
|
122
|
-
#
|
123
|
-
# @return [String] the target of the ticket
|
100
|
+
# @!attribute slug [r]
|
101
|
+
# @return [String] the slug of the ticket group
|
102
|
+
attribute :slug
|
124
103
|
|
125
|
-
|
126
|
-
#
|
104
|
+
# @!attribute tickets
|
105
|
+
# @return [Array<Ticket>] the tickets that are assigned to the ticket
|
106
|
+
# group
|
107
|
+
has_many :tickets
|
127
108
|
|
128
|
-
|
129
|
-
#
|
109
|
+
# @!attribute created_at [r]
|
110
|
+
# @return [String] the timestamp of when the ticket group was created
|
111
|
+
attribute :created_at
|
130
112
|
|
131
|
-
|
132
|
-
#
|
113
|
+
# @!attribute updated_at [r]
|
114
|
+
# @return [String] the timestamp of when the ticket group was last updated
|
115
|
+
attribute :updated_at
|
133
116
|
end
|
134
117
|
|
135
118
|
# = The ticket message class
|
136
119
|
class Message < LWS::Generic::Model
|
137
120
|
use_api LWS::Ticket.api
|
138
121
|
|
139
|
-
|
140
|
-
#
|
122
|
+
# @!attribute id [r]
|
123
|
+
# @return [Fixnum] the (unique) ID of the ticket message
|
124
|
+
attribute :id
|
141
125
|
|
142
|
-
|
143
|
-
#
|
144
|
-
#
|
126
|
+
# @!attribute account
|
127
|
+
# @return [LWS::Auth::Account] the account of the user that created the
|
128
|
+
# ticket message
|
145
129
|
belongs_to :account, class_name: "LWS::Auth::Account"
|
146
130
|
|
147
|
-
|
148
|
-
#
|
149
|
-
#
|
131
|
+
# @!attribute account_id
|
132
|
+
# @return [Fixnum] the ID of the account of the user that created the
|
133
|
+
# ticket message
|
134
|
+
attribute :account_id
|
150
135
|
|
151
|
-
|
152
|
-
#
|
153
|
-
#
|
136
|
+
# @!attribute attachments
|
137
|
+
# @return [Array<Attachment>] the attachments associated with the ticket
|
138
|
+
# message
|
154
139
|
has_many :attachments
|
155
140
|
|
156
|
-
|
157
|
-
#
|
158
|
-
#
|
141
|
+
# @!attribute company
|
142
|
+
# @return [LWS::Auth::Company] the company of the user that created
|
143
|
+
# the ticket message
|
159
144
|
belongs_to :company, class_name: "LWS::Auth::Company"
|
160
145
|
|
161
|
-
|
162
|
-
#
|
163
|
-
#
|
146
|
+
# @!attribute company_id
|
147
|
+
# @return [Fixnum] the ID of the company of the user that created the
|
148
|
+
# ticket message
|
149
|
+
attribute :company_id
|
150
|
+
|
151
|
+
# @!attribute internal
|
152
|
+
# @return [Boolean] whether the message is internal, i.e. not visible
|
153
|
+
# for descendant companies
|
154
|
+
attribute :internal
|
164
155
|
|
165
|
-
|
166
|
-
#
|
156
|
+
# @!attribute message
|
157
|
+
# @return [String] the ticket message body
|
158
|
+
attribute :message
|
167
159
|
|
168
|
-
|
169
|
-
#
|
160
|
+
# @!attribute status
|
161
|
+
# @return [Fixnum] the new ticket status (ID) set by the message
|
162
|
+
attribute :status
|
170
163
|
|
171
|
-
|
172
|
-
#
|
164
|
+
# @!attribute ticket
|
165
|
+
# @return [Ticket] the ticket associated with the message
|
173
166
|
belongs_to :ticket
|
174
167
|
|
175
|
-
|
176
|
-
#
|
177
|
-
|
178
|
-
#@!attribute created_at
|
179
|
-
# @return [String] the timestamp of when the ticket message was created
|
168
|
+
# @!attribute ticket_id
|
169
|
+
# @return [Fixnum] the ID of the ticket associated with the message
|
170
|
+
attribute :ticket_id
|
180
171
|
|
181
|
-
|
182
|
-
#
|
183
|
-
|
172
|
+
# @!attribute created_at [r]
|
173
|
+
# @return [String] the timestamp of when the ticket message was created
|
174
|
+
attribute :created_at
|
175
|
+
|
176
|
+
# @!attribute updated_at [r]
|
177
|
+
# @return [String] the timestamp of when the ticket message was last
|
178
|
+
# updated
|
179
|
+
attribute :updated_at
|
184
180
|
end
|
185
181
|
|
186
|
-
# = The ticket
|
187
|
-
class
|
182
|
+
# = The ticket tag class
|
183
|
+
class Tag < LWS::Generic::Model
|
188
184
|
use_api LWS::Ticket.api
|
189
185
|
|
190
|
-
|
191
|
-
#
|
186
|
+
# @!attribute id [r]
|
187
|
+
# @return [Fixnum] the (unique) ID of the ticket tag
|
188
|
+
attribute :id
|
192
189
|
|
193
|
-
|
194
|
-
#
|
195
|
-
|
190
|
+
# @!attribute description
|
191
|
+
# @return [String, nil] the description of the ticket tag
|
192
|
+
attribute :description
|
196
193
|
|
197
|
-
|
198
|
-
#
|
199
|
-
|
194
|
+
# @!attribute dev_issue_id
|
195
|
+
# @return [Fixnum, nil] the ID of the issue in LeftClick's internal bug
|
196
|
+
# tracking system
|
197
|
+
attribute :dev_issue_id
|
200
198
|
|
201
|
-
|
202
|
-
#
|
203
|
-
|
199
|
+
# @!attribute name
|
200
|
+
# @return [String] the name of the ticket tag
|
201
|
+
attribute :name
|
204
202
|
|
205
|
-
|
206
|
-
#
|
203
|
+
# @!attribute slug [r]
|
204
|
+
# @return [String] the slug of the ticket tag
|
205
|
+
attribute :slug
|
207
206
|
|
208
|
-
|
209
|
-
#
|
207
|
+
# @!attribute tickets
|
208
|
+
# @return [Array<Ticket>] the ticket associated with the tag
|
209
|
+
has_many :tickets
|
210
210
|
|
211
|
-
|
212
|
-
#
|
213
|
-
|
214
|
-
#@!attribute created_at
|
215
|
-
# @return [String] the timestamp of when the ticket message attachment
|
216
|
-
# was created
|
211
|
+
# @!attribute created_at [r]
|
212
|
+
# @return [String] the timestamp of when the ticket tag was created
|
213
|
+
attribute :created_at
|
217
214
|
|
218
|
-
|
219
|
-
#
|
220
|
-
|
215
|
+
# @!attribute updated_at [r]
|
216
|
+
# @return [String] the timestamp of when the ticket tag was last updated
|
217
|
+
attribute :updated_at
|
221
218
|
end
|
222
219
|
|
223
|
-
# = The ticket
|
224
|
-
class
|
220
|
+
# = The ticket class
|
221
|
+
class Ticket < LWS::Generic::Model
|
225
222
|
use_api LWS::Ticket.api
|
226
223
|
|
227
|
-
|
228
|
-
#
|
224
|
+
# @!attribute id [r]
|
225
|
+
# @return [Fixnum] the (unique) ID of the ticket
|
226
|
+
attribute :id
|
229
227
|
|
230
|
-
|
231
|
-
#
|
228
|
+
# @!attribute account
|
229
|
+
# @return [LWS::Auth::Account] the account of the user that created the
|
230
|
+
# ticket
|
231
|
+
belongs_to :account, class_name: "LWS::Auth::Account"
|
232
232
|
|
233
|
-
|
234
|
-
#
|
235
|
-
|
236
|
-
|
237
|
-
|
233
|
+
# @!attribute account_id
|
234
|
+
# @return [Fixnum] the ID of the account of the user that created the
|
235
|
+
# ticket
|
236
|
+
attribute :account_id
|
237
|
+
|
238
|
+
# @!attribute assignee
|
239
|
+
# @return [LWS::Auth::Account, nil] the account of the user that the
|
240
|
+
# ticket is assigned to
|
241
|
+
belongs_to :assignee, class_name: "LWS::Auth::Account",
|
242
|
+
uri: "accounts/:id"
|
243
|
+
|
244
|
+
# @!attribute assignee_id
|
245
|
+
# @return [Fixnum, nil] the ID of the account of the user that the
|
246
|
+
# ticket is assigned to
|
247
|
+
attribute :assignee_id
|
248
|
+
|
249
|
+
# @!attribute company
|
250
|
+
# @return [LWS::Auth::Company] the company of the user that created
|
251
|
+
# the ticket
|
252
|
+
belongs_to :company, class_name: "LWS::Auth::Company"
|
238
253
|
|
239
|
-
|
240
|
-
#
|
254
|
+
# @!attribute company_id
|
255
|
+
# @return [Fixnum] the ID of the company of the user that created the
|
256
|
+
# ticket
|
257
|
+
attribute :company_id
|
241
258
|
|
242
|
-
|
243
|
-
|
259
|
+
# @!attribute description
|
260
|
+
# @return [String, nil] the description (body) of the ticket
|
261
|
+
attribute :description
|
244
262
|
|
245
|
-
|
246
|
-
|
247
|
-
|
263
|
+
# @!attribute display_name
|
264
|
+
# @return [String] the name of the object the ticket is created for
|
265
|
+
attribute :display_name
|
248
266
|
|
249
|
-
|
250
|
-
#
|
267
|
+
# @!attribute due_date
|
268
|
+
# @return [String, nil] the timestamp of when the ticket is due
|
269
|
+
attribute :due_date
|
251
270
|
|
252
|
-
|
253
|
-
#
|
271
|
+
# @!attribute group
|
272
|
+
# @return [Group] the group (e.g. department/ticket type) the ticket
|
273
|
+
# belongs to
|
274
|
+
belongs_to :group
|
254
275
|
|
255
|
-
|
256
|
-
#
|
257
|
-
|
276
|
+
# @!attribute group_id
|
277
|
+
# @return [Fixnum] the ID of the group the ticket belongs to
|
278
|
+
attribute :group_id
|
258
279
|
|
259
|
-
|
260
|
-
#
|
280
|
+
# @!attribute messages
|
281
|
+
# @return [Array<Message>] the messages associated with the ticket
|
282
|
+
has_many :messages
|
261
283
|
|
262
|
-
|
263
|
-
#
|
284
|
+
# @!attribute owner
|
285
|
+
# @return [LWS::Auth::Company] the company that is currently handling
|
286
|
+
# the ticket
|
287
|
+
belongs_to :owner, class_name: "LWS::Auth::Company",
|
288
|
+
uri: "companies/:id"
|
264
289
|
|
265
|
-
|
266
|
-
#
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
#
|
290
|
+
# @!attribute owner_id
|
291
|
+
# @return [Fixnum] the ID of the company that is currently handling
|
292
|
+
# the ticket
|
293
|
+
attribute :owner_id
|
294
|
+
|
295
|
+
# @!attribute priority
|
296
|
+
# @return [Fixnum] the priority (ID) of the ticket
|
297
|
+
attribute :priority
|
298
|
+
|
299
|
+
# @!attribute status
|
300
|
+
# @return [Fixnum] the current ticket status (ID)
|
301
|
+
attribute :status
|
302
|
+
|
303
|
+
# @!attribute tags
|
304
|
+
# @return [Array<Tag>] the tags associated with the ticket
|
305
|
+
has_many :tags
|
306
|
+
|
307
|
+
# @!attribute target
|
308
|
+
# The target is a string that consists of three parts joined by a dot.
|
309
|
+
# It is the name of the app, followed by the model name, followed
|
310
|
+
# by the model ID. This can be resolved into the object the ticket
|
311
|
+
# is created for/on.
|
312
|
+
#
|
313
|
+
# @return [String] the target of the ticket
|
314
|
+
attribute :target
|
315
|
+
|
316
|
+
# @!attribute title
|
317
|
+
# @return [String] the title (short description) of the ticket
|
318
|
+
attribute :title
|
319
|
+
|
320
|
+
# @!attribute created_at [r]
|
321
|
+
# @return [String] the timestamp of when the ticket was created
|
322
|
+
attribute :created_at
|
271
323
|
|
272
|
-
|
273
|
-
#
|
324
|
+
# @!attribute updated_at [r]
|
325
|
+
# @return [String] the timestamp of when the ticket was last updated
|
326
|
+
attribute :updated_at
|
274
327
|
end
|
275
328
|
|
276
329
|
end
|
data/lib/lws/version.rb
CHANGED
data/lib/lws.rb
CHANGED
@@ -11,8 +11,8 @@
|
|
11
11
|
|
12
12
|
require "faraday_middleware"
|
13
13
|
require "hashie"
|
14
|
-
require "her"
|
15
14
|
require "multi_json"
|
15
|
+
require "spyke"
|
16
16
|
require "pp"
|
17
17
|
require "webmock"
|
18
18
|
|
@@ -31,23 +31,43 @@ module LWS
|
|
31
31
|
|
32
32
|
# The list of supported apps (web service libraries) loaded by
|
33
33
|
# {.setup}.
|
34
|
-
SUPPORTED_APPS = [:generic, :auth, :corporate_website, :
|
35
|
-
:ticket]
|
34
|
+
SUPPORTED_APPS = [:generic, :auth, :corporate_website, :digital_signage,
|
35
|
+
:maps, :presence, :ticket]
|
36
|
+
|
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
|
36
53
|
|
37
54
|
# @private
|
38
55
|
# @!visibility private
|
39
56
|
class HTTPLogger < Faraday::Response::Middleware
|
40
57
|
|
41
|
-
def initialize(app, logger)
|
58
|
+
def initialize(app, logger, show_headers)
|
42
59
|
raise "cannot log HTTP requests without a logger" if logger.nil?
|
43
60
|
@logger = logger
|
61
|
+
@show_headers = show_headers
|
44
62
|
super(app)
|
45
63
|
end
|
46
64
|
|
47
65
|
def call(env)
|
48
66
|
@logger.debug ">>> #{env[:method].upcase} #{env[:url].to_s}"
|
49
|
-
|
50
|
-
|
67
|
+
if @show_headers
|
68
|
+
env[:request_headers].each do |hdr, val|
|
69
|
+
@logger.debug " #{hdr}: #{val}"
|
70
|
+
end
|
51
71
|
end
|
52
72
|
@logger.debug ">>> #{env[:body] || "nil"}"
|
53
73
|
super
|
@@ -56,8 +76,10 @@ module LWS
|
|
56
76
|
def on_complete(env)
|
57
77
|
super
|
58
78
|
@logger.debug "<<< HTTP #{env[:status].to_s}"
|
59
|
-
|
60
|
-
|
79
|
+
if @show_headers
|
80
|
+
env[:response_headers].each do |hdr, val|
|
81
|
+
@logger.debug " #{hdr}: #{val}"
|
82
|
+
end
|
61
83
|
end
|
62
84
|
@logger.debug "<<< #{env[:body] || "nil"}"
|
63
85
|
end
|
@@ -75,7 +97,7 @@ module LWS
|
|
75
97
|
end
|
76
98
|
|
77
99
|
def on_complete(env)
|
78
|
-
dump =
|
100
|
+
dump = JSON.pretty_generate(env[:body])
|
79
101
|
dump.split("\n").each { |line| @logger.debug "||| #{line}" }
|
80
102
|
end
|
81
103
|
|
@@ -135,6 +157,10 @@ module LWS
|
|
135
157
|
# @return [Boolean] whether to show HTTP debug messages
|
136
158
|
property :http_debug, default: false
|
137
159
|
|
160
|
+
#@!attribute http_debug_headers
|
161
|
+
# @return [Boolean] whether to show HTTP headers in the debug messages
|
162
|
+
property :http_debug_headers, default: false
|
163
|
+
|
138
164
|
#@!attribute json_debug
|
139
165
|
# @return [Boolean] whether to show JSON debug messages
|
140
166
|
property :json_debug, default: false
|
@@ -161,6 +187,10 @@ module LWS
|
|
161
187
|
# config.logger = Rails.logger
|
162
188
|
# end
|
163
189
|
#
|
190
|
+
# A default value for the API token can be set using the
|
191
|
+
# +LC_LWS_API_TOKEN+ environment variable. The default environment can
|
192
|
+
# be overriden using the +LC_LWS_ENV+ environment variable.
|
193
|
+
#
|
164
194
|
# @yieldparam [Config] config an API configuration object that can be
|
165
195
|
# configured
|
166
196
|
# @raise if API token is not configured
|
@@ -169,8 +199,10 @@ module LWS
|
|
169
199
|
@@config = Config.new
|
170
200
|
yield @@config
|
171
201
|
|
172
|
-
if
|
173
|
-
|
202
|
+
# Override the API token if needed (and no custom API token middleware
|
203
|
+
# is used)
|
204
|
+
if ENV["LC_LWS_API_TOKEN"].present?
|
205
|
+
@@config.api_token = ENV["LC_LWS_API_TOKEN"]
|
174
206
|
end
|
175
207
|
|
176
208
|
# Override the environment if needed
|
@@ -178,6 +210,10 @@ module LWS
|
|
178
210
|
@@config.environment = ENV["LC_LWS_ENV"].to_sym
|
179
211
|
end
|
180
212
|
|
213
|
+
if config.api_token.blank? and config.api_token_middleware.blank?
|
214
|
+
raise "API token or API token middleware is required"
|
215
|
+
end
|
216
|
+
|
181
217
|
load_app_modules
|
182
218
|
load_stubbing
|
183
219
|
|
@@ -186,30 +222,43 @@ module LWS
|
|
186
222
|
|
187
223
|
# @private
|
188
224
|
# @!visibility private
|
225
|
+
#
|
226
|
+
# Sets up the Faraday API object with the current LWS configuration for
|
227
|
+
# the given API URL.
|
228
|
+
#
|
229
|
+
# @param api_url The endpoint URL of the API
|
230
|
+
# @return [Faraday] A Faraday connection that makes requests to the API
|
189
231
|
def self.setup_api(api_url)
|
190
|
-
api =
|
191
|
-
api.setup(url: api_url) do |c|
|
232
|
+
api = Faraday.new(url: api_url) do |c|
|
192
233
|
# Request
|
193
234
|
if config.caching_object
|
194
235
|
c.use FaradayMiddleware::Caching, config.caching_object
|
195
236
|
end
|
196
237
|
c.use RequestHeaders, config.api_token
|
197
238
|
c.use config.api_token_middleware if config.api_token_middleware.present?
|
198
|
-
c.
|
239
|
+
c.request :json
|
199
240
|
|
200
241
|
# Response
|
201
242
|
c.use JSONLogger, config.logger if config.json_debug
|
202
|
-
c.use
|
243
|
+
c.use JSONParser
|
203
244
|
c.use FaradayMiddleware::FollowRedirects, limit: 3
|
204
|
-
c.use HTTPLogger, config.logger if config.http_debug
|
245
|
+
c.use HTTPLogger, config.logger, config.http_debug_headers if config.http_debug
|
205
246
|
|
206
247
|
# Adapter
|
207
|
-
c.
|
248
|
+
c.adapter Faraday.default_adapter
|
208
249
|
end
|
209
250
|
|
210
251
|
return api
|
211
252
|
end
|
212
253
|
|
254
|
+
# Returns the app module for the given app name.
|
255
|
+
#
|
256
|
+
# @param app_name [String, Symbol] the app name
|
257
|
+
# @return [Module] the app module
|
258
|
+
def self.app_module(app_name)
|
259
|
+
@app_modules[app_name.to_sym]
|
260
|
+
end
|
261
|
+
|
213
262
|
# (Re)loads the app modules (usually done by {.setup}).
|
214
263
|
#
|
215
264
|
# @return [Array<Symbol>] the apps that were loaded
|
@@ -235,12 +284,4 @@ module LWS
|
|
235
284
|
end
|
236
285
|
end
|
237
286
|
|
238
|
-
# Returns the app module for the given app name.
|
239
|
-
#
|
240
|
-
# @param app_name [String, Symbol] the app name
|
241
|
-
# @return [Module] the app module
|
242
|
-
def self.app_module(app_name)
|
243
|
-
@app_modules[app_name.to_sym]
|
244
|
-
end
|
245
|
-
|
246
287
|
end # module LWS
|