text_opener 0.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9b4786177a9439671bca510ffbffeaf191c6153b
4
+ data.tar.gz: 593db642846dcd5d94966ddf8924118edce9356a
5
+ SHA512:
6
+ metadata.gz: 0f2a17c8d72bcbd2e46c56c753d43603ea3ea24e5d44f3b899dd865a14f84049a3f86f41ab1021d66ccd06079e5cc2bd5599081639cfaa7de22a9f0b5fb7186c
7
+ data.tar.gz: c098fce1994ac42f218e58d0a3d4078348ebb5efeffe578e98afff90cff3bbf49f69fa2abc18b13c12d6b21116c2f918d8e399d506845b18a3a393121a73c11a
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1 @@
1
+ 2.0.0-p451
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in text_opener.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ # TextOpener
2
+
3
+ TextOpener is like Letter Opener but for text messages sent via Twilio.
4
+ Messages will be previewed in the browser instead of actually sent.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'text_opener'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install text_opener
19
+
20
+ ## Usage
21
+
22
+ Call `TextOpener.install` to stub Twilio texts sent with the twilio-ruby gem.
23
+ If you're using Rails you may want to add an initializer, or call it directly
24
+ from config/environment/development.rb
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,50 @@
1
+ require "text_opener/version"
2
+ require 'json'
3
+ require 'securerandom'
4
+ require 'tmpdir'
5
+ require 'launchy'
6
+ require 'erb'
7
+ require 'twilio-ruby'
8
+
9
+ module TextOpener
10
+ def self.install
11
+ NSA.new.tap(&:intercept)
12
+ end
13
+
14
+ class InterceptingMessage < Twilio::REST::Message; end
15
+ class InterceptingMessages < Twilio::REST::Messages
16
+ def create(params)
17
+ tmp_dir = Dir.mktmpdir
18
+ file_path = File.join(tmp_dir, "#{SecureRandom.uuid}.html")
19
+ File.open(file_path, "w") do |file|
20
+ template = ERB.new(<<-TEMPLATE)
21
+ <html>
22
+ <head><title>SMS to #{params[:to]}</title></head>
23
+ <body>
24
+ <dl>
25
+ <dt>To:</dt><dd>#{params[:to]}</dd>
26
+ <dt>From:</dt><dd>#{params[:from]}</dd>
27
+ </dl>
28
+ <p>#{params[:body]}</p>
29
+ </body>
30
+ </html>
31
+ TEMPLATE
32
+ file.write(template.result(binding))
33
+ end
34
+ Launchy.open(file_path)
35
+ end
36
+ end
37
+
38
+ class NSA
39
+ def intercept
40
+ @original_messages = Twilio::REST::Messages
41
+ Twilio::REST.send(:remove_const, :Messages)
42
+ Twilio::REST.send(:const_set, :Messages, TextOpener::InterceptingMessages)
43
+ end
44
+
45
+ def restore
46
+ Twilio::REST.send(:remove_const, :Messages)
47
+ Twilio::REST.send(:const_set, :Messages, @original_messages)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module TextOpener
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,50 @@
1
+ require 'text_opener'
2
+ require 'webmock'
3
+ require 'webmock/rspec'
4
+
5
+ describe TextOpener do
6
+ it "launchy's an html file with the text info" do
7
+ nsa = TextOpener::NSA.new.tap(&:intercept)
8
+ account_sid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
9
+ auth_token = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
10
+ client = Twilio::REST::Client.new account_sid, auth_token
11
+ from_number = "3334445555"
12
+ to_number = "5554443333"
13
+ message_body = "Your code is 123456"
14
+ file_contents = ''
15
+
16
+ allow(Launchy).to receive(:open) do |file_path|
17
+ file_contents = File.read(file_path)
18
+ end
19
+
20
+ client.account.messages.create({
21
+ from: from_number,
22
+ to: to_number,
23
+ body: message_body
24
+ })
25
+
26
+ expect(Launchy).to have_received(:open)
27
+ expect(file_contents).to include(to_number)
28
+ expect(file_contents).to include(from_number)
29
+ expect(file_contents).to include(message_body)
30
+ nsa.restore
31
+ end
32
+
33
+ it "doesn't do anything until you install it" do
34
+ message_request = WebMock.stub_request(:post, /.*api.twilio.com.*/).to_return({status: 200, body: {sid: ''}.to_json })
35
+
36
+ account_sid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
37
+ auth_token = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
38
+ client = Twilio::REST::Client.new account_sid, auth_token
39
+ from_number = "3334445555"
40
+ to_number = "5554443333"
41
+ message_body = "Your code is 123456"
42
+ client.account.messages.create({
43
+ from: from_number,
44
+ to: to_number,
45
+ body: message_body
46
+ })
47
+
48
+ expect(message_request).to have_been_requested
49
+ end
50
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'text_opener/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "text_opener"
8
+ spec.version = TextOpener::VERSION
9
+ spec.authors = ["Colin O'Byrne", "Whitney Schaefer"]
10
+ spec.email = ["colinobyrne@gmail.com", "whitney.schaefer@gmail.com"]
11
+ spec.description = %q{Opens SMSs sent via twilio}
12
+ spec.summary = %q{Opens SMSs sent via twilio to make development easier.}
13
+ spec.homepage = "http://github.com/cobyrne/text_opener"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "twilio-ruby"
22
+ spec.add_dependency "launchy"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "webmock"
28
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: text_opener
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Colin O'Byrne
8
+ - Whitney Schaefer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-05-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: twilio-ruby
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: launchy
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '1.3'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '1.3'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: webmock
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ description: Opens SMSs sent via twilio
99
+ email:
100
+ - colinobyrne@gmail.com
101
+ - whitney.schaefer@gmail.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - .gitignore
107
+ - .ruby-version
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - lib/text_opener.rb
113
+ - lib/text_opener/version.rb
114
+ - spec/text_opener_spec.rb
115
+ - text_opener.gemspec
116
+ homepage: http://github.com/cobyrne/text_opener
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.0.14
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Opens SMSs sent via twilio to make development easier.
140
+ test_files:
141
+ - spec/text_opener_spec.rb