doodle_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/javascripts/doodle/application.js +13 -0
  6. data/app/assets/javascripts/doodle/auth.js +2 -0
  7. data/app/assets/javascripts/doodle/keywords.js +2 -0
  8. data/app/assets/javascripts/doodle/users.js +2 -0
  9. data/app/assets/stylesheets/doodle/application.css +15 -0
  10. data/app/assets/stylesheets/doodle/auth.css +4 -0
  11. data/app/assets/stylesheets/doodle/keywords.css +4 -0
  12. data/app/assets/stylesheets/doodle/users.css +4 -0
  13. data/app/controllers/doodle/application_controller.rb +15 -0
  14. data/app/controllers/doodle/auth_controller.rb +23 -0
  15. data/app/controllers/doodle/chat_controller.rb +50 -0
  16. data/app/controllers/doodle/conversations_controller.rb +30 -0
  17. data/app/controllers/doodle/keywords_controller.rb +32 -0
  18. data/app/controllers/doodle/users_controller.rb +35 -0
  19. data/app/helpers/doodle/application_helper.rb +4 -0
  20. data/app/helpers/doodle/auth_helper.rb +4 -0
  21. data/app/helpers/doodle/keywords_helper.rb +4 -0
  22. data/app/helpers/doodle/users_helper.rb +4 -0
  23. data/app/models/doodle/channel.rb +12 -0
  24. data/app/models/doodle/keyword/action.rb +4 -0
  25. data/app/models/doodle/keyword/text.rb +4 -0
  26. data/app/models/doodle/keyword.rb +4 -0
  27. data/app/models/doodle/protocol.rb +65 -0
  28. data/app/models/doodle/user/analyst.rb +18 -0
  29. data/app/models/doodle/user/customer.rb +4 -0
  30. data/app/models/doodle/user.rb +9 -0
  31. data/app/models/doodle/user_channel.rb +27 -0
  32. data/app/services/doodle/channel/finder_service.rb +15 -0
  33. data/app/services/doodle/chat/join_service.rb +23 -0
  34. data/app/services/doodle/keyword/finder_service.rb +15 -0
  35. data/app/services/doodle/protocol/creator_service.rb +16 -0
  36. data/app/services/doodle/protocol/finalizer_service.rb +11 -0
  37. data/app/services/doodle/protocol/finder_service.rb +13 -0
  38. data/app/services/layer/conversation/creator_service.rb +11 -0
  39. data/app/services/layer/token_creator_service.rb +13 -0
  40. data/app/views/layouts/doodle/application.html.erb +14 -0
  41. data/config/initializers/layer.rb +12 -0
  42. data/config/routes.rb +25 -0
  43. data/db/migrate/20160211170908_create_doodle_channels.rb +9 -0
  44. data/db/migrate/20160211202503_create_doodle_user_channels.rb +13 -0
  45. data/db/migrate/20160320142137_create_doodle_users.rb +11 -0
  46. data/db/migrate/20160320142142_create_doodle_keywords.rb +11 -0
  47. data/db/migrate/20160320175917_create_doodle_protocols.rb +16 -0
  48. data/lib/doodle/engine.rb +5 -0
  49. data/lib/doodle/version.rb +3 -0
  50. data/lib/doodle.rb +4 -0
  51. data/lib/tasks/doodle_tasks.rake +4 -0
  52. data/test/controllers/doodle/auth_controller_test.rb +13 -0
  53. data/test/controllers/doodle/keywords_controller_test.rb +13 -0
  54. data/test/controllers/doodle/users_controller_test.rb +13 -0
  55. data/test/doodle_test.rb +7 -0
  56. data/test/dummy/README.rdoc +28 -0
  57. data/test/dummy/Rakefile +6 -0
  58. data/test/dummy/app/assets/javascripts/application.js +13 -0
  59. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  60. data/test/dummy/app/controllers/application_controller.rb +5 -0
  61. data/test/dummy/app/helpers/application_helper.rb +2 -0
  62. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  63. data/test/dummy/bin/bundle +3 -0
  64. data/test/dummy/bin/rails +4 -0
  65. data/test/dummy/bin/rake +4 -0
  66. data/test/dummy/bin/setup +29 -0
  67. data/test/dummy/config/application.rb +28 -0
  68. data/test/dummy/config/boot.rb +5 -0
  69. data/test/dummy/config/database.yml +25 -0
  70. data/test/dummy/config/environment.rb +5 -0
  71. data/test/dummy/config/environments/development.rb +41 -0
  72. data/test/dummy/config/environments/production.rb +79 -0
  73. data/test/dummy/config/environments/test.rb +42 -0
  74. data/test/dummy/config/initializers/assets.rb +11 -0
  75. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  76. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  77. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  78. data/test/dummy/config/initializers/inflections.rb +16 -0
  79. data/test/dummy/config/initializers/mime_types.rb +4 -0
  80. data/test/dummy/config/initializers/session_store.rb +3 -0
  81. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  82. data/test/dummy/config/locales/en.yml +23 -0
  83. data/test/dummy/config/private_key.pem +15 -0
  84. data/test/dummy/config/routes.rb +4 -0
  85. data/test/dummy/config/secrets.yml +22 -0
  86. data/test/dummy/config.ru +4 -0
  87. data/test/dummy/db/development.sqlite3 +0 -0
  88. data/test/dummy/db/schema.rb +66 -0
  89. data/test/dummy/log/development.log +7207 -0
  90. data/test/dummy/public/404.html +67 -0
  91. data/test/dummy/public/422.html +67 -0
  92. data/test/dummy/public/500.html +66 -0
  93. data/test/dummy/public/favicon.ico +0 -0
  94. data/test/fixtures/doodle/keywords.yml +11 -0
  95. data/test/fixtures/doodle/users.yml +11 -0
  96. data/test/integration/navigation_test.rb +8 -0
  97. data/test/models/doodle/keyword_test.rb +9 -0
  98. data/test/models/doodle/user_test.rb +9 -0
  99. data/test/test_helper.rb +21 -0
  100. metadata +218 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: af2ea8a12cd16908d7f2afecc8f5bbdcb2f72d11
4
+ data.tar.gz: 81ee8369d7a1c904a43b8c18a724b9d82fe5003f
5
+ SHA512:
6
+ metadata.gz: 198575898ddef68256d9b11dbae7231d95f1cbe8bb4286f74eb18c6d61e92e91a858ac26fb0e93a445255c0edef2a94665c5c79421d9642d30747e1b18935d9f
7
+ data.tar.gz: e91b49295a269c5be4901299463f02226411ab4bea4d6674ef593b167f5e72810ef59db429542847db591fdf6d424d18578fe6df39b4f436d3b85691689f9d35
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Gabriel Malaquias
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Doodle
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Doodle'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,15 @@
1
+ module Doodle
2
+ class ApplicationController < ActionController::Base
3
+ def authenticate
4
+ render json: { session_token: create_and_authenticate }
5
+ end
6
+
7
+ def authenticate_user
8
+
9
+ end
10
+
11
+ def auth_params
12
+ params.require(:auth).permit(:login, :pass)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ require_dependency "doodle/application_controller"
2
+
3
+ module Doodle
4
+ class AuthController < ApplicationController
5
+ def authenticate
6
+ @user = User.where(pass: auth_params[:pass], login: auth_params[:login], type: auth_params[:type]).first
7
+
8
+ if @user.present?
9
+ render json: { login: @user.login, session_token: token_creator_service.token }
10
+ else
11
+ render json: { error: "When authenticate user" }
12
+ end
13
+ end
14
+
15
+ def auth_params
16
+ @params ||= params.require(:auth).permit(:login, :pass, :type)
17
+ end
18
+
19
+ def token_creator_service
20
+ @creator_service ||= Layer::TokenCreatorService.new(@user.login)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,50 @@
1
+ require_dependency "doodle/application_controller"
2
+
3
+ module Doodle
4
+ class ChatController < ApplicationController
5
+
6
+ def has_protocols?
7
+ protocols = Protocol.waiting_in_channel(params.require(:channel))
8
+ render json: { has_protocols: protocols.size }, status: 200
9
+ end
10
+
11
+ def next
12
+ protocol = protocol_finder_service.next
13
+ join_service = chat_join_service(protocol)
14
+ if join_service.break_limit? && protocol.blank?
15
+ render json: { error: 'Analyst already have limit of protocols in progress' }, status: 422
16
+ else
17
+ join_service.join(params.require(:channel))
18
+ render json: { conversation: protocol.conversation_id }, status: 200
19
+ end
20
+ end
21
+
22
+ def finalize
23
+ user = User::Analyst.find_by_login(params.require(:login))
24
+ protocol = protocol_finder_service.find_by_conversation(params.require(:id))
25
+
26
+ if user.blank? || protocol.blank?
27
+ render json: { text: "Protocol or user dont found"}, status: 422
28
+ else
29
+
30
+ protocol_finalizer_service(protocol).call
31
+ chat_join_service(protocol, user).out(protocol.channel.name)
32
+
33
+ render json: { id: protocol.id, text: "Protocol finalized with success" }
34
+ end
35
+ end
36
+
37
+ def protocol_finalizer_service(protocol)
38
+ @protcol_finalizer_service ||= Protocol::FinalizerService.new(protocol)
39
+ end
40
+
41
+ def chat_join_service(protocol, user)
42
+ @chat_join_service ||= Chat::JoinService.new(user, protocol)
43
+ end
44
+
45
+ def protocol_finder_service
46
+ @finder_service ||= Protocol::FinderService.new
47
+ end
48
+ end
49
+ end
50
+
@@ -0,0 +1,30 @@
1
+ require_dependency "doodle/application_controller"
2
+
3
+ module Doodle
4
+ class ConversationsController < ApplicationController
5
+ def create
6
+ channel = channel_finder_service.call.first
7
+
8
+ if channel.present?
9
+ conversation = conversation_creator_service([params.require(:login)]).call
10
+ protocol = protocol_creator_service(channel, conversation).call
11
+ render json: { protocol_id: protocol.id, prococol_status: protocol.status, channel: channel.name, conversation_id: conversation.id }, status: 201
12
+ else
13
+ render json: { error: 'Channel dont found, Please create channel with this name first' }
14
+ end
15
+ end
16
+
17
+ def channel_finder_service
18
+ @channel_finder_service ||= Channel::FinderService.new({name: params.require(:channel)})
19
+ end
20
+
21
+ def protocol_creator_service(channel, conversation)
22
+ @protocol_creator_service ||= Protocol::CreatorService.new(params.require(:login), channel, conversation)
23
+ end
24
+
25
+ def conversation_creator_service(participants)
26
+ @conversation_creator_service ||= ::Layer::Conversation::CreatorService.new(participants)
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,32 @@
1
+ require_dependency "doodle/application_controller"
2
+ require 'pry'
3
+
4
+ module Doodle
5
+ class KeywordsController < ApplicationController
6
+
7
+ def create
8
+ keyword = Keyword.new(keyword_params)
9
+ if keyword.save
10
+ render json: keyword.reload.to_json
11
+ else
12
+ render json: {error: 'When save keyword'}.to_json
13
+ end
14
+ end
15
+
16
+ def index
17
+ if params[:keyword].present?
18
+ render json: finder_service.to_json
19
+ else
20
+ render json: Keyword.all.to_json
21
+ end
22
+ end
23
+
24
+ def keyword_params
25
+ params.require(:keyword).permit(:name, :value, :type)
26
+ end
27
+
28
+ def finder_service
29
+ @finder_service || Doodle::Keyword::FinderService.new(keyword_params)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,35 @@
1
+ require_dependency "doodle/application_controller"
2
+
3
+ module Doodle
4
+ class UsersController < ApplicationController
5
+
6
+ def join
7
+ user = User::Analyst.find_by_params(users_params[:login])
8
+ channel = params.require(:channel)
9
+
10
+ if user
11
+ if user.has_channels?
12
+ user.enter_in_channel(channel)
13
+ end
14
+ render json: { channel: channel }, status: 200
15
+ end
16
+
17
+ render json: { error: 'User not found' }, status: 404
18
+
19
+ end
20
+
21
+
22
+ def create
23
+ user = User.new(users_params)
24
+ if user.save
25
+ render json: user.reload.to_json
26
+ else
27
+ render json: {error: 'When save keyword'}.to_json
28
+ end
29
+ end
30
+
31
+ def users_params
32
+ params.require(:user).permit(:login, :pass, :type)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,4 @@
1
+ module Doodle
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Doodle
2
+ module AuthHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Doodle
2
+ module KeywordsHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Doodle
2
+ module UsersHelper
3
+ end
4
+ end
@@ -0,0 +1,12 @@
1
+ module Doodle
2
+ class Channel < ActiveRecord::Base
3
+ has_many :user_channels
4
+ has_many :users, through: :user_channels
5
+
6
+ has_many :protocols
7
+
8
+ def self.find_protocols_by_channel(name)
9
+ Channel.find_by_name(name).protocols
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ module Doodle
2
+ class Keyword::Action < Keyword
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Doodle
2
+ class Keyword::Text < Keyword
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Doodle
2
+ class Keyword < ActiveRecord::Base
3
+ end
4
+ end
@@ -0,0 +1,65 @@
1
+ module Doodle
2
+ class Protocol < ActiveRecord::Base
3
+ include AASM
4
+ belongs_to :channel
5
+ belongs_to :user
6
+
7
+ aasm column: :status do
8
+ state :waiting, initial: true
9
+ state :in_progress
10
+ state :finalized
11
+
12
+ after_all_transitions :log_status_change
13
+
14
+ event :progress do
15
+ before do
16
+ self.update(in_progress_at: Time.now)
17
+ end
18
+
19
+ transitions from: :waiting, to: :in_progress
20
+ end
21
+
22
+ event :finalize do
23
+ before do
24
+ self.update(finalized_at: Time.now)
25
+ end
26
+
27
+ transitions from: :in_progress, to: :finalized
28
+ end
29
+ end
30
+
31
+ scope :waiting_in_channel, -> (channel){ joins(:channel).where(status: :waiting, 'doodle_channels.name' => channel) }
32
+
33
+ def duration
34
+ (self.finalized_at - self.created_at).round
35
+ end
36
+
37
+ def log_status_change
38
+ Rails.logger.info "[DOODLE] [PROTOCOL] - Protocol #{self.id} of customer #{self.customer_login} changed from #{aasm.from_state} to #{aasm.to_state}"
39
+ end
40
+
41
+ def add_analyst_into(user)
42
+ self.user = user
43
+ self.save
44
+ end
45
+
46
+ def add_participant_into_conversation(login)
47
+ conversation = Layer::Conversation.find(self.conversation_id)
48
+ conversation.participants << login
49
+ conversation.save
50
+ end
51
+
52
+ def remove_participant_from_conversation(login)
53
+ conversation = Layer::Conversation.find(self.conversation_id)
54
+ conversation.participants = conversation.participants - [login]
55
+ conversation.save
56
+ end
57
+
58
+ def self.next(channel = 'corporativo')
59
+ protocol = self.waiting_in_channel(channel).first
60
+ protocol.progress!
61
+ protocol
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,18 @@
1
+ module Doodle
2
+ class User::Analyst < User
3
+
4
+ def enter_in_channel(name)
5
+ user_channel = user_channel_by_name(name)
6
+ user_channel.turn_online! if user_channel.may_turn_online?
7
+ end
8
+
9
+ def out_of_channel(name)
10
+ user_channel = user_channel_by_name(name)
11
+ user_channel.turn_offline! if user_channel.may_turn_offline?
12
+ end
13
+
14
+ def user_channel_by_name(name)
15
+ self.user_channels.joins(:channel).where('doodle_channels.name' => name).first
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ module Doodle
2
+ class User::Customer < User
3
+ end
4
+ end
@@ -0,0 +1,9 @@
1
+ module Doodle
2
+ class User < ActiveRecord::Base
3
+ has_many :user_channels
4
+ has_many :channels, through: :user_channels
5
+
6
+
7
+
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ module Doodle
2
+ class UserChannel < ActiveRecord::Base
3
+ include AASM
4
+
5
+ belongs_to :user
6
+ belongs_to :channel
7
+
8
+ aasm column: :status do
9
+ state :offline, initial: true
10
+ state :online
11
+
12
+ after_all_transitions :log_status_change
13
+
14
+ event :turn_online do
15
+ transitions from: :offline, to: :online
16
+ end
17
+
18
+ event :turn_offline do
19
+ transitions from: :online, to: :offline
20
+ end
21
+ end
22
+
23
+ def log_status_change
24
+ Rails.logger.info "[POC] [CHANNEL] - Analyst #{self.user.login} change your status from #{aasm.from_state} to #{aasm.to_state}"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ module Doodle
2
+ class Channel::FinderService
3
+ def initialize(params)
4
+ @params = params
5
+ end
6
+
7
+ def call
8
+ scope = nil
9
+ @params.each do |k, v|
10
+ scope = Doodle::Channel.where({k => v})
11
+ end
12
+ scope.all
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ module Doodle
2
+ class Chat::JoinService
3
+ def initialize(user, protocol)
4
+ @protocol = protocol
5
+ @user = user
6
+ end
7
+
8
+ def join(channel)
9
+ @protocol.add_analyst_into(@user)
10
+ @protocol.add_participant_into_conversation(@user.login)
11
+ @user.enter_in_channel(channel)
12
+ end
13
+
14
+ def break_limit?
15
+ @user.break_limit_concurrent_protocols?
16
+ end
17
+
18
+ def out(channel)
19
+ @protocol.remove_participant_from_conversation(@user.login)
20
+ @user.out_of_channel(channel)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ module Doodle
2
+ class Keyword::FinderService
3
+ def initialize(params)
4
+ @params = params
5
+ end
6
+
7
+ def call
8
+ scope = nil
9
+ @params.each do |k, v|
10
+ scope = Doodle::Keyword.where(k, v)
11
+ end
12
+ scope.all
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ module Doodle
2
+ class Protocol::CreatorService
3
+ def initialize(customer_login, channel, conversation)
4
+ @customer_login = customer_login
5
+ @channel = channel
6
+ @conversation = conversation
7
+ end
8
+
9
+ def call
10
+ Protocol.create(customer_login: @customer_login,
11
+ channel: @channel,
12
+ conversation_id: @conversation.id,
13
+ phone: '(XX) XXXX-XXXX')
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module Doodle
2
+ class Protocol::FinalizerService
3
+ def initialize(protocol)
4
+ @protocol = protocol
5
+ end
6
+
7
+ def call
8
+ @protocol.finalize!
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module Doodle
2
+ class Protocol::FinderService
3
+ def next
4
+ Protocol.next
5
+ end
6
+
7
+ def find_by_conversation(id)
8
+ Protocol.find_by_conversation_id(id)
9
+ end
10
+ end
11
+ end
12
+
13
+
@@ -0,0 +1,11 @@
1
+ module Layer
2
+ class Conversation::CreatorService
3
+ def initialize(participants)
4
+ @participants = participants
5
+ end
6
+
7
+ def call
8
+ Layer::Conversation.create(participants: @participants)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ class Layer::TokenCreatorService
2
+ def initialize(login)
3
+ @login = login
4
+ end
5
+
6
+ def token
7
+ client = Layer::Client.authenticate do |nonce|
8
+ Layer::IdentityToken.new(@login, nonce)
9
+ end
10
+ client.token
11
+ end
12
+
13
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Doodle</title>
5
+ <%= stylesheet_link_tag "doodle/application", media: "all" %>
6
+ <%= javascript_include_tag "doodle/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,12 @@
1
+ Layer::Client.configure do |config|
2
+ config.app_id = "layer:///apps/staging/151aa76a-ce72-11e5-ac55-80e4720f6b18"
3
+ config.token = "H6EvCKXyPpXuQtBDU07TdgLguNMatEQcOKBmQqpJTVsg5Gdj"
4
+ end
5
+
6
+ Layer::IdentityToken.layer_provider_id = "layer:///providers/1519612a-ce72-11e5-ac55-80e4720f6b18"
7
+ Layer::IdentityToken.layer_key_id = "layer:///keys/0ff36abc-d0d2-11e5-b2af-61c9960f423b"
8
+
9
+ key = File.readlines("#{Rails.root}/config/private_key.pem").join('')
10
+ Layer::IdentityToken.layer_private_key = OpenSSL::PKey::RSA.new(key)
11
+
12
+