smsinabox 0.2.0
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.
- data/.gitignore +4 -0
- data/History.txt +13 -0
- data/PostInstall.txt +10 -0
- data/README.rdoc +47 -0
- data/Rakefile +29 -0
- data/TODO.txt +14 -0
- data/bin/sms-credit +38 -0
- data/bin/sms-send +76 -0
- data/bin/sms-setup +54 -0
- data/lib/smsinabox.rb +143 -0
- data/lib/smsinabox/configuration.rb +55 -0
- data/lib/smsinabox/delivery_report.rb +49 -0
- data/lib/smsinabox/exceptions.rb +9 -0
- data/lib/smsinabox/message.rb +21 -0
- data/lib/smsinabox/reply.rb +27 -0
- data/lib/smsinabox/sent_message.rb +32 -0
- data/lib/smsinabox/sms.rb +4 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/smsinabox.gemspec +101 -0
- data/spec/delivery_report_spec.rb +40 -0
- data/spec/fixtures/sendparam_response.xml +29 -0
- data/spec/message_spec.rb +47 -0
- data/spec/reply_spec.rb +36 -0
- data/spec/sent_message_spec.rb +40 -0
- data/spec/smsinabox_spec.rb +80 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +40 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/rspec.rake +21 -0
- data/tasks/website.rake +9 -0
- metadata +137 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Smsinabox::SentMessage do
|
4
|
+
before(:each) do
|
5
|
+
xml = <<-EOF
|
6
|
+
<api_result>
|
7
|
+
<data>
|
8
|
+
<changeid>26053853</changeid>
|
9
|
+
<sentid>339611089</sentid>
|
10
|
+
<eventid>33369735</eventid>
|
11
|
+
<smstype>SMS</smstype>
|
12
|
+
<numto>27123456789</numto>
|
13
|
+
<data>Foo</data>
|
14
|
+
<flash>false</flash>
|
15
|
+
<customerid/>
|
16
|
+
<status>DELIVRD</status>
|
17
|
+
<statusdate>07/Aug/2009 14:13:44</statusdate>
|
18
|
+
</data>
|
19
|
+
</api_result>
|
20
|
+
EOF
|
21
|
+
|
22
|
+
@xml_response = Nokogiri::XML( xml )
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should parse the sent message from the response" do
|
26
|
+
sent = Smsinabox::SentMessage.from_response( @xml_response.xpath('/api_result/data').first )
|
27
|
+
|
28
|
+
sent.id.should == 339611089
|
29
|
+
sent.change_id.should == 26053853
|
30
|
+
sent.event_id.should == 33369735
|
31
|
+
sent.type.should == 'SMS'
|
32
|
+
sent.to.should == '27123456789'
|
33
|
+
sent.message.should == 'Foo'
|
34
|
+
sent.flash.should be_false
|
35
|
+
sent.customer_id.should == ''
|
36
|
+
sent.status.should == 'DELIVRD'
|
37
|
+
sent.should be_delivered
|
38
|
+
sent.status_date.should == '07/Aug/2009 14:13:44'
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe Smsinabox, "configuration" do
|
4
|
+
|
5
|
+
it "should have a default base URI" do
|
6
|
+
Smsinabox.uri.to_s.should == "http://www.mymobileapi.com/api5/http5.aspx"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should accept a username" do
|
10
|
+
Smsinabox.username = 'test'
|
11
|
+
Smsinabox.username.should eql('test')
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should accept a password" do
|
15
|
+
Smsinabox.password = 'test'
|
16
|
+
Smsinabox.password.should eql('test')
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe Smsinabox do
|
22
|
+
before do
|
23
|
+
Smsinabox.username = 'test'
|
24
|
+
Smsinabox.password = 'test'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should know how much credit is available" do
|
28
|
+
#response = Object.new
|
29
|
+
#response.expects(:body).returns("<api_result><data><credits>0</credits></data><call_result><result>True</result><error /></call_result></api_result>")
|
30
|
+
#Net::HTTP.expects(:post_form).with( Smsinabox.uri, { :Type => 'credits', :Username => 'test', :Password => 'test'} ).returns( response )
|
31
|
+
mock_request(
|
32
|
+
{'Type' => 'credits', 'Username' => 'test', 'Password' => 'test'},
|
33
|
+
"<api_result><data><credits>0</credits></data><call_result><result>True</result><error /></call_result></api_result>"
|
34
|
+
)
|
35
|
+
|
36
|
+
Smsinabox.credit_remaining.should be(0)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should be able to deliver SMS-type messages" do
|
40
|
+
mock_request(
|
41
|
+
has_entries({ 'Type' => 'sendparam', 'Username' => 'test', 'Password' => 'test', 'numto' => '0123456789', 'data1' => 'Foo' }),
|
42
|
+
"<api_result><send_info><eventid>1</eventid><credits>1</credits><msgs_success>1</msgs_success></send_info><entries_success><numto>0123456789</numto></entries_success></api_result>"
|
43
|
+
)
|
44
|
+
|
45
|
+
sms = Smsinabox::SMS.new( :recipient => '0123456789', :body => 'Foo')
|
46
|
+
res = Smsinabox.deliver( sms )
|
47
|
+
|
48
|
+
res.should be_a( Smsinabox::DeliveryReport )
|
49
|
+
res.success_count.should be(1)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should be able to retrieve replies" do
|
53
|
+
mock_request(
|
54
|
+
has_entries({'Type' => 'replies', 'Username' => 'test', 'Password' => 'test', 'XMLData' => "<reply><settings><id>0</id><max_recs>100</max_recs><cols_returned>eventid,numfrom,receiveddata,received,sentid,sentdata,sentdatetime,sentcustomerid</cols_returned></settings></reply>"}),
|
55
|
+
"<api_result><data><replyid></replyid><eventid></eventid><numfrom>0123456789</numfrom><receiveddata>Bar</receiveddata><sentid></sentid><sentdata>Foo</sentdata><sentcustomerid/><received></received><senddatetime></senddatetime></data></api_result>"
|
56
|
+
)
|
57
|
+
|
58
|
+
Smsinabox.replies do |reply|
|
59
|
+
reply.should be_a( Smsinabox::Reply )
|
60
|
+
reply.from.should == '0123456789'
|
61
|
+
reply.message.should == 'Bar'
|
62
|
+
reply.original.should == 'Foo'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should be able to retrieve sent data" do
|
67
|
+
mock_request(
|
68
|
+
has_entries({'Type' => 'sent', 'Username' => 'test', 'Password' => 'test', 'XMLData' => "<sent><settings><id>0</id><max_recs>100</max_recs><cols_returned>sentid,eventid,smstype,numto,data,flash,customerid,status,statusdate</cols_returned></settings></sent>"}),
|
69
|
+
"<api_result><data><changeid></changeid><sentid></sentid><eventid></eventid><smstype>SMS</smstype><numto>0123456789</numto><data>Foo</data><flash>false</flash><customerid/><status>DELIVRD</status><statusdate></statusdate></data></api_result>"
|
70
|
+
)
|
71
|
+
|
72
|
+
results = Smsinabox.sent
|
73
|
+
results.size.should == 1
|
74
|
+
|
75
|
+
item = results.first
|
76
|
+
item.to.should == '0123456789'
|
77
|
+
item.message.should == 'Foo'
|
78
|
+
item.type.should == 'SMS'
|
79
|
+
end
|
80
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
5
|
+
gem 'rspec'
|
6
|
+
require 'spec'
|
7
|
+
end
|
8
|
+
|
9
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
10
|
+
require 'smsinabox'
|
11
|
+
|
12
|
+
Spec::Runner.configure do |config|
|
13
|
+
# == Mock Framework
|
14
|
+
#
|
15
|
+
# RSpec uses it's own mocking framework by default. If you prefer to
|
16
|
+
# use mocha, flexmock or RR, uncomment the appropriate line:
|
17
|
+
#
|
18
|
+
config.mock_with :mocha
|
19
|
+
# config.mock_with :flexmock
|
20
|
+
# config.mock_with :rr
|
21
|
+
end
|
22
|
+
|
23
|
+
# Horrible tactics to mock Net::HTTP
|
24
|
+
def mock_request( params, response_body )
|
25
|
+
mock_post = {}
|
26
|
+
mock_post.expects(:set_form_data).with(params)
|
27
|
+
#mock.expects(:[]=).with('user-agent', anything)
|
28
|
+
|
29
|
+
url = Smsinabox.uri
|
30
|
+
Net::HTTP::Post.expects(:new).with( url.path ).returns(mock_post)
|
31
|
+
|
32
|
+
response = Net::HTTPSuccess.new('1.1', 200, 'OK')
|
33
|
+
response.instance_variable_set :@body, response_body
|
34
|
+
response.instance_variable_set :@read, true
|
35
|
+
|
36
|
+
mock_http = Object.new
|
37
|
+
mock_http.expects(:start).returns(response)
|
38
|
+
|
39
|
+
Net::HTTP.expects(:new).with( url.host, url.port ).returns(mock_http)
|
40
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
desc 'Release the website and new gem version'
|
2
|
+
task :deploy => [:check_version, :website, :release] do
|
3
|
+
puts "Remember to create SVN tag:"
|
4
|
+
puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
|
5
|
+
"svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
|
6
|
+
puts "Suggested comment:"
|
7
|
+
puts "Tagging release #{CHANGES}"
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
|
11
|
+
task :local_deploy => [:website_generate, :install_gem]
|
12
|
+
|
13
|
+
task :check_version do
|
14
|
+
unless ENV['VERSION']
|
15
|
+
puts 'Must pass a VERSION=x.y.z release version'
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
unless ENV['VERSION'] == VERS
|
19
|
+
puts "Please update your version.rb to match the release version, currently #{VERS}"
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
|
25
|
+
task :install_gem_no_doc => [:clean, :package] do
|
26
|
+
sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
|
27
|
+
end
|
28
|
+
|
29
|
+
namespace :manifest do
|
30
|
+
desc 'Recreate Manifest.txt to include ALL files'
|
31
|
+
task :refresh do
|
32
|
+
`rake check_manifest | patch -p0 > Manifest.txt`
|
33
|
+
end
|
34
|
+
end
|
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
5
|
+
require 'spec'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'spec/rake/spectask'
|
9
|
+
rescue LoadError
|
10
|
+
puts <<-EOS
|
11
|
+
To use rspec for testing you must install rspec gem:
|
12
|
+
gem install rspec
|
13
|
+
EOS
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run the specs under spec/models"
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
19
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
+
end
|
data/tasks/website.rake
ADDED
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: smsinabox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kenneth.kalmer@gmail.com
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-06-18 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: nokogiri
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.3.3
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: cucumber
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
description: Ruby API for sending text messages via http://www.smsinabox.co.za
|
46
|
+
email: kenneth.kalmer@gmail.com
|
47
|
+
executables:
|
48
|
+
- sms-credit
|
49
|
+
- sms-send
|
50
|
+
- sms-setup
|
51
|
+
extensions: []
|
52
|
+
|
53
|
+
extra_rdoc_files:
|
54
|
+
- History.txt
|
55
|
+
- PostInstall.txt
|
56
|
+
- README.rdoc
|
57
|
+
- TODO.txt
|
58
|
+
files:
|
59
|
+
- .gitignore
|
60
|
+
- History.txt
|
61
|
+
- PostInstall.txt
|
62
|
+
- README.rdoc
|
63
|
+
- Rakefile
|
64
|
+
- TODO.txt
|
65
|
+
- bin/sms-credit
|
66
|
+
- bin/sms-send
|
67
|
+
- bin/sms-setup
|
68
|
+
- lib/smsinabox.rb
|
69
|
+
- lib/smsinabox/configuration.rb
|
70
|
+
- lib/smsinabox/delivery_report.rb
|
71
|
+
- lib/smsinabox/exceptions.rb
|
72
|
+
- lib/smsinabox/message.rb
|
73
|
+
- lib/smsinabox/reply.rb
|
74
|
+
- lib/smsinabox/sent_message.rb
|
75
|
+
- lib/smsinabox/sms.rb
|
76
|
+
- script/console
|
77
|
+
- script/destroy
|
78
|
+
- script/generate
|
79
|
+
- smsinabox.gemspec
|
80
|
+
- spec/delivery_report_spec.rb
|
81
|
+
- spec/fixtures/sendparam_response.xml
|
82
|
+
- spec/message_spec.rb
|
83
|
+
- spec/reply_spec.rb
|
84
|
+
- spec/sent_message_spec.rb
|
85
|
+
- spec/smsinabox_spec.rb
|
86
|
+
- spec/spec.opts
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
- tasks/deployment.rake
|
89
|
+
- tasks/environment.rake
|
90
|
+
- tasks/rspec.rake
|
91
|
+
- tasks/website.rake
|
92
|
+
has_rdoc: true
|
93
|
+
homepage: http://github.com/kennethkalmer/smsinabox
|
94
|
+
licenses: []
|
95
|
+
|
96
|
+
post_install_message: |
|
97
|
+
|
98
|
+
For more information on smsinabox, see http://www.opensourcery.co.za/smsinabox
|
99
|
+
|
100
|
+
Setup your account by running sms-setup now. You can then use the following
|
101
|
+
commands to interact with SMS in a Box:
|
102
|
+
|
103
|
+
sms-send: Send SMS messages
|
104
|
+
sms-credit: Quick overview of the credit available
|
105
|
+
sms-replies: Quick access to your replies
|
106
|
+
sms-setup: To change the account details
|
107
|
+
|
108
|
+
rdoc_options:
|
109
|
+
- --charset=UTF-8
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: "0"
|
117
|
+
version:
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: "0"
|
123
|
+
version:
|
124
|
+
requirements: []
|
125
|
+
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 1.3.5
|
128
|
+
signing_key:
|
129
|
+
specification_version: 3
|
130
|
+
summary: Ruby API for sending text messages via http://www.smsinabox.co.za
|
131
|
+
test_files:
|
132
|
+
- spec/delivery_report_spec.rb
|
133
|
+
- spec/message_spec.rb
|
134
|
+
- spec/reply_spec.rb
|
135
|
+
- spec/sent_message_spec.rb
|
136
|
+
- spec/smsinabox_spec.rb
|
137
|
+
- spec/spec_helper.rb
|