virtual_sms 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 643672cccb3b99f08f897039c4cbc16549d500aa
4
+ data.tar.gz: 897b0bd15f0a933c6f2df730376466497d9e514f
5
+ SHA512:
6
+ metadata.gz: 3dee8e2c654df967e1f0e610874e2a97b9fbb2ee16a6f8323ae3ef43777ab2b4d1138f263b28f4074b3ab3872d89d524aec9170048c4031359f3146a2ad8a255
7
+ data.tar.gz: 164897889b2d300554c24a6890d2760eaf307d5ebf1d15645432890b4f1a81e9ca3d383a24359bf8b0c5c1f7a19d3d55151fc39a36a7f9a9baff540ef484410a
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # v0.1.0 / 2015-10-26
2
+
3
+ Create project
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Chen Yi-Cyuan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Virtual SMS
2
+
3
+ [![Build Status](https://api.travis-ci.org/emn178/virtual_sms.png)](https://travis-ci.org/emn178/virtual_sms)
4
+ [![Coverage Status](https://coveralls.io/repos/emn178/virtual_sms/badge.svg?branch=master)](https://coveralls.io/r/emn178/virtual_sms?branch=master)
5
+
6
+ A rails plugin that provides a virtual SMS box and [SMS Carrier](https://github.com/emn178/sms_carrier) delivery method. You can send SMS to this virtual SMS box instead of real SMS service in development environment, and you can preview the SMSes in this virtual SMS box in web page.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'virtual_sms', group: :development
14
+ ```
15
+ Make sure you have:
16
+ ```ruby
17
+ gem 'jquery-rails'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ bundle
23
+
24
+ ### Route
25
+ Add virtual SMS box route in your `config/route.rb`
26
+ ```Ruby
27
+ mount VirtualSms::Engine => "/virtual_sms" if Rails.env.development?
28
+ ```
29
+
30
+ ### Delivery Method
31
+ Set up delivery method of action mailer in your `config/environments/developmnet.rb`
32
+ ```Ruby
33
+ config.sms_carrier.delivery_method = :virtual
34
+ ```
35
+
36
+ ## Usage
37
+ Now, you can go to http://localhost:3000/virtual_sms and check the SMSes!
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
42
+
43
+ ## Contact
44
+ The project's website is located at https://github.com/emn178/virtual_sms
45
+ Author: emn178@gmail.com
data/Rakefile ADDED
@@ -0,0 +1,16 @@
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
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
8
+ load 'rails/tasks/engine.rake'
9
+
10
+ Bundler::GemHelper.install_tasks
11
+
12
+ require "rspec/core/rake_task"
13
+
14
+ RSpec::Core::RakeTask.new(:spec)
15
+
16
+ task :default => :spec
@@ -0,0 +1,15 @@
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 jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,113 @@
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
+ */
16
+
17
+ /* http://meyerweb.com/eric/tools/css/reset/
18
+ v2.0 | 20110126
19
+ License: none (public domain)
20
+ */
21
+
22
+ html, body, div, span, applet, object, iframe,
23
+ h1, h2, h3, h4, h5, h6, p, blockquote, pre,
24
+ a, abbr, acronym, address, big, cite, code,
25
+ del, dfn, em, img, ins, kbd, q, s, samp,
26
+ small, strike, strong, sub, sup, tt, var,
27
+ b, u, i, center,
28
+ dl, dt, dd, ol, ul, li,
29
+ fieldset, form, label, legend,
30
+ table, caption, tbody, tfoot, thead, tr, th, td,
31
+ article, aside, canvas, details, embed,
32
+ figure, figcaption, footer, header, hgroup,
33
+ menu, nav, output, ruby, section, summary,
34
+ time, mark, audio, video {
35
+ margin: 0;
36
+ padding: 0;
37
+ border: 0;
38
+ font-size: 100%;
39
+ font: inherit;
40
+ vertical-align: baseline;
41
+ }
42
+ /* HTML5 display-role reset for older browsers */
43
+ article, aside, details, figcaption, figure,
44
+ footer, header, hgroup, menu, nav, section {
45
+ display: block;
46
+ }
47
+ body {
48
+ line-height: 1;
49
+ }
50
+ ol, ul {
51
+ list-style: none;
52
+ }
53
+ blockquote, q {
54
+ quotes: none;
55
+ }
56
+ blockquote:before, blockquote:after,
57
+ q:before, q:after {
58
+ content: '';
59
+ content: none;
60
+ }
61
+ table {
62
+ border-collapse: collapse;
63
+ border-spacing: 0;
64
+ }
65
+
66
+ body {
67
+ font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
68
+ font-size: 14px;
69
+ line-height: 1.42857143;
70
+ color: #333;
71
+ margin: 0 20px;
72
+ }
73
+
74
+ h2 {
75
+ font-size: 30px;
76
+ margin-top: 20px;
77
+ margin-bottom: 10px;
78
+ font-family: inherit;
79
+ font-weight: 500;
80
+ line-height: 1.1;
81
+ }
82
+
83
+ table {
84
+ border: 1px solid #ddd;
85
+ width: 100%;
86
+ max-width: 100%;
87
+ border-spacing: 0;
88
+ border-collapse: collapse;
89
+ }
90
+
91
+ tr:nth-of-type(odd) {
92
+ background-color: #f9f9f9;
93
+ }
94
+
95
+ tr:first-child>th {
96
+ border-top: 0;
97
+ }
98
+
99
+ th, td {
100
+ border-bottom-width: 2px;
101
+ border: 1px solid #ddd;
102
+ vertical-align: bottom;
103
+ border-bottom: 2px solid #ddd;
104
+ padding: 8px;
105
+ line-height: 1.42857143;
106
+ vertical-align: top;
107
+ border-top: 1px solid #ddd;
108
+ }
109
+
110
+ a {
111
+ text-decoration: none;
112
+ color: #007CFF;
113
+ }
@@ -0,0 +1,2 @@
1
+ class VirtualSms::ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,27 @@
1
+ module VirtualSms
2
+ class MessagesController < VirtualSms::ApplicationController
3
+ before_action :find_message, :only => [:show, :raw]
4
+
5
+ def index
6
+ @messages = VirtualSms::Message.all
7
+ end
8
+
9
+ def show
10
+ end
11
+
12
+ def raw
13
+ render :plain => @message.raw
14
+ end
15
+
16
+ def clear
17
+ VirtualSms::Message.clear
18
+ redirect_to messages_path
19
+ end
20
+
21
+ private
22
+
23
+ def find_message
24
+ @message = VirtualSms::Message.find(params[:id])
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,55 @@
1
+ require 'securerandom'
2
+
3
+ module VirtualSms
4
+ class Message
5
+ include ActionView::Helpers::TagHelper
6
+
7
+ attr_accessor :sms
8
+ delegate :body, :from, to: :sms
9
+
10
+ def initialize(sms)
11
+ @sms = sms
12
+ @sms[:sms_id] = SecureRandom.uuid
13
+ end
14
+
15
+ def id
16
+ @sms[:sms_id]
17
+ end
18
+
19
+ def to
20
+ addresses = @sms.to
21
+ address = addresses[0].to_s
22
+ count = addresses.length
23
+ count > 1 ? address + ", ...#{count - 1} more" : address
24
+ end
25
+
26
+ def list_to
27
+ @sms.to.join(', ')
28
+ end
29
+
30
+ def body_tag
31
+ content_tag :pre, body unless body.nil?
32
+ end
33
+
34
+ def raw
35
+ @sms.to_s
36
+ end
37
+
38
+ def self.all
39
+ messages = Rails.cache.fetch(CacheKey) do
40
+ messages = []
41
+ end
42
+ messages
43
+ end
44
+
45
+ def self.find(id)
46
+ message = all.find { |message| message.id == id }
47
+ raise ActiveRecord::RecordNotFound if message.nil?
48
+ message
49
+ end
50
+
51
+ def self.clear
52
+ Rails.cache.delete(CacheKey)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html>
3
+ <head>
4
+ <title>
5
+ Virtual SMS Box
6
+ </title>
7
+ <%= stylesheet_link_tag "virtual_sms/application", media: "all", "data-turbolinks-track" => true %>
8
+ <%= javascript_include_tag "virtual_sms/application", "data-turbolinks-track" => true %>
9
+ <%= csrf_meta_tags %>
10
+ </head>
11
+ <body>
12
+ <h2>
13
+ <%= link_to 'Virtual SMS Box', messages_path %>
14
+ </h2>
15
+ <%= yield %>
16
+ </body>
17
+ </html>
@@ -0,0 +1,27 @@
1
+ <%= link_to 'Clear', clear_messages_path, :method => :delete, :data => {:confirm => "Are you sure?"} %>
2
+ <table>
3
+ <colgroup>
4
+ <col width="250px"></col>
5
+ <col width="300px"></col>
6
+ <col></col>
7
+ <col width="200px"></col>
8
+ </colgroup>
9
+ <tr>
10
+ <th>From</th>
11
+ <th>To</th>
12
+ <th>Body</th>
13
+ </tr>
14
+ <% @messages.each do |message| %>
15
+ <tr>
16
+ <td>
17
+ <%= message.from %>
18
+ </td>
19
+ <td>
20
+ <%= message.to %>
21
+ </td>
22
+ <td>
23
+ <%= link_to message.body, message_path(:id => message.id) %>
24
+ </td>
25
+ </tr>
26
+ <% end %>
27
+ </table>
@@ -0,0 +1,25 @@
1
+ <table>
2
+ <tr>
3
+ <th>From</th>
4
+ <td>
5
+ <%= @message.from %>
6
+ <%= link_to '(Raw)', raw_message_path(:id => @message.id), :target => 'raw' %>
7
+ </td>
8
+ </tr>
9
+ <tr>
10
+ <th>To</th>
11
+ <td>
12
+ <%= @message.list_to %>
13
+ </td>
14
+ </tr>
15
+ <tr>
16
+ <th colspan="2">
17
+ Body
18
+ </th>
19
+ </tr>
20
+ <tr>
21
+ <td colspan="2">
22
+ <%= @message.body_tag %>
23
+ </td>
24
+ </tr>
25
+ </table>
data/config/routes.rb ADDED
@@ -0,0 +1,10 @@
1
+ VirtualSms::Engine.routes.draw do
2
+ resources :messages, :path => '/', :only => [:index, :show] do
3
+ member do
4
+ get 'raw'
5
+ end
6
+ collection do
7
+ delete 'clear'
8
+ end
9
+ end
10
+ end
data/config/spring.rb ADDED
@@ -0,0 +1 @@
1
+ Spring.application_root = './spec/dummy'
@@ -0,0 +1,15 @@
1
+ module VirtualSms
2
+ class Carrier
3
+ attr_accessor :settings
4
+
5
+ def initialize(settings)
6
+ self.settings = settings
7
+ end
8
+
9
+ def deliver!(sms)
10
+ messages = VirtualSms::Message.all
11
+ messages << VirtualSms::Message.new(sms)
12
+ Rails.cache.write(CacheKey, messages)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module VirtualSms
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace VirtualSms
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module VirtualSms
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ require "sms_carrier"
2
+ require "virtual_sms/engine"
3
+ require "virtual_sms/carrier"
4
+
5
+ module VirtualSms
6
+ CacheKey = 'virtual_sms'
7
+
8
+ SmsCarrier::Base.add_delivery_method :virtual, VirtualSms::Carrier
9
+ end
metadata ADDED
@@ -0,0 +1,204 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: virtual_sms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chen Yi-Cyuan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: sms_carrier
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jquery-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-its
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: coveralls
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: An rails plugin that provides a virtual SMS box and SMS Carrier delivery
154
+ method.
155
+ email:
156
+ - emn178@gmail.com
157
+ executables: []
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - CHANGELOG.md
162
+ - LICENSE.txt
163
+ - README.md
164
+ - Rakefile
165
+ - app/assets/javascripts/virtual_sms/application.js
166
+ - app/assets/stylesheets/virtual_sms/application.css
167
+ - app/controllers/virtual_sms/application_controller.rb
168
+ - app/controllers/virtual_sms/messages_controller.rb
169
+ - app/models/virtual_sms/message.rb
170
+ - app/views/layouts/virtual_sms/application.erb
171
+ - app/views/virtual_sms/messages/index.html.erb
172
+ - app/views/virtual_sms/messages/show.html.erb
173
+ - config/routes.rb
174
+ - config/spring.rb
175
+ - lib/virtual_sms.rb
176
+ - lib/virtual_sms/carrier.rb
177
+ - lib/virtual_sms/engine.rb
178
+ - lib/virtual_sms/version.rb
179
+ homepage: https://github.com/emn178/virtual_sms
180
+ licenses:
181
+ - MIT
182
+ metadata: {}
183
+ post_install_message:
184
+ rdoc_options: []
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ requirements: []
198
+ rubyforge_project:
199
+ rubygems_version: 2.4.8
200
+ signing_key:
201
+ specification_version: 4
202
+ summary: An rails plugin that provides a virtual SMS box and SMS Carrier delivery
203
+ method.
204
+ test_files: []