twilio_base 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
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,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module Chat
6
+ class Client
7
+ cattr_accessor :members, :messages
8
+ self.members = []
9
+ self.messages = []
10
+
11
+ def initialize(_account_sid, _auth_token); end
12
+
13
+ def chat
14
+ self
15
+ end
16
+
17
+ def v2
18
+ self
19
+ end
20
+
21
+ def services(service_sid = nil)
22
+ TwilioBase::Fake::Chat::Service.new(service_sid)
23
+ end
24
+
25
+ def channels(channel_id = nil)
26
+ TwilioBase::Fake::Chat::Channel.new(channel_id)
27
+ end
28
+
29
+ def create_task(sender_number:, receiving_number:, claim_id:)
30
+ TwilioBase::Fake::TaskRouter::Task.new
31
+ .create(attributes: {
32
+ sender_number: sender_number,
33
+ receiving_number: receiving_number,
34
+ claim_id: claim_id
35
+ })
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module Chat
6
+ class Member
7
+ Member = Struct.new(:attributes) do
8
+ def identity
9
+ JSON.parse(attributes)['identity']
10
+ end
11
+ end
12
+
13
+ cattr_accessor :members
14
+ self.members = []
15
+
16
+ def create(attributes)
17
+ self.class.members << Member.new(attributes)
18
+ self
19
+ end
20
+
21
+ def list
22
+ members
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module Chat
6
+ class Message
7
+ Message = Struct.new(:attributes) do
8
+ def sid
9
+ @sid ||= Time.now.to_i
10
+ end
11
+
12
+ def created_at
13
+ Time.now
14
+ end
15
+
16
+ def date_created
17
+ 2.days.ago
18
+ end
19
+
20
+ def body
21
+ attributes[:body]
22
+ end
23
+
24
+ def from
25
+ attributes[:from]
26
+ end
27
+
28
+ def to
29
+ attributes[:to]
30
+ end
31
+ end
32
+
33
+ cattr_accessor :messages
34
+ self.messages = []
35
+
36
+ def create(attributes)
37
+ self.class.messages << Message.new(attributes)
38
+ self
39
+ end
40
+
41
+ def list
42
+ self.class.messages
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module Chat
6
+ class Service
7
+ Service = Struct.new(:friendly_name) do
8
+ attr_accessor :webhook_filters, :post_webhook_url
9
+
10
+ def sid
11
+ @sid ||= TwilioBase::GlobalConfig.first&.chat_service_sid ||
12
+ FactoryBot.generate(:chat_service_sid)
13
+ end
14
+
15
+ def update(post_webhook_url:, webhook_filters: nil)
16
+ self.post_webhook_url = post_webhook_url
17
+ self.webhook_filters = webhook_filters if webhook_filters
18
+ end
19
+ end
20
+
21
+ cattr_accessor :services
22
+ self.services = []
23
+
24
+ def initialize(service_sid = nil)
25
+ self.service_sid = service_sid
26
+ end
27
+
28
+ def create(friendly_name:)
29
+ service = Service.new(friendly_name)
30
+ self.class.services << service
31
+ service
32
+ end
33
+
34
+ def channels(channel_id = nil)
35
+ TwilioBase::Fake::Chat::Channel.new(channel_id)
36
+ end
37
+
38
+ def fetch
39
+ services.detect { |service| service.sid == service_sid }
40
+ end
41
+
42
+ def list
43
+ services
44
+ end
45
+
46
+ private
47
+
48
+ attr_accessor :service_sid
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module Clients
6
+ class Rest
7
+ Message = Struct.new(:from, :to, :body)
8
+
9
+ cattr_accessor :messages
10
+ self.messages = []
11
+
12
+ def initialize(_account_sid = nil, _auth_token = nil); end
13
+
14
+ def messages
15
+ self
16
+ end
17
+
18
+ def create(from:, to:, body:)
19
+ self.class.messages << Message.new(from, to, body)
20
+ end
21
+
22
+ def taskrouter
23
+ TwilioBase::Fake::TaskRouter::Client.new(nil, nil)
24
+ end
25
+
26
+ def calls(sid = nil)
27
+ TwilioBase::Fake::VoiceCall.new(sid)
28
+ end
29
+
30
+ def chat
31
+ TwilioBase::Fake::Chat::Client.new(nil, nil)
32
+ end
33
+
34
+ def conferences(conference_sid = nil)
35
+ TwilioBase::Fake::Conference.new(conference_sid)
36
+ end
37
+
38
+ def flex_flow
39
+ TwilioBase::Fake::FlexFlow.new
40
+ end
41
+
42
+ def new_keys
43
+ TwilioBase::Fake::ApiKey.new
44
+ end
45
+
46
+ def proxy
47
+ TwilioBase::Fake::Proxy.new
48
+ end
49
+
50
+ def applications(sid = nil)
51
+ TwilioBase::Fake::Application.new(sid)
52
+ end
53
+
54
+ def available_phone_numbers(country_code)
55
+ TwilioBase::Fake::AvailablePhoneNumber.new(country_code)
56
+ end
57
+
58
+ def incoming_phone_numbers
59
+ TwilioBase::Fake::IncomingPhoneNumber.new
60
+ end
61
+
62
+ def lookups
63
+ TwilioBase::Fake::Lookup::Client.new(nil, nil)
64
+ end
65
+
66
+ def sync
67
+ TwilioBase::Fake::Sync::Client.new
68
+ end
69
+
70
+ def services(sid = nil)
71
+ TwilioBase::Fake::Notify::V1.new(sid)
72
+ end
73
+
74
+ def method_missing(_name)
75
+ self || super
76
+ end
77
+
78
+ def respond_to_missing?(method_name)
79
+ super
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module Clients
6
+ class Sms
7
+ Message = Struct.new(:from, :to, :body)
8
+
9
+ cattr_accessor :messages
10
+ self.messages = []
11
+
12
+ def messages
13
+ self
14
+ end
15
+
16
+ def create(from:, to:, body:)
17
+ self.class.messages << Message.new(from, to, body)
18
+ self.class.messages.last
19
+ end
20
+
21
+ def list(_attributes = {})
22
+ self.class.messages
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ class Conference
6
+ Conference = Struct.new(:attributes) do
7
+ def sid
8
+ @sid ||= FactoryBot.generate(:conference_sid)
9
+ end
10
+
11
+ def status
12
+ attributes[:status]
13
+ end
14
+
15
+ def update(attributes)
16
+ self.attributes = attributes
17
+ end
18
+ end
19
+
20
+ cattr_accessor :conferences, :sid
21
+ self.conferences = []
22
+
23
+ def initialize(sid = nil)
24
+ self.sid = sid
25
+ end
26
+
27
+ def create(args = {})
28
+ conference = Conference.new(args)
29
+ conferences << conference
30
+ conference
31
+ end
32
+
33
+ def participants(sid = nil)
34
+ TwilioBase::Fake::VoiceCall.new(sid)
35
+ end
36
+
37
+ def list(attributes = {})
38
+ conferences.select do |conference|
39
+ conference.attributes.slice(*attributes.keys) == attributes
40
+ end
41
+ end
42
+
43
+ def fetch
44
+ conferences.detect { |conference| conference.sid == sid }
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ class FlexFlow
6
+ FlexFlow = Struct.new(:attributes) do
7
+ def channel_type
8
+ attributes[:channel_type]
9
+ end
10
+
11
+ def contact_identity
12
+ attributes[:contact_identity]
13
+ end
14
+
15
+ def update(update_attributes)
16
+ attributes.merge(update_attributes)
17
+
18
+ self
19
+ end
20
+ end
21
+
22
+ cattr_accessor :flex_flows
23
+ self.flex_flows = []
24
+
25
+ def create(args = {})
26
+ flex_flow = FlexFlow.new(args)
27
+ flex_flows << flex_flow
28
+ flex_flow
29
+ end
30
+
31
+ def list
32
+ flex_flows
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module Helpers
6
+ def clean_cache
7
+ TwilioBase::Fake::ApiKey.keys = []
8
+ TwilioBase::Fake::Application.applications = []
9
+ TwilioBase::Fake::AvailablePhoneNumber.phone_numbers = []
10
+ TwilioBase::Fake::Chat::Channel.channels = []
11
+ TwilioBase::Fake::Chat::Member.members = []
12
+ TwilioBase::Fake::Chat::Message.messages = []
13
+ TwilioBase::Fake::Chat::Service.services = []
14
+ TwilioBase::Fake::Clients::Rest.messages = []
15
+ TwilioBase::Fake::Clients::Sms.messages = []
16
+ TwilioBase::Fake::FlexFlow.flex_flows = []
17
+ TwilioBase::Fake::IncomingPhoneNumber.phone_numbers = []
18
+ TwilioBase::Fake::Notify::Binding.bindings = []
19
+ TwilioBase::Fake::Notify::SegmentMembership.memberships = []
20
+ TwilioBase::Fake::Notify::User.users = []
21
+ TwilioBase::Fake::Notify::V1.all_notifications = []
22
+ TwilioBase::Fake::Proxy.proxies = []
23
+ TwilioBase::Fake::Sync::Services::Document.documents = []
24
+ TwilioBase::Fake::Sync::Services::List.lists = []
25
+ TwilioBase::Fake::Sync::Services::Map.maps = []
26
+ TwilioBase::Fake::TaskRouter::Activity.activities = []
27
+ TwilioBase::Fake::TaskRouter::Channel.channels = []
28
+ TwilioBase::Fake::TaskRouter::Task.tasks = []
29
+ TwilioBase::Fake::TaskRouter::TaskQueue.task_queues = []
30
+ TwilioBase::Fake::TaskRouter::Worker.workers = []
31
+ TwilioBase::Fake::TaskRouter::Workflow.workflows = []
32
+ TwilioBase::Fake::TaskRouter::Workspace.workspaces = []
33
+ TwilioBase::Fake::VoiceCall.calls = []
34
+ end
35
+ module_function :clean_cache
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ class IncomingPhoneNumber
6
+ PhoneNumber = Struct.new(:phone_number) do
7
+ attr_accessor :attributes
8
+
9
+ def update(attributes)
10
+ self.attributes = attributes
11
+ end
12
+
13
+ def sms_application_sid
14
+ attributes[:sms_application_sid]
15
+ end
16
+
17
+ def voice_application_sid
18
+ attributes[:voice_application_sid]
19
+ end
20
+ end
21
+
22
+ cattr_accessor :phone_numbers
23
+ self.phone_numbers = []
24
+
25
+ def phone_numbers
26
+ self
27
+ end
28
+
29
+ def create(phone_number:)
30
+ new_phone_number = PhoneNumber.new(phone_number)
31
+ self.class.phone_numbers << new_phone_number
32
+ new_phone_number
33
+ end
34
+
35
+ def list(phone_number: nil)
36
+ if phone_number.present?
37
+ self.class.phone_numbers.select do |pn|
38
+ pn.phone_number == phone_number
39
+ end
40
+ else
41
+ self.class.phone_numbers
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module Lookup
6
+ class Client
7
+ class RestError < StandardError
8
+ def code
9
+ 20_404
10
+ end
11
+ end
12
+
13
+ def initialize(_account_sid, _auth_token); end
14
+
15
+ def v1
16
+ self
17
+ end
18
+
19
+ def phone_numbers(phone_number = nil)
20
+ if phone_number.to_s.length < 10
21
+ raise RestError, '[HTTP 404] 20404 : Unable to fetch record'
22
+ end
23
+
24
+ TwilioBase::Fake::Lookup::PhoneNumber.new(phone_number)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module Lookup
6
+ class PhoneNumber
7
+ PhoneNumberInstance = Struct.new(
8
+ :attributes,
9
+ :phone_number,
10
+ :national_format,
11
+ :caller_name,
12
+ :carrier,
13
+ :country_code
14
+ ) do
15
+ def carrier
16
+ {
17
+ 'type' => 'mobile'
18
+ }
19
+ end
20
+ end
21
+
22
+ attr_accessor :phone_number
23
+
24
+ def initialize(phone_number)
25
+ self.phone_number = phone_number
26
+ end
27
+
28
+ def fetch(attributes = {})
29
+ PhoneNumberInstance.new(attributes, phone_number)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module Notify
6
+ class Binding
7
+ attr_accessor :sid
8
+ cattr_accessor :bindings
9
+ BindingObject = Struct.new(
10
+ :address,
11
+ :binding_type,
12
+ :identity,
13
+ :tag,
14
+ :sid
15
+ )
16
+
17
+ self.bindings = []
18
+
19
+ def initialize(sid = nil)
20
+ self.sid = sid
21
+ end
22
+
23
+ def create(attributes)
24
+ attributes[:sid] = SecureRandom.hex(16)
25
+ object = BindingObject.new(*attributes.values)
26
+ bindings << object
27
+ TwilioBase::Fake::Notify::User.users << object
28
+ object
29
+ end
30
+
31
+ def delete
32
+ bindings.delete_if { |binding| binding.sid == sid }
33
+ end
34
+
35
+ def list(*)
36
+ bindings
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module Notify
6
+ class Notification
7
+ attr_accessor :sid
8
+
9
+ NotificationInstance = Struct.new(
10
+ :account_sid,
11
+ :action,
12
+ :alexa,
13
+ :apn,
14
+ :body,
15
+ :data,
16
+ :date_created,
17
+ :facebook_messenger,
18
+ :fcm,
19
+ :gcm,
20
+ :identities,
21
+ :priority,
22
+ :segments,
23
+ :service_sid,
24
+ :sid,
25
+ :sms,
26
+ :sound,
27
+ :tags,
28
+ :title,
29
+ :ttl
30
+ )
31
+
32
+ def initialize(_attributes = {})
33
+ NotificationInstance.new(
34
+ sid: SecureRandom.hex(16)
35
+ )
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module Notify
6
+ class SegmentMembership
7
+ cattr_accessor :memberships
8
+
9
+ self.memberships = []
10
+
11
+ def create(attributes)
12
+ memberships << attributes
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module Notify
6
+ class User
7
+ attr_accessor :identity
8
+ cattr_accessor :users
9
+
10
+ self.users = []
11
+
12
+ def initialize(identity = nil)
13
+ self.identity = identity
14
+ end
15
+
16
+ def create(attributes)
17
+ users << attributes.merge(sid: SecureRandom.hex(16))
18
+ end
19
+
20
+ def delete
21
+ users.delete_if { |user| user.address == identity }
22
+ end
23
+
24
+ def segment_memberships
25
+ TwilioBase::Fake::Notify::SegmentMembership.new
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Fake
5
+ module Notify
6
+ class V1
7
+ cattr_accessor :all_notifications
8
+
9
+ self.all_notifications = []
10
+
11
+ def initialize(_notify_service_sid = nil); end
12
+
13
+ def notifications
14
+ self
15
+ end
16
+
17
+ def create(attributes)
18
+ all_notifications << attributes
19
+
20
+ TwilioBase::Fake::Notify::Notification.new
21
+ end
22
+
23
+ def bindings(sid = nil)
24
+ TwilioBase::Fake::Notify::Binding.new(sid)
25
+ end
26
+
27
+ def users(sid = nil)
28
+ TwilioBase::Fake::Notify::User.new(sid)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end