twilio_base 1.8.0

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.
Files changed (179) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +82 -0
  5. data/.ruby-version +1 -0
  6. data/.tool-versions +1 -0
  7. data/Gemfile +8 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +142 -0
  10. data/Rakefile +12 -0
  11. data/app/controllers/twilio_base/base_controller.rb +32 -0
  12. data/app/models/twilio_base/global_config.rb +5 -0
  13. data/app/services/twilio_base/api_key.rb +15 -0
  14. data/app/services/twilio_base/application.rb +29 -0
  15. data/app/services/twilio_base/clients.rb +37 -0
  16. data/app/services/twilio_base/phone_number.rb +40 -0
  17. data/app/services/twilio_base/protocols/voice/base.rb +65 -0
  18. data/app/services/twilio_base/protocols/voice/pstn.rb +13 -0
  19. data/app/services/twilio_base/protocols/voice/sip.rb +48 -0
  20. data/app/services/twilio_base/protocols/voice.rb +24 -0
  21. data/app/services/twilio_base/request_verification_service.rb +21 -0
  22. data/app/services/twilio_base/routers/voice/base.rb +44 -0
  23. data/app/services/twilio_base/routers/voice/default.rb +24 -0
  24. data/app/services/twilio_base/routers/voice/direct_dial.rb +10 -0
  25. data/app/services/twilio_base/routers/voice/task_router.rb +34 -0
  26. data/app/services/twilio_base/sync/service.rb +18 -0
  27. data/app/services/twilio_base/task_router/activity.rb +49 -0
  28. data/app/services/twilio_base/task_router/base.rb +17 -0
  29. data/app/services/twilio_base/task_router/task.rb +33 -0
  30. data/app/services/twilio_base/task_router/task_queue.rb +40 -0
  31. data/app/services/twilio_base/task_router/worker.rb +27 -0
  32. data/app/services/twilio_base/task_router/workflow.rb +22 -0
  33. data/app/services/twilio_base/task_router/workspace.rb +51 -0
  34. data/bin/console +8 -0
  35. data/bin/rails +14 -0
  36. data/bin/setup +6 -0
  37. data/circle.yml +36 -0
  38. data/config/locales/en.yml +2 -0
  39. data/config/routes.rb +4 -0
  40. data/db/migrate/20171214105252_create_twilio_base_global_configs.rb +18 -0
  41. data/lib/twilio_base/engine.rb +7 -0
  42. data/lib/twilio_base/helpers/protocols.rb +12 -0
  43. data/lib/twilio_base/version.rb +5 -0
  44. data/lib/twilio_base.rb +11 -0
  45. data/spec/factories/channel_sid.rb +7 -0
  46. data/spec/factories/chat_member_id.rb +7 -0
  47. data/spec/factories/global_config/activity_sid.rb +7 -0
  48. data/spec/factories/global_config/api_key_secret.rb +7 -0
  49. data/spec/factories/global_config/api_key_sid.rb +7 -0
  50. data/spec/factories/global_config/application_sid.rb +7 -0
  51. data/spec/factories/global_config/chat_service_sid.rb +7 -0
  52. data/spec/factories/global_config/conference_sid.rb +7 -0
  53. data/spec/factories/global_config/message_sid.rb +7 -0
  54. data/spec/factories/global_config/phone_number.rb +7 -0
  55. data/spec/factories/global_config/recording_sid.rb +7 -0
  56. data/spec/factories/global_config/sync_service_sid.rb +7 -0
  57. data/spec/factories/global_config/task_sid.rb +7 -0
  58. data/spec/factories/global_config/voice_call_sid.rb +7 -0
  59. data/spec/factories/global_config/worker_sid.rb +7 -0
  60. data/spec/factories/global_config/workflow_sid.rb +7 -0
  61. data/spec/factories/global_config/workspace_sid.rb +7 -0
  62. data/spec/factories/global_configs.rb +28 -0
  63. data/spec/lib/twilio_base/helpers/protocols_spec.rb +49 -0
  64. data/spec/services/twilio_base/api_key_spec.rb +17 -0
  65. data/spec/services/twilio_base/application_spec.rb +31 -0
  66. data/spec/services/twilio_base/phone_number_spec.rb +49 -0
  67. data/spec/services/twilio_base/protocols/voice/base_spec.rb +134 -0
  68. data/spec/services/twilio_base/protocols/voice/pstn_spec.rb +13 -0
  69. data/spec/services/twilio_base/protocols/voice/sip_spec.rb +104 -0
  70. data/spec/services/twilio_base/protocols/voice_spec.rb +48 -0
  71. data/spec/services/twilio_base/request_verification_service_spec.rb +105 -0
  72. data/spec/services/twilio_base/routers/voice/base_spec.rb +91 -0
  73. data/spec/services/twilio_base/routers/voice/default_spec.rb +59 -0
  74. data/spec/services/twilio_base/routers/voice/task_router_spec.rb +63 -0
  75. data/spec/services/twilio_base/sync/service.rb +25 -0
  76. data/spec/services/twilio_base/task_router/activity_spec.rb +68 -0
  77. data/spec/services/twilio_base/task_router/task_queue_spec.rb +114 -0
  78. data/spec/services/twilio_base/task_router/worker_spec.rb +49 -0
  79. data/spec/services/twilio_base/task_router/workflow_spec.rb +37 -0
  80. data/spec/spec_helper.rb +68 -0
  81. data/spec/support/factory_bot.rb +9 -0
  82. data/spec/support/shared_contexts/global_config.rb +6 -0
  83. data/spec/support/shared_contexts/twilio_controller.rb +7 -0
  84. data/spec/support/twilio_base/fake/api_key.rb +26 -0
  85. data/spec/support/twilio_base/fake/application.rb +59 -0
  86. data/spec/support/twilio_base/fake/available_phone_number.rb +29 -0
  87. data/spec/support/twilio_base/fake/chat/channel.rb +63 -0
  88. data/spec/support/twilio_base/fake/chat/client.rb +40 -0
  89. data/spec/support/twilio_base/fake/chat/member.rb +27 -0
  90. data/spec/support/twilio_base/fake/chat/message.rb +47 -0
  91. data/spec/support/twilio_base/fake/chat/service.rb +52 -0
  92. data/spec/support/twilio_base/fake/clients/rest.rb +84 -0
  93. data/spec/support/twilio_base/fake/clients/sms.rb +27 -0
  94. data/spec/support/twilio_base/fake/conference.rb +48 -0
  95. data/spec/support/twilio_base/fake/flex_flow.rb +36 -0
  96. data/spec/support/twilio_base/fake/helpers.rb +38 -0
  97. data/spec/support/twilio_base/fake/incoming_phone_number.rb +46 -0
  98. data/spec/support/twilio_base/fake/lookup/client.rb +29 -0
  99. data/spec/support/twilio_base/fake/lookup/phone_number.rb +34 -0
  100. data/spec/support/twilio_base/fake/notify/binding.rb +41 -0
  101. data/spec/support/twilio_base/fake/notify/notification.rb +40 -0
  102. data/spec/support/twilio_base/fake/notify/segment_membership.rb +17 -0
  103. data/spec/support/twilio_base/fake/notify/user.rb +30 -0
  104. data/spec/support/twilio_base/fake/notify/v1.rb +33 -0
  105. data/spec/support/twilio_base/fake/proxy.rb +30 -0
  106. data/spec/support/twilio_base/fake/recording.rb +44 -0
  107. data/spec/support/twilio_base/fake/sync/client.rb +17 -0
  108. data/spec/support/twilio_base/fake/sync/service.rb +78 -0
  109. data/spec/support/twilio_base/fake/sync/services/document.rb +50 -0
  110. data/spec/support/twilio_base/fake/sync/services/list.rb +50 -0
  111. data/spec/support/twilio_base/fake/sync/services/lists/item.rb +48 -0
  112. data/spec/support/twilio_base/fake/sync/services/map.rb +50 -0
  113. data/spec/support/twilio_base/fake/sync/services/maps/item.rb +54 -0
  114. data/spec/support/twilio_base/fake/task_router/activity.rb +34 -0
  115. data/spec/support/twilio_base/fake/task_router/channel.rb +40 -0
  116. data/spec/support/twilio_base/fake/task_router/client.rb +31 -0
  117. data/spec/support/twilio_base/fake/task_router/statistic.rb +38 -0
  118. data/spec/support/twilio_base/fake/task_router/task.rb +80 -0
  119. data/spec/support/twilio_base/fake/task_router/task_queue.rb +46 -0
  120. data/spec/support/twilio_base/fake/task_router/worker.rb +64 -0
  121. data/spec/support/twilio_base/fake/task_router/workflow.rb +54 -0
  122. data/spec/support/twilio_base/fake/task_router/workspace.rb +83 -0
  123. data/spec/support/twilio_base/fake/voice_call.rb +54 -0
  124. data/spec/support/twilio_base/responses/twiml.rb +29 -0
  125. data/spec/twilio_base_dummy/.gitignore +21 -0
  126. data/spec/twilio_base_dummy/Rakefile +5 -0
  127. data/spec/twilio_base_dummy/app/assets/config/manifest.js +0 -0
  128. data/spec/twilio_base_dummy/app/channels/application_cable/channel.rb +6 -0
  129. data/spec/twilio_base_dummy/app/channels/application_cable/connection.rb +6 -0
  130. data/spec/twilio_base_dummy/app/controllers/application_controller.rb +5 -0
  131. data/spec/twilio_base_dummy/app/controllers/concerns/.keep +0 -0
  132. data/spec/twilio_base_dummy/app/helpers/application_helper.rb +4 -0
  133. data/spec/twilio_base_dummy/bin/bundle +5 -0
  134. data/spec/twilio_base_dummy/bin/rails +11 -0
  135. data/spec/twilio_base_dummy/bin/rake +11 -0
  136. data/spec/twilio_base_dummy/bin/setup +36 -0
  137. data/spec/twilio_base_dummy/bin/spring +18 -0
  138. data/spec/twilio_base_dummy/bin/update +31 -0
  139. data/spec/twilio_base_dummy/config/application.rb +13 -0
  140. data/spec/twilio_base_dummy/config/boot.rb +7 -0
  141. data/spec/twilio_base_dummy/config/cable.yml +5 -0
  142. data/spec/twilio_base_dummy/config/database.example.yml +13 -0
  143. data/spec/twilio_base_dummy/config/environment.rb +5 -0
  144. data/spec/twilio_base_dummy/config/environments/development.rb +28 -0
  145. data/spec/twilio_base_dummy/config/environments/test.rb +17 -0
  146. data/spec/twilio_base_dummy/config/initializers/application_controller_renderer.rb +1 -0
  147. data/spec/twilio_base_dummy/config/initializers/assets.rb +3 -0
  148. data/spec/twilio_base_dummy/config/initializers/backtrace_silencers.rb +1 -0
  149. data/spec/twilio_base_dummy/config/initializers/cookies_serializer.rb +3 -0
  150. data/spec/twilio_base_dummy/config/initializers/filter_parameter_logging.rb +3 -0
  151. data/spec/twilio_base_dummy/config/initializers/inflections.rb +1 -0
  152. data/spec/twilio_base_dummy/config/initializers/mime_types.rb +1 -0
  153. data/spec/twilio_base_dummy/config/initializers/new_framework_defaults.rb +9 -0
  154. data/spec/twilio_base_dummy/config/initializers/session_store.rb +3 -0
  155. data/spec/twilio_base_dummy/config/initializers/wrap_parameters.rb +5 -0
  156. data/spec/twilio_base_dummy/config/locales/en.yml +23 -0
  157. data/spec/twilio_base_dummy/config/puma.rb +7 -0
  158. data/spec/twilio_base_dummy/config/routes.rb +5 -0
  159. data/spec/twilio_base_dummy/config/secrets.yml +10 -0
  160. data/spec/twilio_base_dummy/config/spring.rb +8 -0
  161. data/spec/twilio_base_dummy/config.ru +7 -0
  162. data/spec/twilio_base_dummy/db/schema.rb +31 -0
  163. data/spec/twilio_base_dummy/db/seeds.rb +1 -0
  164. data/spec/twilio_base_dummy/lib/assets/.keep +0 -0
  165. data/spec/twilio_base_dummy/lib/tasks/.keep +0 -0
  166. data/spec/twilio_base_dummy/log/.keep +0 -0
  167. data/spec/twilio_base_dummy/public/404.html +67 -0
  168. data/spec/twilio_base_dummy/public/422.html +67 -0
  169. data/spec/twilio_base_dummy/public/500.html +66 -0
  170. data/spec/twilio_base_dummy/public/apple-touch-icon-precomposed.png +0 -0
  171. data/spec/twilio_base_dummy/public/apple-touch-icon.png +0 -0
  172. data/spec/twilio_base_dummy/public/favicon.ico +0 -0
  173. data/spec/twilio_base_dummy/public/robots.txt +5 -0
  174. data/spec/twilio_base_dummy/tmp/.keep +0 -0
  175. data/spec/twilio_base_dummy/vendor/assets/javascripts/.keep +0 -0
  176. data/spec/twilio_base_dummy/vendor/assets/stylesheets/.keep +0 -0
  177. data/spec/twilio_base_spec.rb +7 -0
  178. data/twilio_base.gemspec +45 -0
  179. metadata +580 -0
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ class Proxy
6
+ Proxy = Struct.new(:attributes) do
7
+ def unique_name
8
+ attributes[:unique_name]
9
+ end
10
+ end
11
+
12
+ cattr_accessor :proxies
13
+ self.proxies = []
14
+
15
+ def create(attributes)
16
+ proxy = Proxy.new(attributes)
17
+ self.class.proxies << proxy
18
+ proxy
19
+ end
20
+
21
+ def services
22
+ self
23
+ end
24
+
25
+ def list
26
+ proxies
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ class Recording
6
+ Recording = Struct.new(:sid, :attributes) do
7
+ def update(attributes)
8
+ self.attributes.merge! attributes
9
+
10
+ self
11
+ end
12
+ end
13
+
14
+ cattr_accessor :recordings, :sid
15
+ self.recordings = []
16
+
17
+ def initialize(sid = nil)
18
+ self.sid = sid || FactoryBot.generate(:recording_sid)
19
+ end
20
+
21
+ def create(args = {})
22
+ Recording.new(sid, args).tap do |recording|
23
+ recordings << recording
24
+ end
25
+ end
26
+
27
+ def list(attributes = {})
28
+ recordings.select do |recording|
29
+ recording.attributes.slice(*attributes.keys) == attributes
30
+ end
31
+ end
32
+
33
+ def fetch
34
+ recordings.detect { |recording| recording.sid == sid }
35
+ end
36
+
37
+ def update(attrs = {})
38
+ return fetch.update(attrs) if fetch.present?
39
+
40
+ create(attrs)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module Sync
6
+ class Client
7
+ def v1
8
+ self
9
+ end
10
+
11
+ def services(sid = nil)
12
+ Fake::Sync::Service.new(sid)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module Sync
6
+ class Service
7
+ Service = Struct.new(:friendly_name) do
8
+ def sid
9
+ @sid ||= FactoryBot.generate(:sync_service_sid)
10
+ end
11
+
12
+ def create(friendly_name: '')
13
+ self.friendly_name = friendly_name
14
+ end
15
+
16
+ def documents
17
+ Fake::Sync::Services::Document.new
18
+ end
19
+
20
+ def sync_lists
21
+ Fake::Sync::Services::List.new
22
+ end
23
+
24
+ def sync_maps
25
+ Fake::Sync::Services::Map.new
26
+ end
27
+ end
28
+
29
+ cattr_accessor :services
30
+ self.services = []
31
+
32
+ def initialize(sid = nil)
33
+ self.sid = sid
34
+ end
35
+
36
+ def create(friendly_name: '')
37
+ service = Service.new(
38
+ friendly_name: friendly_name
39
+ )
40
+ self.class.services << service
41
+ service
42
+ end
43
+
44
+ def services(unique_name = nil)
45
+ Service.new(unique_name || rand(999).to_s)
46
+ end
47
+
48
+ def documents(document_unique_name = nil)
49
+ Fake::Sync::Services::Document.new(unique_name: document_unique_name)
50
+ end
51
+
52
+ def sync_lists(list_unique_name = nil)
53
+ Fake::Sync::Services::List.new(unique_name: list_unique_name)
54
+ end
55
+
56
+ def sync_maps(map_unique_name = nil)
57
+ Fake::Sync::Services::Map.new(unique_name: map_unique_name)
58
+ end
59
+
60
+ def v1
61
+ self
62
+ end
63
+
64
+ private
65
+
66
+ attr_accessor :sid
67
+
68
+ def method_missing(_name)
69
+ self || super
70
+ end
71
+
72
+ def respond_to_missing?(method_name)
73
+ super
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module Sync
6
+ module Services
7
+ class Document
8
+ cattr_accessor :documents
9
+ self.documents = []
10
+
11
+ def initialize(data: {}, ttl: '', unique_name: '')
12
+ self.data = data
13
+ self.ttl = ttl
14
+ self.unique_name = unique_name
15
+ end
16
+
17
+ attr_accessor :data, :ttl, :unique_name
18
+
19
+ def create(data: {}, ttl: '', unique_name: '')
20
+ document = Document.new(
21
+ data: data,
22
+ ttl: ttl,
23
+ unique_name: unique_name
24
+ )
25
+ self.class.documents << document
26
+ document
27
+ end
28
+
29
+ def fetch
30
+ matched_document = self.class.documents.detect do |document|
31
+ document.unique_name == unique_name
32
+ end
33
+
34
+ raise ArgumentError if matched_document.blank?
35
+
36
+ matched_document
37
+ end
38
+
39
+ def documents(unique_name = nil)
40
+ Document.new(unique_name || rand(999).to_s)
41
+ end
42
+
43
+ def update(params)
44
+ params[:data]
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module Sync
6
+ module Services
7
+ class List
8
+ cattr_accessor :lists
9
+ self.lists = []
10
+
11
+ attr_accessor :data, :ttl, :unique_name
12
+
13
+ def initialize(data: {}, ttl: '', unique_name: '')
14
+ self.data = data
15
+ self.ttl = ttl
16
+ self.unique_name = unique_name
17
+ end
18
+
19
+ def create(data: {}, ttl: '', unique_name: '')
20
+ list = List.new(
21
+ data: data,
22
+ ttl: ttl,
23
+ unique_name: unique_name
24
+ )
25
+ self.class.lists << list
26
+ list
27
+ end
28
+
29
+ def fetch
30
+ matched_list = self.class.lists.detect do |list|
31
+ list.unique_name == unique_name
32
+ end
33
+
34
+ raise ArgumentError if matched_list.blank?
35
+
36
+ matched_list
37
+ end
38
+
39
+ def lists(unique_name = nil)
40
+ List.new(unique_name || rand(999).to_s)
41
+ end
42
+
43
+ def sync_list_items
44
+ Fake::Sync::Services::Lists::Item.new
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module Sync
6
+ module Services
7
+ module Lists
8
+ class Item
9
+ Item = Struct.new(:data) do
10
+ attr_accessor :sid
11
+
12
+ def create(data: {})
13
+ self.data = data
14
+ end
15
+ end
16
+
17
+ cattr_accessor :items
18
+ self.items = []
19
+
20
+ def initialize(sid = nil)
21
+ self.sid = sid
22
+ end
23
+
24
+ def create(data: {})
25
+ item = Item.new(
26
+ data: data
27
+ )
28
+ self.class.items << item
29
+ item
30
+ end
31
+
32
+ private
33
+
34
+ attr_accessor :sid
35
+
36
+ def method_missing(_name)
37
+ self || super
38
+ end
39
+
40
+ def respond_to_missing?(method_name)
41
+ super
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module Sync
6
+ module Services
7
+ class Map
8
+ cattr_accessor :maps
9
+ self.maps = {}
10
+
11
+ attr_accessor :data, :ttl, :unique_name
12
+
13
+ def initialize(data: {}, ttl: '', unique_name: '')
14
+ self.data = data
15
+ self.ttl = ttl
16
+ self.unique_name = unique_name
17
+ end
18
+
19
+ def create(data: {}, ttl: '', unique_name: '')
20
+ map = Map.new(
21
+ data: data,
22
+ ttl: ttl,
23
+ unique_name: unique_name
24
+ )
25
+ self.class.maps << map
26
+ map
27
+ end
28
+
29
+ def fetch
30
+ matched_map = self.class.maps.detect do |map|
31
+ map.unique_name == unique_name
32
+ end
33
+
34
+ raise ArgumentError if matched_map.blank?
35
+
36
+ matched_map
37
+ end
38
+
39
+ def maps(unique_name = nil)
40
+ Map.new(unique_name || rand(999).to_s)
41
+ end
42
+
43
+ def sync_map_items
44
+ Fake::Sync::Services::Maps::Item.new
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module Sync
6
+ module Services
7
+ module Maps
8
+ class Item
9
+ Map = Struct.new(:data, :key) do
10
+ attr_accessor :sid
11
+
12
+ def create(data: {}, key: '')
13
+ self.data = data
14
+ self.key = key
15
+ end
16
+
17
+ def update(data: {})
18
+ self.data = data
19
+ end
20
+ end
21
+
22
+ cattr_accessor :items
23
+ self.items = []
24
+
25
+ def initialize(sid = nil)
26
+ self.sid = sid
27
+ end
28
+
29
+ def create(data: {}, key: '')
30
+ item = Map.new(
31
+ data: data,
32
+ key: key
33
+ )
34
+ self.class.items << item
35
+ item
36
+ end
37
+
38
+ private
39
+
40
+ attr_accessor :sid
41
+
42
+ def method_missing(_name)
43
+ self || super
44
+ end
45
+
46
+ def respond_to_missing?(method_name)
47
+ super
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module TaskRouter
6
+ class Activity
7
+ Activity = Struct.new(:friendly_name) do
8
+ def sid
9
+ @sid ||= ::FactoryBot.generate(:activity_sid)
10
+ end
11
+ end
12
+
13
+ cattr_accessor :activities
14
+ self.activities = []
15
+
16
+ def create(friendly_name:)
17
+ activity = Activity.new(friendly_name)
18
+ self.class.activities << activity
19
+ activity
20
+ end
21
+
22
+ def list(friendly_name: nil)
23
+ if friendly_name
24
+ self.class.activities.select do |activity|
25
+ activity.friendly_name == friendly_name
26
+ end
27
+ else
28
+ self.class.activities
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module TaskRouter
6
+ class Channel
7
+ Channel = Struct.new(:name, :attributes) do
8
+ def sid
9
+ @sid ||= FactoryBot.generate(channel_sid)
10
+ end
11
+
12
+ def capacity
13
+ attributes[:capacity]
14
+ end
15
+
16
+ def update(attributes)
17
+ self.attributes = attributes
18
+ end
19
+ end
20
+
21
+ cattr_accessor :channels, :name
22
+ self.channels = []
23
+
24
+ def initialize(name = nil)
25
+ self.name = name
26
+ end
27
+
28
+ def create(name, attributes = nil)
29
+ channel = Channel.new(name, attributes)
30
+ self.class.channels << channel
31
+ channel
32
+ end
33
+
34
+ def fetch
35
+ channels.detect { |channel| channel.name == name }
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module TaskRouter
6
+ class Client
7
+ def initialize(_account_sid, _auth_token); end
8
+
9
+ def v1
10
+ self
11
+ end
12
+
13
+ def workspaces(sid = nil)
14
+ Fake::TaskRouter::Workspace.new(sid)
15
+ end
16
+
17
+ def tasks(sid = nil)
18
+ @tasks ||= Fake::TaskRouter::Task.new(sid)
19
+ end
20
+
21
+ def workers
22
+ Fake::TaskRouter::Worker.new
23
+ end
24
+
25
+ def activities
26
+ Fake::TaskRouter::Activity.new
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module TaskRouter
6
+ class Statistic
7
+ Statistic = Struct.new(:sid, :realtime) do
8
+ def update(_attributes = {})
9
+ self
10
+ end
11
+ end
12
+
13
+ cattr_accessor :attrs, :sid, :statistics
14
+ self.statistics = []
15
+
16
+ def initialize(sid = nil, attrs = {})
17
+ self.sid = sid
18
+ self.attrs = attrs
19
+ end
20
+
21
+ def create
22
+ statistic = Statistic.new(
23
+ sid,
24
+ attrs[:realtime]
25
+ )
26
+ self.class.statistics << statistic
27
+ statistic
28
+ end
29
+
30
+ def fetch
31
+ create
32
+
33
+ statistics.detect { |statistic| statistic.sid == sid }
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module TaskRouter
6
+ class Task
7
+ Task = Struct.new(
8
+ :sid,
9
+ :workflow_sid,
10
+ :task_channel,
11
+ :attributes,
12
+ :age,
13
+ :priority,
14
+ :task_queue_friendly_name,
15
+ :timeout
16
+ ) do
17
+ def assignment_status
18
+ JSON.parse(attributes)['assignment_status']
19
+ end
20
+
21
+ def delete
22
+ TwilioBase::Fake::TaskRouter::Task.tasks -= [self]
23
+ end
24
+
25
+ def task_channel_unique_name
26
+ task_channel&.name
27
+ end
28
+
29
+ def update(params = {})
30
+ self.attributes = params.to_json
31
+ end
32
+
33
+ def update(params)
34
+ attributes = JSON.parse(params[:attributes] || '{}')
35
+ self.attributes = attributes.merge(params.except(:attributes))
36
+ .to_json
37
+ end
38
+ end
39
+
40
+ cattr_accessor :sid, :tasks
41
+ self.tasks = []
42
+
43
+ def initialize(sid = nil)
44
+ self.sid = sid || FactoryBot.generate(:task_sid)
45
+ end
46
+
47
+ def create(attributes)
48
+ task = Task.new(
49
+ sid,
50
+ attributes[:workflow_sid],
51
+ attributes[:task_channel],
52
+ task_attributes(attributes),
53
+ attributes[:age],
54
+ attributes[:priority],
55
+ attributes[:task_queue_friendly_name],
56
+ attributes[:timeout]
57
+ )
58
+ self.class.tasks << task
59
+ task
60
+ end
61
+
62
+ def task_attributes(attributes)
63
+ if attributes[:attributes].present?
64
+ attributes[:attributes]
65
+ else
66
+ { assignment_status: 'reserved' }.to_json
67
+ end
68
+ end
69
+
70
+ def list(_attributes = {})
71
+ tasks
72
+ end
73
+
74
+ def fetch
75
+ tasks.detect { |task| task.sid == sid }
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module TaskRouter
6
+ class TaskQueue
7
+ TaskQueue = Struct.new(:attributes) do
8
+ def assignment_activity_sid
9
+ attributes[:assignment_activity_sid]
10
+ end
11
+
12
+ def friendly_name
13
+ attributes[:friendly_name]
14
+ end
15
+
16
+ def reservation_activity_sid
17
+ attributes[:reservation_activity_sid]
18
+ end
19
+
20
+ def update(params)
21
+ self.attributes = params.to_json
22
+ end
23
+ end
24
+
25
+ cattr_accessor :task_queues
26
+ self.task_queues = []
27
+
28
+ def create(attributes)
29
+ task_queue = TaskQueue.new(attributes)
30
+ self.class.task_queues << task_queue
31
+ task_queue
32
+ end
33
+
34
+ def list(friendly_name: nil)
35
+ if friendly_name
36
+ task_queues.select do |task_queue|
37
+ task_queue.friendly_name == friendly_name
38
+ end
39
+ else
40
+ task_queues
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end