stealth-twilio 0.9.0 → 0.9.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5329076b9bcf28a0d0d0d9319cbc69c50f8ea9fb
4
- data.tar.gz: fc3136011f21dadfe79a699595d23a35422366a8
3
+ metadata.gz: f4d48578bf7d1de00513f6d3f7828925ee12bf79
4
+ data.tar.gz: 6859b9d6290b867c80a1868d16d709c6b7121797
5
5
  SHA512:
6
- metadata.gz: 6db2b4d73a01e484ecb82e7d3dcb0f2ef82e834b1cebd8264ca7c41974d998e7c5d64683afee3fb52e95abad676e9338859ac703a6096a354c989cb0df75dbd0
7
- data.tar.gz: 1fc1652d0b2632e1e382f554c5c452361e5aad02cae1253be7201782d1dae41289716b713ae2ce7efc1cae32930159f2cd3b5bb6d786af8f9ebfb1d26af02d63
6
+ metadata.gz: 7e3e5eccba03b9153f506ff9651171c71b7c3eeb7c9a58663a4cf14ed87bc1dcf3c73742fb8ad128ae16114a0f56e32a906344452d04d10dc23ad44549d28c77
7
+ data.tar.gz: 598439d9586afb8b0e7278088196dd8997449a2fdb2f1d6fc6fc18b85aa97989e16a1ea1e8fcc47794085a140e324619ab2e37c2fda0743ce30ad581096d1996
@@ -0,0 +1,60 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.4.1-node-browsers
11
+ environment:
12
+ STEALTH_ENV: test
13
+
14
+ # Specify service dependencies here if necessary
15
+ # CircleCI maintains a library of pre-built images
16
+ # documented at https://circleci.com/docs/2.0/circleci-images/
17
+ # - image: circleci/postgres:9.4
18
+
19
+ working_directory: ~/repo
20
+
21
+ steps:
22
+ - checkout
23
+
24
+ # Download and cache dependencies
25
+ - restore_cache:
26
+ keys:
27
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
28
+ # fallback to using the latest cache if no exact match is found
29
+ - v1-dependencies-
30
+
31
+ - run:
32
+ name: install dependencies
33
+ command: |
34
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
35
+
36
+ - save_cache:
37
+ paths:
38
+ - ./vendor/bundle
39
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
40
+
41
+ # run tests!
42
+ - run:
43
+ name: run tests
44
+ command: |
45
+ mkdir /tmp/test-results
46
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
47
+
48
+ bundle exec rspec --format progress \
49
+ --format RspecJunitFormatter \
50
+ --out /tmp/test-results/rspec.xml \
51
+ --format progress \
52
+ -- \
53
+ $TEST_FILES
54
+
55
+ # collect reports
56
+ - store_test_results:
57
+ path: /tmp/test-results
58
+ - store_artifacts:
59
+ path: /tmp/test-results
60
+ destination: test-results
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ # please add general patterns to your global ignore list
2
+ # see https://github.com/github/gitignore#readme
3
+ .DS_STORE
4
+ *.swp
5
+ *.rbc
6
+ *.sass-cache
7
+ /pkg
8
+ /doc/api
9
+ /coverage
10
+ .yardoc
11
+ doc/
12
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,90 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ stealth-twilio (0.9.0)
5
+ stealth (~> 0.9)
6
+ twilio-ruby (~> 5.5)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.1.4)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (~> 0.7)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ concurrent-ruby (1.0.5)
17
+ connection_pool (2.2.1)
18
+ diff-lcs (1.3)
19
+ faraday (0.13.1)
20
+ multipart-post (>= 1.2, < 3)
21
+ i18n (0.9.1)
22
+ concurrent-ruby (~> 1.0)
23
+ jwt (2.1.0)
24
+ mini_portile2 (2.3.0)
25
+ minitest (5.10.3)
26
+ multi_json (1.12.2)
27
+ multipart-post (2.0.0)
28
+ mustermann (1.0.1)
29
+ nokogiri (1.8.1)
30
+ mini_portile2 (~> 2.3.0)
31
+ puma (3.11.0)
32
+ rack (2.0.3)
33
+ rack-protection (2.0.0)
34
+ rack
35
+ rack-test (0.7.0)
36
+ rack (>= 1.0, < 3)
37
+ redis (4.0.1)
38
+ rspec (3.7.0)
39
+ rspec-core (~> 3.7.0)
40
+ rspec-expectations (~> 3.7.0)
41
+ rspec-mocks (~> 3.7.0)
42
+ rspec-core (3.7.0)
43
+ rspec-support (~> 3.7.0)
44
+ rspec-expectations (3.7.0)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.7.0)
47
+ rspec-mocks (3.7.0)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.7.0)
50
+ rspec-support (3.7.0)
51
+ rspec_junit_formatter (0.3.0)
52
+ rspec-core (>= 2, < 4, != 2.12.0)
53
+ sidekiq (5.0.5)
54
+ concurrent-ruby (~> 1.0)
55
+ connection_pool (~> 2.2, >= 2.2.0)
56
+ rack-protection (>= 1.5.0)
57
+ redis (>= 3.3.4, < 5)
58
+ sinatra (2.0.0)
59
+ mustermann (~> 1.0)
60
+ rack (~> 2.0)
61
+ rack-protection (= 2.0.0)
62
+ tilt (~> 2.0)
63
+ stealth (0.9.8)
64
+ activesupport (~> 5.1)
65
+ multi_json (~> 1.12)
66
+ puma (~> 3.10)
67
+ sidekiq (~> 5.0)
68
+ sinatra (~> 2.0)
69
+ thor (~> 0.20)
70
+ thor (0.20.0)
71
+ thread_safe (0.3.6)
72
+ tilt (2.0.8)
73
+ twilio-ruby (5.6.0)
74
+ faraday (~> 0.9)
75
+ jwt (>= 1.5, <= 2.5)
76
+ nokogiri (>= 1.6, < 2.0)
77
+ tzinfo (1.2.4)
78
+ thread_safe (~> 0.1)
79
+
80
+ PLATFORMS
81
+ ruby
82
+
83
+ DEPENDENCIES
84
+ rack-test (~> 0.7)
85
+ rspec (~> 3.6)
86
+ rspec_junit_formatter (~> 0.3)
87
+ stealth-twilio!
88
+
89
+ BUNDLED WITH
90
+ 1.16.0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2017 Mauricio Gomes, Black Ops Bureau
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.md ADDED
@@ -0,0 +1,16 @@
1
+ # Stealth Twilio SMS
2
+
3
+ The Stealth Twilio SMS driver adds the ability to build your bot using Twilio's SMS service.
4
+
5
+ ## Supported Reply Types
6
+
7
+ * Text
8
+ * Image
9
+ * Audio
10
+ * Video
11
+ * Delay
12
+
13
+ Image, Audio, and Video reply types will leverage the MMS protocol. It is recommended by Twilio that
14
+ the content is limited to images, however, this is the full list of supported content types: https://www.twilio.com/docs/api/messaging/accepted-mime-types.
15
+
16
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.9.1
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'twilio-ruby'
5
+
6
+ require 'stealth/services/twilio/message_handler'
7
+ require 'stealth/services/twilio/reply_handler'
8
+ require 'stealth/services/twilio/setup'
9
+
10
+ module Stealth
11
+ module Services
12
+ module Twilio
13
+
14
+ class Client < Stealth::Services::BaseClient
15
+
16
+ attr_reader :twilio_client, :reply
17
+
18
+ def initialize(reply:)
19
+ @reply = reply
20
+ account_sid = Stealth.config.twilio.account_sid
21
+ auth_token = Stealth.config.twilio.auth_token
22
+ @twilio_client = ::Twilio::REST::Client.new(account_sid, auth_token)
23
+ end
24
+
25
+ def transmit
26
+ # Don't transmit anything for delays
27
+ return true if reply.blank?
28
+
29
+ response = twilio_client.messages.create(reply)
30
+ Stealth::Logger.l(topic: "twilio", message: "Transmitting. Response: #{response.status}: #{response.error_message}")
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,53 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module Stealth
5
+ module Services
6
+ module Twilio
7
+
8
+ class MessageHandler < Stealth::Services::BaseMessageHandler
9
+
10
+ attr_reader :service_message, :params, :headers
11
+
12
+ def initialize(params:, headers:)
13
+ @params = params
14
+ @headers = headers
15
+ end
16
+
17
+ def coordinate
18
+ Stealth::Services::HandleMessageJob.perform_async('twilio', params, {})
19
+
20
+ # Relay our acceptance
21
+ [204, 'No Content']
22
+ end
23
+
24
+ def process
25
+ @service_message = ServiceMessage.new(service: 'twilio')
26
+ service_message.sender_id = params['From']
27
+ service_message.message = params['Body']
28
+
29
+ # Check for media attachments
30
+ attachment_count = 0
31
+ begin
32
+ attachment_count = Integer(params['NumMedia'])
33
+ rescue ArgumentError
34
+
35
+ end
36
+
37
+ if attachment_count > 0
38
+ for i in (0..attachment_count) do
39
+ service_message.attachments << {
40
+ type: params["MediaContentType#{i}"],
41
+ url: params["MediaUrl#{i}"]
42
+ }
43
+ end
44
+ end
45
+
46
+ service_message
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,62 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module Stealth
5
+ module Services
6
+ module Twilio
7
+
8
+ class ReplyHandler < Stealth::Services::BaseReplyHandler
9
+
10
+ attr_reader :recipient_id, :reply
11
+
12
+ def initialize(recipient_id: nil, reply: nil)
13
+ @recipient_id = recipient_id
14
+ @reply = reply
15
+ end
16
+
17
+ def text
18
+ check_text_length
19
+
20
+ format_response({ body: reply['text'] })
21
+ end
22
+
23
+ def image
24
+ check_text_length
25
+
26
+ format_response({ body: reply['text'], media_url: reply['image_url'] })
27
+ end
28
+
29
+ def audio
30
+ check_text_length
31
+
32
+ format_response({ body: reply['text'], media_url: reply['audio_url'] })
33
+ end
34
+
35
+ def video
36
+ check_text_length
37
+
38
+ format_response({ body: reply['text'], media_url: reply['video_url'] })
39
+ end
40
+
41
+ def delay
42
+
43
+ end
44
+
45
+ private
46
+
47
+ def check_text_length
48
+ if reply['text'].size > 1600
49
+ raise(ArgumentError, "Text messages must be 1600 characters or less.")
50
+ end
51
+ end
52
+
53
+ def format_response(response)
54
+ sender_info = { from: Stealth.config.twilio.from_phone, to: recipient_id }
55
+ response.merge(sender_info)
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'stealth/services/twilio/client'
5
+
6
+ module Stealth
7
+ module Services
8
+ module Twilio
9
+
10
+ class Setup
11
+
12
+ class << self
13
+ def trigger
14
+ Stealth::Logger.l(topic: "twilio", message: "There is no setup needed!")
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module Stealth
5
+ module Services
6
+ module Twilio
7
+ module Version
8
+ def self.version
9
+ File.read(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'VERSION')).strip
10
+ end
11
+ end
12
+
13
+ VERSION = Version.version
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,2 @@
1
+ require 'stealth/services/twilio/version'
2
+ require 'stealth/services/twilio/client'
@@ -0,0 +1 @@
1
+ require 'stealth/twilio'
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+
5
+ require 'stealth'
6
+ require 'stealth-twilio'
7
+
8
+ # Requires supporting files with custom matchers and macros, etc,
9
+ # in ./support/ and its subdirectories.
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
11
+
12
+ RSpec.configure do |config|
13
+
14
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
4
+
5
+ describe "Stealth::Services::Twilio::Version" do
6
+
7
+ let(:version_in_file) { File.read(File.join(File.dirname(__FILE__), '..', 'VERSION')).strip }
8
+
9
+ it "should return the current gem version" do
10
+ expect(Stealth::Services::Twilio::Version.version).to eq version_in_file
11
+ end
12
+
13
+ it "should return the current gem version via a constant" do
14
+ expect(Stealth::Services::Twilio::VERSION).to eq version_in_file
15
+ end
16
+ end
@@ -0,0 +1,26 @@
1
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
+
3
+ version = File.read(File.join(File.dirname(__FILE__), 'VERSION')).strip
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'stealth-twilio'
7
+ s.summary = 'Stealth Twilio SMS driver'
8
+ s.description = 'Twilio SMS driver for Stealth.'
9
+ s.homepage = 'https://github.com/whoisblackops/stealth-twilio'
10
+ s.licenses = ['MIT']
11
+ s.version = version
12
+ s.author = 'Mauricio Gomes'
13
+ s.email = 'mauricio@edge14.com'
14
+
15
+ s.add_dependency 'stealth', '~> 0.9'
16
+ s.add_dependency 'twilio-ruby', '~> 5.5'
17
+
18
+ s.add_development_dependency 'rspec', '~> 3.6'
19
+ s.add_development_dependency 'rspec_junit_formatter', '~> 0.3'
20
+ s.add_development_dependency 'rack-test', '~> 0.7'
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
25
+ s.require_paths = ['lib']
26
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stealth-twilio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mauricio Gomes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-07 00:00:00.000000000 Z
11
+ date: 2017-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stealth
@@ -85,7 +85,24 @@ email: mauricio@edge14.com
85
85
  executables: []
86
86
  extensions: []
87
87
  extra_rdoc_files: []
88
- files: []
88
+ files:
89
+ - ".circleci/config.yml"
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - LICENSE
94
+ - README.md
95
+ - VERSION
96
+ - lib/stealth-twilio.rb
97
+ - lib/stealth/services/twilio/client.rb
98
+ - lib/stealth/services/twilio/message_handler.rb
99
+ - lib/stealth/services/twilio/reply_handler.rb
100
+ - lib/stealth/services/twilio/setup.rb
101
+ - lib/stealth/services/twilio/version.rb
102
+ - lib/stealth/twilio.rb
103
+ - spec/spec_helper.rb
104
+ - spec/version_spec.rb
105
+ - stealth-twilio.gemspec
89
106
  homepage: https://github.com/whoisblackops/stealth-twilio
90
107
  licenses:
91
108
  - MIT
@@ -106,8 +123,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
123
  version: '0'
107
124
  requirements: []
108
125
  rubyforge_project:
109
- rubygems_version: 2.6.11
126
+ rubygems_version: 2.6.12
110
127
  signing_key:
111
128
  specification_version: 4
112
129
  summary: Stealth Twilio SMS driver
113
- test_files: []
130
+ test_files:
131
+ - spec/spec_helper.rb
132
+ - spec/version_spec.rb