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,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Routers
5
+ module Voice
6
+ module Default
7
+ module_function
8
+
9
+ def init(protocol:, routing_method: nil)
10
+ routing_method ||= ENV.fetch('ROUTING_METHOD')
11
+
12
+ klass = {
13
+ 'direct_dial' => TwilioBase::Routers::Voice::DirectDial,
14
+ 'task_router' => TwilioBase::Routers::Voice::TaskRouter
15
+ }.fetch(routing_method, TwilioBase::Routers::Voice::DirectDial)
16
+
17
+ klass.new(
18
+ protocol: protocol
19
+ )
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Routers
5
+ module Voice
6
+ class DirectDial < Base
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Routers
5
+ module Voice
6
+ class TaskRouter < Base
7
+ def route
8
+ yield_response = yield if block_given?
9
+ (yield_response || voice_response).enqueue(enqueue_params) do |e|
10
+ e.task task_attributes
11
+ end.to_s
12
+ end
13
+
14
+ private
15
+
16
+ def enqueue_params
17
+ {
18
+ action: protocol.action_url,
19
+ wait_url: protocol.wait_url,
20
+ workflow_sid: workflow_sid
21
+ }
22
+ end
23
+
24
+ def task_attributes
25
+ { outbound_contact_uri: protocol.endpoint }
26
+ end
27
+
28
+ def workflow_sid
29
+ @workflow_sid ||= TwilioBase::GlobalConfig.first.workflow_sid
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module Sync
5
+ class Service
6
+ DEFAULT_FRIENDLY_NAME = 'Default Sync Service'
7
+
8
+ class << self
9
+ include TwilioBase::Clients
10
+
11
+ def create(name: nil)
12
+ friendly_name = name || DEFAULT_FRIENDLY_NAME
13
+ rest_client.sync.v1.services.create(friendly_name: friendly_name)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module TaskRouter
5
+ class Activity < Base
6
+ AVAILABLE_ACTIVITY_NAME = 'Available'
7
+ ASSIGNMENT_ACTIVITY_NAME = 'Busy'
8
+ IDLE_ACTIVITY_NAME = 'Idle'
9
+ OFFLINE_ACTIVITY_NAME = 'Offline'
10
+ RESERVATION_ACTIVITY_NAME = 'Reserved'
11
+
12
+ class << self
13
+ def available
14
+ list.detect do |activity|
15
+ activity.friendly_name == AVAILABLE_ACTIVITY_NAME
16
+ end
17
+ end
18
+
19
+ def busy
20
+ list.detect do |activity|
21
+ activity.friendly_name == ASSIGNMENT_ACTIVITY_NAME
22
+ end
23
+ end
24
+
25
+ def idle
26
+ list.detect do |activity|
27
+ activity.friendly_name == IDLE_ACTIVITY_NAME
28
+ end
29
+ end
30
+
31
+ def list
32
+ workspace.activities.list
33
+ end
34
+
35
+ def offline
36
+ list.detect do |activity|
37
+ activity.friendly_name == OFFLINE_ACTIVITY_NAME
38
+ end
39
+ end
40
+
41
+ def reserved
42
+ list.detect do |activity|
43
+ activity.friendly_name == RESERVATION_ACTIVITY_NAME
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module TaskRouter
5
+ class Base
6
+ class << self
7
+ include TwilioBase::Clients
8
+
9
+ private
10
+
11
+ def workspace
12
+ rest_client.taskrouter.workspaces(workspace_sid)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module TaskRouter
5
+ class Task < Base
6
+ class << self
7
+ def create(task_attributes:, **options)
8
+ workspace.tasks.create(
9
+ attributes: task_attributes.to_json,
10
+ workflow_sid: workflow_sid,
11
+ **options
12
+ )
13
+ end
14
+
15
+ def find(sid)
16
+ workspace.tasks(sid).fetch
17
+ end
18
+
19
+ def where(attributes)
20
+ workspace.tasks.list(
21
+ evaluate_task_attributes: evaluable_attributes(attributes)
22
+ )
23
+ end
24
+
25
+ private
26
+
27
+ def evaluable_attributes(attributes)
28
+ attributes.map { |k, v| "#{k} == '#{v}'" }.join(' AND ')
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module TaskRouter
5
+ class TaskQueue
6
+ class << self
7
+ def find_or_create_by(workspace:, friendly_name:, target_workers: nil)
8
+ attributes = {
9
+ workspace: workspace,
10
+ friendly_name: friendly_name,
11
+ target_workers: target_workers
12
+ }.to_a
13
+
14
+ find_by(attributes[0..1].to_h) || create(attributes.to_h)
15
+ end
16
+
17
+ def find_by(workspace:, friendly_name:)
18
+ workspace.task_queues.list(friendly_name: friendly_name).first
19
+ end
20
+
21
+ def create(workspace:, friendly_name:, target_workers:)
22
+ workspace.task_queues.create(
23
+ assignment_activity_sid: assignment_activity_sid(workspace),
24
+ friendly_name: friendly_name,
25
+ reservation_activity_sid: reservation_activity_sid(workspace),
26
+ target_workers: target_workers
27
+ )
28
+ end
29
+
30
+ def assignment_activity_sid(workspace)
31
+ workspace.activities.list(friendly_name: 'Busy').first.sid
32
+ end
33
+
34
+ def reservation_activity_sid(workspace)
35
+ workspace.activities.list(friendly_name: 'Reserved').first.sid
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 TaskRouter
5
+ class Worker < Base
6
+ class << self
7
+ def create(name:, attributes:)
8
+ workspace.workers.create(
9
+ friendly_name: name,
10
+ activity_sid: idle_activity.sid,
11
+ attributes: attributes.to_json
12
+ )
13
+ end
14
+
15
+ def find(worker_sid)
16
+ workspace.workers(worker_sid).fetch
17
+ end
18
+
19
+ private
20
+
21
+ def idle_activity
22
+ TwilioBase::TaskRouter::Activity.idle
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module TaskRouter
5
+ class Workflow
6
+ class << self
7
+ include Rails.application.routes.url_helpers
8
+ include TwilioBase::Clients
9
+
10
+ def create(workspace:, attributes:)
11
+ workspace.workflows.create(
12
+ attributes
13
+ )
14
+ end
15
+
16
+ private
17
+
18
+ attr_accessor :params
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ module TaskRouter
5
+ class Workspace
6
+ class << self
7
+ include TwilioBase::Clients
8
+
9
+ DEFAULT_TEMPLATE = 'FIFO'
10
+ REQUIRED_EVENTS = %w[
11
+ task.canceled
12
+ task.completed
13
+ task.updated
14
+ workflow.timeout
15
+ ].freeze
16
+
17
+ def create(friendly_name:)
18
+ workspace_client.create(
19
+ event_callback_url: event_callback_url,
20
+ events_filter: events,
21
+ friendly_name: friendly_name,
22
+ multi_task_enabled: true,
23
+ template: DEFAULT_TEMPLATE
24
+ )
25
+ end
26
+
27
+ def find(sid)
28
+ workspace_client(sid)
29
+ end
30
+
31
+ private
32
+
33
+ def event_callback_url
34
+ TwilioBase::Engine.routes.url_helpers.task_router_callbacks_url
35
+ end
36
+
37
+ def workspace_client(sid = nil)
38
+ if sid
39
+ rest_client.taskrouter.v1.workspaces(sid)
40
+ else
41
+ rest_client.taskrouter.v1.workspaces
42
+ end
43
+ end
44
+
45
+ def events
46
+ REQUIRED_EVENTS.join(',')
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "twilio_base"
6
+
7
+ require "irb"
8
+ IRB.start(__FILE__)
data/bin/rails ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ ENGINE_ROOT = File.expand_path('..', __dir__)
5
+ ENGINE_PATH = File.expand_path(
6
+ '../lib/twilio_base/engine', __dir__
7
+ )
8
+
9
+ # Set up gems listed in the Gemfile.
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
11
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
12
+
13
+ require 'rails/all'
14
+ require 'rails/engine/commands'
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
data/circle.yml ADDED
@@ -0,0 +1,36 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: circleci/ruby:2.5.1-node-browsers
6
+ environment:
7
+ PGHOST: 127.0.0.1
8
+ PGUSER: twilio_base
9
+ RAILS_ENV: test
10
+ - image: postgres:9.5
11
+ environment:
12
+ POSTGRES_USER: twilio_base
13
+ POSTGRES_DB: twilio_base_test
14
+ POSTGRES_PASSWORD: ""
15
+ steps:
16
+ - checkout
17
+ - run: bundle install
18
+ - run: cp spec/twilio_base_dummy/config/database.example.yml spec/twilio_base_dummy/config/database.yml
19
+ - run: bundle exec rake db:setup
20
+ - run:
21
+ name: Parallel RSpec
22
+ command: bundle exec rspec spec/
23
+ - run:
24
+ name: Rubocop
25
+ command: bundle exec rubocop
26
+ - run:
27
+ name: Publish gem to gemfury
28
+ command: |
29
+ if [ "${CIRCLE_BRANCH}" == "master" ]
30
+ then
31
+ gem install gemfury
32
+ gem build twilio_base.gemspec
33
+ fury push $(ls | grep twilio_base-) --as=dvelp --api-token=$BUNDLE_GEM__FURY__IO
34
+ else
35
+ echo "Publishing to gemfury allowed only for master branch"
36
+ fi
@@ -0,0 +1,2 @@
1
+ en:
2
+
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ TwilioBase::Engine.routes.draw do
4
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateTwilioBaseGlobalConfigs < ActiveRecord::Migration[5.0]
4
+ def change
5
+ create_table :twilio_base_global_configs do |t|
6
+ t.string :api_key_secret
7
+ t.string :api_key_sid
8
+ t.string :application_sid
9
+ t.string :chat_service_sid
10
+ t.string :phone_number
11
+ t.string :sync_service_sid
12
+ t.string :workflow_sid
13
+ t.string :workspace_sid
14
+
15
+ t.timestamps
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace TwilioBase
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Helpers
4
+ module Protocols
5
+ module_function
6
+
7
+ def extract_mpoa(str)
8
+ /((?<=sip:))?(?<number>\d+)(?=@|\d*)/ =~ str
9
+ number.nil? ? str : '+' + number.to_s
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ VERSION = '1.8.0'
5
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'twilio_base/engine'
4
+ require 'twilio_base/version'
5
+ require 'addressable'
6
+ require 'twilio-ruby'
7
+
8
+ Gem.find_files('twilio_base/**/*.rb').each { |f| require f }
9
+
10
+ module TwilioBase
11
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ sequence :channel_sid do |n|
5
+ "CH#{format('%06i', n)}"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ sequence :chat_member_id do |n|
5
+ "15111#{format('%06i', n)}"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ sequence :activity_sid do |n|
5
+ "WA#{format('%06i', n)}"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ sequence :api_key_secret do |n|
5
+ "Secret#{format('%06i', n)}"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ sequence :api_key_sid do |n|
5
+ "SK#{format('%06i', n)}"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ sequence :application_sid do |n|
5
+ "AP#{format('%06i', n)}"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ sequence :chat_service_sid do |n|
5
+ "IS#{format('%06i', n)}"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ sequence :conference_sid do |n|
5
+ "WT#{format('%06i', n)}"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ sequence :message_sid do |n|
5
+ "MS#{format('%06i', n)}"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ sequence :phone_number do |n|
5
+ "+447777#{format('%06i', n)}"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ sequence :recording_sid do |n|
5
+ "RE#{format('%06i', n)}"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ sequence :sync_service_sid do |n|
5
+ "IS#{format('%06i', n)}"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ sequence :task_sid do |n|
5
+ "WT#{format('%06i', n)}"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ sequence :voice_call_sid do |n|
5
+ "CA#{format('%06i', n)}"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ sequence :worker_sid do |n|
5
+ "WK#{format('%06i', n)}"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ sequence :workflow_sid do |n|
5
+ "WW#{format('%06i', n)}"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ sequence :workspace_sid do |n|
5
+ "WS#{format('%06i', n)}"
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwilioBase
4
+ FactoryBot.define do
5
+ factory :global_config, class: TwilioBase::GlobalConfig do
6
+ api_key_sid
7
+ api_key_secret
8
+ application_sid
9
+ chat_service_sid
10
+ phone_number
11
+ sync_service_sid
12
+ workflow_sid
13
+ workspace_sid
14
+ end
15
+
16
+ trait :empty do
17
+ api_key_sid { nil }
18
+ api_key_secret { nil }
19
+ application_sid { nil }
20
+ chat_service_sid { nil }
21
+ message_sid { nil }
22
+ phone_number { nil }
23
+ sync_service_sid { nil }
24
+ workflow_sid { nil }
25
+ workspace_sid { nil }
26
+ end
27
+ end
28
+ end