cangaroo 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/app/controllers/cangaroo/endpoint_controller.rb +22 -28
  4. data/app/interactors/cangaroo/count_json_object.rb +2 -12
  5. data/app/interactors/cangaroo/perform_jobs.rb +2 -6
  6. data/app/interactors/cangaroo/run_polls.rb +0 -1
  7. data/app/interactors/cangaroo/validate_json_schema.rb +3 -8
  8. data/app/jobs/cangaroo/base_job.rb +35 -0
  9. data/app/jobs/cangaroo/job.rb +2 -36
  10. data/app/jobs/cangaroo/poll_job.rb +20 -44
  11. data/app/jobs/cangaroo/push_job.rb +15 -0
  12. data/app/models/cangaroo/connection.rb +3 -3
  13. data/app/models/cangaroo/poll_timestamp.rb +1 -2
  14. data/db/migrate/20151028172151_create_cangaroo_connections.rb +1 -1
  15. data/db/migrate/20151030140821_add_parameters_to_cangaroo_connection.rb +1 -1
  16. data/db/migrate/20160317020230_create_cangaroo_poll_timestamps.rb +2 -2
  17. data/lib/cangaroo.rb +9 -0
  18. data/lib/cangaroo/class_configuration.rb +7 -4
  19. data/lib/cangaroo/engine.rb +2 -0
  20. data/lib/cangaroo/logger.rb +13 -58
  21. data/lib/cangaroo/logger_helper.rb +13 -0
  22. data/lib/cangaroo/migration.rb +11 -0
  23. data/lib/cangaroo/version.rb +1 -1
  24. data/lib/cangaroo/webhook/client.rb +27 -15
  25. data/spec/factories/cangaroo_connections.rb +26 -2
  26. data/spec/features/push_flow_spec.rb +79 -0
  27. data/spec/fixtures/json_payload_ok.json +3 -1
  28. data/spec/interactors/cangaroo/count_json_object_spec.rb +4 -2
  29. data/spec/interactors/cangaroo/perform_jobs_spec.rb +2 -3
  30. data/spec/jobs/cangaroo/poll_job_spec.rb +15 -17
  31. data/spec/jobs/cangaroo/{job_spec.rb → push_job_spec.rb} +25 -17
  32. data/spec/lib/cangaroo/logger_helper_spec.rb +21 -0
  33. data/spec/lib/cangaroo/logger_spec.rb +83 -0
  34. data/spec/lib/cangaroo/webhook/client_spec.rb +39 -24
  35. data/spec/rails_helper.rb +4 -2
  36. data/spec/{controllers/cangaroo/endpoint_controller_spec.rb → requests/cangaroo/endpoint_spec.rb} +21 -30
  37. data/spec/support/jobs/confirm_order_mail_job.rb +10 -0
  38. data/spec/support/jobs/erp_job.rb +10 -0
  39. data/spec/support/jobs/fake_push_job.rb +5 -0
  40. data/spec/support/jobs/shipped_order_mail_job.rb +10 -0
  41. data/spec/support/jobs/store_job.rb +10 -0
  42. data/spec/support/jobs/warehouse_job.rb +10 -0
  43. data/spec/support/rails_app.rb +1 -0
  44. data/spec/support/spec_helpers.rb +23 -0
  45. metadata +53 -32
  46. data/app/controllers/cangaroo/application_controller.rb +0 -4
@@ -0,0 +1,10 @@
1
+ module Cangaroo
2
+ class ConfirmOrderMailJob < PushJob
3
+ connection :mail
4
+ path '/send_confirmation_order_email'
5
+
6
+ def perform?
7
+ type == 'orders' && payload['state'] == 'confirmed'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Cangaroo
2
+ class ErpJob < PushJob
3
+ connection :erp
4
+ path '/add_order'
5
+
6
+ def perform?
7
+ type == 'orders' && payload['state'] == 'payed'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ class FakePushJob < Cangaroo::PushJob
2
+ connection :store
3
+ path '/webhook_path'
4
+ parameters(email: 'info@nebulab.it')
5
+ end
@@ -0,0 +1,10 @@
1
+ module Cangaroo
2
+ class ShippedOrderMailJob < PushJob
3
+ connection :mail
4
+ path '/send_shipped_order_email'
5
+
6
+ def perform?
7
+ type == 'orders' && payload['state'] == 'shipped'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Cangaroo
2
+ class StoreJob < PushJob
3
+ connection :store
4
+ path '/update_order'
5
+
6
+ def perform?
7
+ type == 'orders' && %w(confirmed shipped).include?(payload['state'])
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Cangaroo
2
+ class WarehouseJob < PushJob
3
+ connection :warehouse
4
+ path '/add_shipment'
5
+
6
+ def perform?
7
+ type == 'orders' && payload['state'] == 'confirmed'
8
+ end
9
+ end
10
+ end
@@ -12,6 +12,7 @@ ENV['DATABASE_URL'] = "sqlite3://#{database_path}"
12
12
  # Initialize our test app
13
13
 
14
14
  class RailsApp < Rails::Application
15
+ config.active_job.queue_adapter = :inline
15
16
  config.secret_key_base = SecureRandom.hex
16
17
  config.eager_load = false
17
18
  end
@@ -7,9 +7,32 @@ module Cangaroo
7
7
  def parse_fixture(filename)
8
8
  JSON.parse(load_fixture(filename))
9
9
  end
10
+
11
+ def stub_api(job:, request_body: {}, response_body: nil, response_status: 200)
12
+ job_id = SecureRandom.uuid
13
+ connection = Cangaroo::Connection.find_by(name: job.connection) || create(job.connection)
14
+
15
+ allow_any_instance_of(job).to receive(:job_id).and_return(job_id)
16
+
17
+ request_body = request_body.merge(
18
+ request_id: job_id,
19
+ parameters: connection.parameters || {}
20
+ )
21
+
22
+ response_body = response_body.merge('request_id' => job_id).to_json if response_body
23
+
24
+ stub_request(:post, "#{connection.url}#{job.path}")
25
+ .with(body: request_body,
26
+ headers: { 'Accept': 'application/json',
27
+ 'Content-Type': 'application/json',
28
+ 'X-Hub-Token': connection.token })
29
+ .to_return(body: response_body, status: response_status)
30
+ end
10
31
  end
11
32
  end
12
33
 
13
34
  RSpec.configure do |config|
35
+ config.include RSpec::Rails::RequestExampleGroup, type: :feature
14
36
  config.include Cangaroo::SpecHelpers
37
+ config.include Cangaroo::Engine.routes.url_helpers
15
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cangaroo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessio Rocco
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-05-20 00:00:00.000000000 Z
12
+ date: 2018-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -31,42 +31,42 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '2.0'
34
+ version: 2.1.1
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '2.0'
41
+ version: 2.1.1
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: json-schema
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: 2.5.1
48
+ version: 2.8.0
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: 2.5.1
55
+ version: 2.8.0
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: httparty
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: 0.13.7
62
+ version: 0.14.0
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: 0.13.7
69
+ version: 0.14.0
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: appraisal
72
72
  requirement: !ruby/object:Gem::Requirement
@@ -244,7 +244,6 @@ extra_rdoc_files: []
244
244
  files:
245
245
  - MIT-LICENSE
246
246
  - Rakefile
247
- - app/controllers/cangaroo/application_controller.rb
248
247
  - app/controllers/cangaroo/endpoint_controller.rb
249
248
  - app/interactors/cangaroo/authenticate_connection.rb
250
249
  - app/interactors/cangaroo/count_json_object.rb
@@ -253,8 +252,10 @@ files:
253
252
  - app/interactors/cangaroo/perform_jobs.rb
254
253
  - app/interactors/cangaroo/run_polls.rb
255
254
  - app/interactors/cangaroo/validate_json_schema.rb
255
+ - app/jobs/cangaroo/base_job.rb
256
256
  - app/jobs/cangaroo/job.rb
257
257
  - app/jobs/cangaroo/poll_job.rb
258
+ - app/jobs/cangaroo/push_job.rb
258
259
  - app/models/cangaroo/connection.rb
259
260
  - app/models/cangaroo/poll_timestamp.rb
260
261
  - config/routes.rb
@@ -265,12 +266,14 @@ files:
265
266
  - lib/cangaroo/class_configuration.rb
266
267
  - lib/cangaroo/engine.rb
267
268
  - lib/cangaroo/logger.rb
269
+ - lib/cangaroo/logger_helper.rb
270
+ - lib/cangaroo/migration.rb
268
271
  - lib/cangaroo/version.rb
269
272
  - lib/cangaroo/webhook/client.rb
270
273
  - lib/cangaroo/webhook/error.rb
271
274
  - lib/tasks/cangaroo_tasks.rake
272
- - spec/controllers/cangaroo/endpoint_controller_spec.rb
273
275
  - spec/factories/cangaroo_connections.rb
276
+ - spec/features/push_flow_spec.rb
274
277
  - spec/fixtures/json_payload_connection_response.json
275
278
  - spec/fixtures/json_payload_empty.json
276
279
  - spec/fixtures/json_payload_no_id.json
@@ -283,14 +286,23 @@ files:
283
286
  - spec/interactors/cangaroo/perform_jobs_spec.rb
284
287
  - spec/interactors/cangaroo/run_polls_spec.rb
285
288
  - spec/interactors/cangaroo/validate_json_schema_spec.rb
286
- - spec/jobs/cangaroo/job_spec.rb
287
289
  - spec/jobs/cangaroo/poll_job_spec.rb
290
+ - spec/jobs/cangaroo/push_job_spec.rb
291
+ - spec/lib/cangaroo/logger_helper_spec.rb
292
+ - spec/lib/cangaroo/logger_spec.rb
288
293
  - spec/lib/cangaroo/webhook/client_spec.rb
289
294
  - spec/models/cangaroo/connection_spec.rb
290
295
  - spec/rails_helper.rb
296
+ - spec/requests/cangaroo/endpoint_spec.rb
291
297
  - spec/spec_helper.rb
292
298
  - spec/support/database_cleaner.rb
293
299
  - spec/support/factory_girl.rb
300
+ - spec/support/jobs/confirm_order_mail_job.rb
301
+ - spec/support/jobs/erp_job.rb
302
+ - spec/support/jobs/fake_push_job.rb
303
+ - spec/support/jobs/shipped_order_mail_job.rb
304
+ - spec/support/jobs/store_job.rb
305
+ - spec/support/jobs/warehouse_job.rb
294
306
  - spec/support/rails_app.rb
295
307
  - spec/support/shoulda_matchers.rb
296
308
  - spec/support/spec_helpers.rb
@@ -315,34 +327,43 @@ required_rubygems_version: !ruby/object:Gem::Requirement
315
327
  version: '0'
316
328
  requirements: []
317
329
  rubyforge_project:
318
- rubygems_version: 2.6.3
330
+ rubygems_version: 2.6.10
319
331
  signing_key:
320
332
  specification_version: 4
321
333
  summary: Connect Any App to Any Service
322
334
  test_files:
323
- - spec/controllers/cangaroo/endpoint_controller_spec.rb
335
+ - spec/spec_helper.rb
336
+ - spec/features/push_flow_spec.rb
337
+ - spec/models/cangaroo/connection_spec.rb
338
+ - spec/requests/cangaroo/endpoint_spec.rb
339
+ - spec/support/webmock.rb
340
+ - spec/support/rails_app.rb
341
+ - spec/support/shoulda_matchers.rb
342
+ - spec/support/database_cleaner.rb
343
+ - spec/support/jobs/warehouse_job.rb
344
+ - spec/support/jobs/shipped_order_mail_job.rb
345
+ - spec/support/jobs/erp_job.rb
346
+ - spec/support/jobs/confirm_order_mail_job.rb
347
+ - spec/support/jobs/fake_push_job.rb
348
+ - spec/support/jobs/store_job.rb
349
+ - spec/support/spec_helpers.rb
350
+ - spec/support/factory_girl.rb
324
351
  - spec/factories/cangaroo_connections.rb
325
- - spec/fixtures/json_payload_connection_response.json
326
- - spec/fixtures/json_payload_empty.json
327
- - spec/fixtures/json_payload_no_id.json
328
- - spec/fixtures/json_payload_ok.json
352
+ - spec/lib/cangaroo/webhook/client_spec.rb
353
+ - spec/lib/cangaroo/logger_spec.rb
354
+ - spec/lib/cangaroo/logger_helper_spec.rb
329
355
  - spec/fixtures/json_payload_wrong_key.json
356
+ - spec/fixtures/json_payload_ok.json
357
+ - spec/fixtures/json_payload_no_id.json
358
+ - spec/fixtures/json_payload_empty.json
359
+ - spec/fixtures/json_payload_connection_response.json
360
+ - spec/jobs/cangaroo/push_job_spec.rb
361
+ - spec/jobs/cangaroo/poll_job_spec.rb
362
+ - spec/interactors/cangaroo/perform_jobs_spec.rb
363
+ - spec/interactors/cangaroo/validate_json_schema_spec.rb
364
+ - spec/interactors/cangaroo/run_polls_spec.rb
330
365
  - spec/interactors/cangaroo/authenticate_connection_spec.rb
331
366
  - spec/interactors/cangaroo/count_json_object_spec.rb
332
- - spec/interactors/cangaroo/handle_request_spec.rb
333
367
  - spec/interactors/cangaroo/perform_flow_spec.rb
334
- - spec/interactors/cangaroo/perform_jobs_spec.rb
335
- - spec/interactors/cangaroo/run_polls_spec.rb
336
- - spec/interactors/cangaroo/validate_json_schema_spec.rb
337
- - spec/jobs/cangaroo/job_spec.rb
338
- - spec/jobs/cangaroo/poll_job_spec.rb
339
- - spec/lib/cangaroo/webhook/client_spec.rb
340
- - spec/models/cangaroo/connection_spec.rb
368
+ - spec/interactors/cangaroo/handle_request_spec.rb
341
369
  - spec/rails_helper.rb
342
- - spec/spec_helper.rb
343
- - spec/support/database_cleaner.rb
344
- - spec/support/factory_girl.rb
345
- - spec/support/rails_app.rb
346
- - spec/support/shoulda_matchers.rb
347
- - spec/support/spec_helpers.rb
348
- - spec/support/webmock.rb
@@ -1,4 +0,0 @@
1
- module Cangaroo
2
- class ApplicationController < ActionController::Base
3
- end
4
- end