forest_liana 2.13.7 → 2.14.0

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
  SHA1:
3
- metadata.gz: 16318e2524b21f70f7486522ffb5a3c7c1f665e0
4
- data.tar.gz: 15fdb1c6676f2085ac309da628b11828307525ce
3
+ metadata.gz: 0e5ad26fa4fc70fb9b65e3327884b7d2c9f0b7bb
4
+ data.tar.gz: 06a6093675ef2b6906dd45b585d3be366230a718
5
5
  SHA512:
6
- metadata.gz: 2b86c92edbd972fa0c6b8b039de6f116d942b5642fd69c05eeaa4a6397f245e702d9ddb50a4ac30b5c50da960dff7c493848e3cda79b8c854ce27ac3f72dbabf
7
- data.tar.gz: c5523d04cfa10feb27c457c40fab742bc295ff97e111242ec6d455901269e83cdf8cb26caf76a7b4846fd9d2c67c0ed1713a6341c8c4d9cb8be69249c12e3465
6
+ metadata.gz: 4a209c7f717e94558c2c2f23235b3f45d65542d5cb52a2b9d559dea1e3d31ee3bea929ab77c8502c7923013c4e97b9fea713a107741f17aab5d1805f16722c91
7
+ data.tar.gz: 05ac2085057362df3aa8bd4424d53d15399fad2efe1bc97a64e6ec56be8451bd04e4c279d3c069ae893a232aeaa9ebd43b04b5a4b15cdf3e28d4c7feff9a8457
@@ -18,7 +18,7 @@ module ForestLiana
18
18
  headers = { 'email' => @auth_data[:email], 'password' => @auth_data[:password] }
19
19
  end
20
20
 
21
- query_parameters = { 'renderingId' => @rendering_id }
21
+ query_parameters = {}
22
22
 
23
23
  if @two_factor_registration
24
24
  query_parameters['two-factor-registration'] = true
@@ -1,9 +1,7 @@
1
1
  module ForestLiana
2
2
  class Bootstraper
3
3
 
4
- def initialize(app)
5
- @app = app
6
-
4
+ def initialize
7
5
  @integration_stripe_valid = false
8
6
  @integration_intercom_valid = false
9
7
 
@@ -17,23 +15,39 @@ module ForestLiana
17
15
  end
18
16
  end
19
17
 
20
- def perform
21
- fetch_models
22
- check_integrations_setup
23
- namespace_duplicated_models
24
- create_factories
18
+ def perform(with_feedback=false)
19
+ introspect_and_generate_factories
25
20
 
26
21
  if ForestLiana.env_secret
27
- create_apimap
28
- require_lib_forest_liana
29
- format_and_validate_smart_actions
22
+ generate_apimap
23
+ send_apimap(with_feedback)
24
+ end
25
+ end
26
+
27
+ def display_apimap
28
+ introspect_and_generate_factories
30
29
 
31
- send_apimap
30
+ if ForestLiana.env_secret
31
+ generate_apimap
32
+ puts " = Current Forest Apimap:\n#{JSON.pretty_generate(get_apimap_serialized)}"
32
33
  end
33
34
  end
34
35
 
35
36
  private
36
37
 
38
+ def introspect_and_generate_factories
39
+ fetch_models
40
+ check_integrations_setup
41
+ namespace_duplicated_models
42
+ create_factories
43
+ end
44
+
45
+ def generate_apimap
46
+ create_apimap
47
+ require_lib_forest_liana
48
+ format_and_validate_smart_actions
49
+ end
50
+
37
51
  def is_sti_parent_model?(model)
38
52
  return false unless model.try(:table_exists?)
39
53
 
@@ -199,26 +213,32 @@ module ForestLiana
199
213
  end
200
214
  end
201
215
 
202
- def send_apimap
216
+ def get_apimap_serialized
217
+ apimap = JSONAPI::Serializer.serialize(ForestLiana.apimap, {
218
+ is_collection: true,
219
+ include: ['actions', 'segments'],
220
+ meta: {
221
+ liana: 'forest-rails',
222
+ liana_version: liana_version,
223
+ framework_version: Gem.loaded_specs["rails"].version.version,
224
+ orm_version: Gem.loaded_specs["activerecord"].version.version,
225
+ database_type: database_type
226
+ }
227
+ })
228
+
229
+ ForestLiana::ApimapSorter.new(apimap).perform
230
+ end
231
+
232
+ def send_apimap(with_feedback=false)
203
233
  if ForestLiana.env_secret && ForestLiana.env_secret.length != 64
204
234
  FOREST_LOGGER.error "Your env_secret does not seem to be correct. " \
205
235
  "Can you check on Forest that you copied it properly in the " \
206
236
  "forest_liana initializer?"
207
237
  else
208
- apimap = JSONAPI::Serializer.serialize(ForestLiana.apimap, {
209
- is_collection: true,
210
- include: ['actions', 'segments'],
211
- meta: {
212
- liana: 'forest-rails',
213
- liana_version: liana_version,
214
- framework_version: Gem.loaded_specs["rails"].version.version,
215
- orm_version: Gem.loaded_specs["activerecord"].version.version,
216
- database_type: database_type
217
- }
218
- })
238
+ apimap = get_apimap_serialized
219
239
 
220
240
  begin
221
- apimap = ForestLiana::ApimapSorter.new(apimap).perform
241
+ puts " = Sending Forest Apimap:\n#{JSON.pretty_generate(apimap)}" if with_feedback
222
242
  uri = URI.parse("#{forest_url}/forest/apimaps")
223
243
  http = Net::HTTP.new(uri.host, uri.port)
224
244
  http.use_ssl = true if forest_url.start_with?('https')
@@ -234,6 +254,14 @@ module ForestLiana
234
254
  warning = JSON.parse(response.body)['warning']
235
255
  end
236
256
 
257
+ if with_feedback
258
+ if response.is_a?(Net::HTTPOK) || response.is_a?(Net::HTTPNoContent)
259
+ puts " = Apimap Received - nothing changed"
260
+ elsif response.is_a?(Net::HTTPAccepted)
261
+ puts " = Apimap Received - update detected (currently updating the UI)"
262
+ end
263
+ end
264
+
237
265
  if response.is_a?(Net::HTTPNotFound) # NOTICE: HTTP 404 Error
238
266
  FOREST_LOGGER.error "Cannot find the project related to the " \
239
267
  "env_secret you configured. Can you check on Forest that " \
@@ -242,10 +270,10 @@ module ForestLiana
242
270
  FOREST_LOGGER.error "An error occured with the apimap sent " \
243
271
  "to Forest. Please contact support@forestadmin.com for " \
244
272
  "further investigations."
245
- elsif response.is_a?(Net::HTTPServiceUnavailable) # NOTICE: HTTP 503 Error
246
- FOREST_LOGGER.warn "Forest is in maintenance for a few " \
247
- "minutes. We are upgrading your experience in the " \
248
- "forest. We just need a few more minutes to get it right."
273
+ elsif response.is_a?(Net::HTTPServiceUnavailable) # NOTICE: HTTP 503 Error
274
+ FOREST_LOGGER.warn "Forest is in maintenance for a few " \
275
+ "minutes. We are upgrading your experience in the " \
276
+ "forest. We just need a few more minutes to get it right."
249
277
  elsif warning
250
278
  FOREST_LOGGER.warn warning
251
279
  end
@@ -67,11 +67,13 @@ module ForestLiana
67
67
  "domains for CORS constraint:\n#{error}"
68
68
  end
69
69
 
70
- eager_load_active_record_descendants(app)
70
+ unless ENV['FOREST_DEACTIVATE_AUTOMATIC_APIMAP']
71
+ eager_load_active_record_descendants(app)
71
72
 
72
- if database_available?
73
- # NOTICE: Do not run the code below on rails g forest_liana:install.
74
- Bootstraper.new(app).perform if ForestLiana.env_secret || ForestLiana.secret_key
73
+ if database_available?
74
+ # NOTICE: Do not run the code below on rails g forest_liana:install.
75
+ Bootstraper.new().perform if ForestLiana.env_secret || ForestLiana.secret_key
76
+ end
75
77
  end
76
78
  end
77
79
  end
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "2.13.7"
2
+ VERSION = "2.14.0"
3
3
  end
@@ -0,0 +1,8 @@
1
+ namespace :forest do
2
+ desc "Display the current Forest Apimap version"
3
+ task(:display_apimap).clear
4
+ task display_apimap: :environment do
5
+ bootstraper = ForestLiana::Bootstraper.new()
6
+ bootstraper.display_apimap
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ namespace :forest do
2
+ desc "Synchronize the models/customization with Forest servers"
3
+ task(:send_apimap).clear
4
+ task send_apimap: :environment do
5
+ if ForestLiana.env_secret
6
+ bootstraper = ForestLiana::Bootstraper.new()
7
+ bootstraper.perform(true)
8
+ else
9
+ puts 'Cannot send the Apimap, Forest cannot find your env_secret'
10
+ end
11
+ end
12
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_liana
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.13.7
4
+ version: 2.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Munda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-19 00:00:00.000000000 Z
11
+ date: 2018-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -288,6 +288,8 @@ files:
288
288
  - lib/forest_liana/mixpanel_event.rb
289
289
  - lib/forest_liana/version.rb
290
290
  - lib/generators/forest_liana/install_generator.rb
291
+ - lib/tasks/display_apimap.rake
292
+ - lib/tasks/send_apimap.rake
291
293
  - test/dummy/README.rdoc
292
294
  - test/dummy/Rakefile
293
295
  - test/dummy/app/assets/javascripts/application.js