Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
221 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
CHANGELOG | ||
LICENSE | ||
MIT-LICENSE | ||
MANIFEST.txt | ||
README.txt | ||
Rakefile | ||
generators/sms/USAGE | ||
generators/sms/sms_generator.rb | ||
generators/sms/templates/fixture.rhtml | ||
generators/sms/templates/model.rb | ||
generators/sms/templates/unit_test.rb | ||
init.rb | ||
lib/activesms.rb | ||
lib/activesms/adv_attr_accessor.rb | ||
lib/activesms/base.rb | ||
lib/activesms/connection_adapters/abstract_adapter.rb | ||
lib/activesms/connection_adapters/bulk_sms_adapter.rb | ||
lib/activesms/connection_adapters/clickatell_adapter.rb | ||
lib/activesms/connection_adapters/simplewire_adapter.rb | ||
lib/activesms/connections.rb | ||
lib/activesms/exceptions.rb | ||
lib/activesms/sms.rb | ||
lib/activesms/validations.rb | ||
lib/activesms/version.rb | ||
scripts/txt2html | ||
setup.rb | ||
test/connection_adapters/test_simplewire_adapter.rb | ||
test/test_activesms.rb | ||
test/test_helper.rb | ||
website/index.html | ||
website/index.txt | ||
website/javascripts/rounded_corners_lite.inc.js | ||
website/stylesheets/screen.css | ||
website/template.rhtml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'rubygems' | ||
require 'redcloth' | ||
require 'syntax/convertors/html' | ||
require 'erb' | ||
require File.dirname(__FILE__) + '/../lib/activesms/version.rb' | ||
|
||
version = ActiveSms::VERSION::STRING | ||
download = 'http://rubyforge.org/projects/activesms' | ||
|
||
class Fixnum | ||
def ordinal | ||
# teens | ||
return 'th' if (10..19).include?(self % 100) | ||
# others | ||
case self % 10 | ||
when 1: return 'st' | ||
when 2: return 'nd' | ||
when 3: return 'rd' | ||
else return 'th' | ||
end | ||
end | ||
end | ||
|
||
class Time | ||
def pretty | ||
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}" | ||
end | ||
end | ||
|
||
def convert_syntax(syntax, source) | ||
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'') | ||
end | ||
|
||
if ARGV.length >= 1 | ||
src, template = ARGV | ||
template ||= File.dirname(__FILE__) + '/../website/template.rhtml' | ||
|
||
else | ||
puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html") | ||
exit! | ||
end | ||
|
||
template = ERB.new(File.open(template).read) | ||
|
||
title = nil | ||
body = nil | ||
File.open(src) do |fsrc| | ||
title_text = fsrc.readline | ||
body_text = fsrc.read | ||
syntax_items = [] | ||
body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</>!m){ | ||
ident = syntax_items.length | ||
element, syntax, source = $1, $2, $3 | ||
syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>" | ||
"syntax-temp-#{ident}" | ||
} | ||
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip | ||
body = RedCloth.new(body_text).to_html | ||
body.gsub!(%r!(?:<pre><code>)?syntax-temp-(d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] } | ||
end | ||
stat = File.stat(src) | ||
created = stat.ctime | ||
modified = stat.mtime | ||
|
||
$stdout << template.result(binding) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
puts "test" | ||
|
||
require File.dirname(__FILE__) + "/../test_helper" | ||
|
||
# Only run this test if using jruby | ||
if RUBY_PLATFORM =~ /java/ | ||
class SimplewireAdapterTest < Test::Unit::TestCase | ||
def setup | ||
@simplewire_adapter = ActiveSms::ConnectionAdapters::SimplewireAdapter.new(nil, { | ||
:subscriber_id => 'id', | ||
:subscriber_password => 'password'}) | ||
end | ||
|
||
def test_instantiation | ||
assert_raise(RuntimeError) { ActiveSms::ConnectionAdapters::SimplewireAdapter.new(nil, {}) } | ||
assert @simplewire_adapter | ||
end | ||
|
||
def test_sms_size | ||
sms = flexmock("sms") | ||
sms.should_receive(:subscriber_id).and_return("id") | ||
sms.should_receive(:subscriber_password).and_return("password") | ||
sms.should_receive(:recipients).and_return("4081234567") | ||
sms.should_receive(:from).and_return("6502435555") | ||
long_body = "" | ||
150.times {long_body += "x"} | ||
sms.should_receive(:body).and_return(long_body) | ||
|
||
assert_raise(StandardError) do | ||
s = @simplewire_adapter.create_sms(sms) | ||
end | ||
end | ||
|
||
def test_parse_sms | ||
xmldata = create_sms('121212', '6502435555', 'blah blah') | ||
sms = @simplewire_adapter.parse(xmldata) | ||
assert_equal 'blah blah', sms.body | ||
assert_equal '121212', sms.to | ||
assert_equal '6502435555', sms.from | ||
end | ||
|
||
def test_create_sms | ||
sms = flexmock("sms") | ||
sms.should_receive(:subscriber_id).and_return("id") | ||
sms.should_receive(:subscriber_password).and_return("password") | ||
sms.should_receive(:recipients).and_return("4081234567") | ||
sms.should_receive(:from).and_return("6502435555") | ||
sms.should_receive(:body).and_return("This is the body of the sms") | ||
|
||
s = @simplewire_adapter.create_sms(sms) | ||
|
||
assert_equal "id", s.subscriber_id | ||
assert_equal "password", s.subscriber_password | ||
assert_equal "4081234567", s.destination_addr.address | ||
assert_equal "6502435555", s.source_addr.address | ||
assert_equal "This is the body of the sms", s.msg_text | ||
end | ||
|
||
protected | ||
def create_sms(to, from, body) | ||
xmldata =<<END | ||
<?xml version="1.0" ?> | ||
<request version="3.0" protocol="wmp" type="deliver"> | ||
<account id="123-456-789-12345"/> | ||
<destination ton="3" address="#{to}"/> | ||
<source carrier="348" ton="1" address="#{from}"/> | ||
<option datacoding="7bit" /> | ||
<message udhi="true" data="0605040B8423F0#{body.unpack('H*')}"/> | ||
<ticket id="12004-0923R-1845S-10M25"/> | ||
</request> | ||
END | ||
xmldata | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'test/unit' | ||
|
||
class ActiveSmsTest < Test::Unit::TestCase | ||
# Replace this with your real tests. | ||
def test_this_plugin | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
$:.unshift(File.dirname(__FILE__) + "/../lib") | ||
|
||
require 'rubygems' | ||
require 'test/unit' | ||
require 'activesms' | ||
require 'flexmock/test_unit' |