kennethkalmer-smsinabox 0.0.2
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/History.txt +4 -0
- data/Manifest.txt +29 -0
- data/PostInstall.txt +10 -0
- data/README.rdoc +47 -0
- data/Rakefile +4 -0
- data/TODO.txt +14 -0
- data/bin/sms-credit +32 -0
- data/bin/sms-send +53 -0
- data/bin/sms-setup +51 -0
- data/config/hoe.rb +73 -0
- data/config/requirements.rb +15 -0
- data/lib/smsinabox.rb +66 -0
- data/lib/smsinabox/configuration.rb +47 -0
- data/lib/smsinabox/exceptions.rb +9 -0
- data/lib/smsinabox/message.rb +21 -0
- data/lib/smsinabox/version.rb +10 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/setup.rb +1585 -0
- data/smsinabox.gemspec +44 -0
- data/spec/message_spec.rb +47 -0
- data/spec/smsinabox_spec.rb +15 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -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 +107 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
PostInstall.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
TODO.txt
|
7
|
+
bin/sms-credit
|
8
|
+
bin/sms-send
|
9
|
+
bin/sms-setup
|
10
|
+
config/hoe.rb
|
11
|
+
config/requirements.rb
|
12
|
+
lib/smsinabox.rb
|
13
|
+
lib/smsinabox/configuration.rb
|
14
|
+
lib/smsinabox/exceptions.rb
|
15
|
+
lib/smsinabox/message.rb
|
16
|
+
lib/smsinabox/version.rb
|
17
|
+
script/console
|
18
|
+
script/destroy
|
19
|
+
script/generate
|
20
|
+
setup.rb
|
21
|
+
smsinabox.gemspec
|
22
|
+
spec/message_spec.rb
|
23
|
+
spec/smsinabox_spec.rb
|
24
|
+
spec/spec.opts
|
25
|
+
spec/spec_helper.rb
|
26
|
+
tasks/deployment.rake
|
27
|
+
tasks/environment.rake
|
28
|
+
tasks/rspec.rake
|
29
|
+
tasks/website.rake
|
data/PostInstall.txt
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
|
2
|
+
For more information on smsinabox, see http://www.opensourcery.co.za/smsinabox
|
3
|
+
|
4
|
+
Setup your account by running sms-setup now. You can then use the following
|
5
|
+
commands to interact with SMS in a Box:
|
6
|
+
|
7
|
+
sms-send: Send SMS messages
|
8
|
+
sms-credit: Quick overview of the credit available
|
9
|
+
sms-replies: Quick access to your replies
|
10
|
+
sms-setup: To change the account details
|
data/README.rdoc
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
= smsinabox
|
2
|
+
|
3
|
+
* http://www.opensourcery.co.za/smsinabox
|
4
|
+
* http://www.smsinabox.co.za/
|
5
|
+
|
6
|
+
== DESCRIPTION:
|
7
|
+
|
8
|
+
A Ruby wrapper for the SMS in a Box HTTP API, as well as command line tools for
|
9
|
+
sending SMS's and checking account balances
|
10
|
+
|
11
|
+
== FEATURES/PROBLEMS:
|
12
|
+
|
13
|
+
* Ruby module 'Smsinabox' for using in your own code
|
14
|
+
* sms-setup, sms-send, sms-credit & sms-replies CLI apps
|
15
|
+
|
16
|
+
== REQUIREMENTS:
|
17
|
+
|
18
|
+
* Developed and tested on Ruby 1.8.6
|
19
|
+
|
20
|
+
== INSTALL:
|
21
|
+
|
22
|
+
* sudo gem install kennethkalmer-smsinabox
|
23
|
+
|
24
|
+
== LICENSE:
|
25
|
+
|
26
|
+
(The MIT License)
|
27
|
+
|
28
|
+
Copyright (c) 2008 Kenneth Kalmer & SMS in a Box
|
29
|
+
|
30
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
31
|
+
a copy of this software and associated documentation files (the
|
32
|
+
'Software'), to deal in the Software without restriction, including
|
33
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
34
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
35
|
+
permit persons to whom the Software is furnished to do so, subject to
|
36
|
+
the following conditions:
|
37
|
+
|
38
|
+
The above copyright notice and this permission notice shall be
|
39
|
+
included in all copies or substantial portions of the Software.
|
40
|
+
|
41
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
42
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
43
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
44
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
45
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
46
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
47
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/TODO.txt
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
SMS in a BOX TODO
|
2
|
+
=================
|
3
|
+
|
4
|
+
Lets call this the builtin LightHouse :)
|
5
|
+
|
6
|
+
* Send bulk SMS messages
|
7
|
+
* Identify and handle invalid credentials
|
8
|
+
* Better exception generation and handling throughout the code
|
9
|
+
* Smsinabox::Message.to_xml
|
10
|
+
* Reply script
|
11
|
+
* Highline dependencies for better input
|
12
|
+
* SMS body input via STDIN
|
13
|
+
* Multiple accounts support
|
14
|
+
* Options to stay quite during operation
|
data/bin/sms-credit
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created on 2008-9-25.
|
4
|
+
# Copyright (c) 2008. All rights reserved.
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'rubygems'
|
8
|
+
rescue LoadError
|
9
|
+
# no rubygems to load, so we fail silently
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'smsinabox'
|
13
|
+
require 'optparse'
|
14
|
+
|
15
|
+
parser = OptionParser.new do |opts|
|
16
|
+
opts.banner = <<BANNER
|
17
|
+
Retrieve the number of credits in the account
|
18
|
+
|
19
|
+
Usage: #{File.basename($0)} [options]
|
20
|
+
|
21
|
+
Options are:
|
22
|
+
BANNER
|
23
|
+
opts.separator ""
|
24
|
+
opts.on("-h", "--help",
|
25
|
+
"Show this help message.") { puts opts; exit }
|
26
|
+
opts.parse!(ARGV)
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
Smsinabox.configure!
|
31
|
+
|
32
|
+
puts "Credits left: #{Smsinabox.credits}"
|
data/bin/sms-send
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created on 2008-9-25.
|
4
|
+
# Copyright (c) 2008. All rights reserved.
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'rubygems'
|
8
|
+
rescue LoadError
|
9
|
+
# no rubygems to load, so we fail silently
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'smsinabox'
|
13
|
+
require 'optparse'
|
14
|
+
|
15
|
+
OPTIONS = {
|
16
|
+
:recipient => nil,
|
17
|
+
:message => nil
|
18
|
+
}
|
19
|
+
MANDATORY_OPTIONS = %w( recipient message)
|
20
|
+
|
21
|
+
parser = OptionParser.new do |opts|
|
22
|
+
opts.banner = <<BANNER
|
23
|
+
Send a single SMS message to the specified recipient
|
24
|
+
|
25
|
+
Usage: #{File.basename($0)} [options]
|
26
|
+
|
27
|
+
Options are:
|
28
|
+
BANNER
|
29
|
+
opts.separator ""
|
30
|
+
opts.on("-r", "--recipient=RECIPIENT", String,
|
31
|
+
"The recipient of the SMS") { |r| OPTIONS[:recipient] = r }
|
32
|
+
opts.on("-m", "--message=MESSAGE", String,
|
33
|
+
"The body of the message (wrap in quotes)") { |m| OPTIONS[:message] = m }
|
34
|
+
opts.on("-h", "--help",
|
35
|
+
"Show this help message.") { puts opts; exit }
|
36
|
+
opts.parse!(ARGV)
|
37
|
+
|
38
|
+
if MANDATORY_OPTIONS && MANDATORY_OPTIONS.find { |option| OPTIONS[option.to_sym].nil? }
|
39
|
+
puts opts; exit
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
Smsinabox.configure!
|
44
|
+
id = Smsinabox.send(
|
45
|
+
Smsinabox::Message.new(
|
46
|
+
:recipient => OPTIONS[:recipient], :body => OPTIONS[:message]
|
47
|
+
)
|
48
|
+
)
|
49
|
+
|
50
|
+
puts "Message sent"
|
51
|
+
puts "Reference: #{id}"
|
52
|
+
puts "Recipient: #{OPTIONS[:recipient]}"
|
53
|
+
puts "Message: #{OPTIONS[:message]}"
|
data/bin/sms-setup
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created on 2008-9-25.
|
4
|
+
# Copyright (c) 2008. All rights reserved.
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'rubygems'
|
8
|
+
rescue LoadError
|
9
|
+
# no rubygems to load, so we fail silently
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'smsinabox'
|
13
|
+
require 'optparse'
|
14
|
+
|
15
|
+
OPTIONS = {
|
16
|
+
:username => nil,
|
17
|
+
:password => nil
|
18
|
+
}
|
19
|
+
MANDATORY_OPTIONS = %w( username password )
|
20
|
+
|
21
|
+
parser = OptionParser.new do |opts|
|
22
|
+
opts.banner = <<BANNER
|
23
|
+
Configure your local SMS in a Box commands to use the supplied details.
|
24
|
+
|
25
|
+
The configuration file is located at ~/.smsinabox and will have permissions of
|
26
|
+
0600. It contains your password information in plain text, so be careful.
|
27
|
+
|
28
|
+
Usage: #{File.basename($0)} [options]
|
29
|
+
|
30
|
+
Options are:
|
31
|
+
BANNER
|
32
|
+
opts.separator ""
|
33
|
+
opts.on("-u", "--username=USERNAME", String,
|
34
|
+
"Username to use") { |u| OPTIONS[:username] = u }
|
35
|
+
opts.on("-p", "--password=PASSWORD", String,
|
36
|
+
"Password to use") { |p| OPTIONS[:password] = p }
|
37
|
+
opts.on("-h", "--help",
|
38
|
+
"Show this help message.") { puts opts; exit }
|
39
|
+
opts.parse!(ARGV)
|
40
|
+
|
41
|
+
if MANDATORY_OPTIONS && MANDATORY_OPTIONS.find { |option| OPTIONS[option.to_sym].nil? }
|
42
|
+
puts opts; exit
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
config = Smsinabox::Configuration.new
|
47
|
+
config[:username] = OPTIONS[:username]
|
48
|
+
config[:password] = OPTIONS[:password]
|
49
|
+
config.save
|
50
|
+
|
51
|
+
puts 'Configuration file updated.'
|
data/config/hoe.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'smsinabox/version'
|
2
|
+
|
3
|
+
AUTHOR = 'Kenneth Kalmer' # can also be an array of Authors
|
4
|
+
EMAIL = "kenneth.kalmer@gmail.com"
|
5
|
+
DESCRIPTION = "Ruby API for the SMS in a Box service, as well as command line utilities for interacting with SMS in a Box"
|
6
|
+
GEM_NAME = 'smsinabox' # what ppl will type to install your gem
|
7
|
+
RUBYFORGE_PROJECT = 'smsinabox' # The unix name for your project
|
8
|
+
HOMEPATH = "http://www.opensourcery.co.za/smsinabox"
|
9
|
+
DOWNLOAD_PATH = "http://github.com/kennethkalmer/smsinabox"
|
10
|
+
EXTRA_DEPENDENCIES = [
|
11
|
+
# ['activesupport', '>= 1.3.1']
|
12
|
+
] # An array of rubygem dependencies [name, version]
|
13
|
+
|
14
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
15
|
+
@config = nil
|
16
|
+
RUBYFORGE_USERNAME = "unknown"
|
17
|
+
def rubyforge_username
|
18
|
+
unless @config
|
19
|
+
begin
|
20
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
21
|
+
rescue
|
22
|
+
puts <<-EOS
|
23
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
24
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
25
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
26
|
+
EOS
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
end
|
30
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
REV = nil
|
35
|
+
# UNCOMMENT IF REQUIRED:
|
36
|
+
# REV = YAML.load(`svn info`)['Revision']
|
37
|
+
VERS = Smsinabox::VERSION::STRING + (REV ? ".#{REV}" : "")
|
38
|
+
RDOC_OPTS = ['--quiet', '--title', 'SMS in a Box documentation',
|
39
|
+
"--opname", "index.html",
|
40
|
+
"--line-numbers",
|
41
|
+
"--main", "README",
|
42
|
+
"--inline-source"]
|
43
|
+
|
44
|
+
class Hoe
|
45
|
+
def extra_deps
|
46
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
47
|
+
@extra_deps
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Generate all the Rake tasks
|
52
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
53
|
+
$hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
54
|
+
p.developer(AUTHOR, EMAIL)
|
55
|
+
p.description = DESCRIPTION
|
56
|
+
p.summary = DESCRIPTION
|
57
|
+
p.url = HOMEPATH
|
58
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
59
|
+
p.test_globs = ["test/**/test_*.rb"]
|
60
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
61
|
+
|
62
|
+
# == Optional
|
63
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
64
|
+
#p.extra_deps = EXTRA_DEPENDENCIES
|
65
|
+
|
66
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
67
|
+
end
|
68
|
+
|
69
|
+
CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
70
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
71
|
+
$hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
72
|
+
$hoe.rsync_args = '-av --delete --ignore-errors'
|
73
|
+
$hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
include FileUtils
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
6
|
+
begin
|
7
|
+
require req_gem
|
8
|
+
rescue LoadError
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
data/lib/smsinabox.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'net/http'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
require 'smsinabox/version'
|
8
|
+
require 'smsinabox/exceptions'
|
9
|
+
require 'smsinabox/message'
|
10
|
+
require 'smsinabox/configuration'
|
11
|
+
|
12
|
+
module Smsinabox
|
13
|
+
|
14
|
+
class << self
|
15
|
+
|
16
|
+
# Username for the SMS in a Box service
|
17
|
+
attr_accessor :username
|
18
|
+
|
19
|
+
# Password for the SMS in a Box service
|
20
|
+
attr_accessor :password
|
21
|
+
|
22
|
+
# Return the number of available credits
|
23
|
+
def credits
|
24
|
+
perform_request( 'type' => 'credits' ).to_i
|
25
|
+
end
|
26
|
+
|
27
|
+
# Send a SMS messages and return the message ID
|
28
|
+
def send( message )
|
29
|
+
raise MessageInvalid unless message.valid?
|
30
|
+
|
31
|
+
perform_request(
|
32
|
+
'type' => 'singlesms', 'Number' => message.recipient,
|
33
|
+
'Message' => message.body
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Set our username and password from ~/.smsinabox
|
38
|
+
def configure!
|
39
|
+
c = Configuration.new
|
40
|
+
@username = c["username"]
|
41
|
+
@password = c["password"]
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def perform_request( params = {})
|
48
|
+
raise MissingCredentialException if @username.nil? || @password.nil?
|
49
|
+
params.merge!( 'username' => @username, 'password' => @password )
|
50
|
+
|
51
|
+
url = URI.parse( "http://www.smsinabox.co.za/httppost4.aspx" )
|
52
|
+
req = Net::HTTP::Post.new( url.path )
|
53
|
+
req.set_form_data( params )
|
54
|
+
req['user-agent'] = 'SMS in a Box/' + Smsinabox::VERSION::STRING
|
55
|
+
res = Net::HTTP.new( url.host, url.port ).start { |http| http.request( req ) }
|
56
|
+
case res
|
57
|
+
when Net::HTTPSuccess
|
58
|
+
return res.body
|
59
|
+
else
|
60
|
+
raise "Could not complete request"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Smsinabox
|
4
|
+
class Configuration
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
check_file!
|
8
|
+
load_config
|
9
|
+
end
|
10
|
+
|
11
|
+
def []( key )
|
12
|
+
@configuration[key.to_s]
|
13
|
+
end
|
14
|
+
|
15
|
+
def []=( key, value )
|
16
|
+
@configuration[ key.to_s ] = value
|
17
|
+
end
|
18
|
+
|
19
|
+
def save
|
20
|
+
File.open( config_name, 'w' ) do |f|
|
21
|
+
YAML::dump( @configuration , f )
|
22
|
+
end
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def load_config
|
29
|
+
@configuration = File.open( config_name, 'r' ) do |f|
|
30
|
+
YAML::load( f )
|
31
|
+
end
|
32
|
+
rescue
|
33
|
+
@configuration = {}
|
34
|
+
end
|
35
|
+
|
36
|
+
def check_file!
|
37
|
+
unless File.exist?( config_name )
|
38
|
+
File.open( config_name, 'w' ) { |f| f.write('') }
|
39
|
+
File.chmod( 0600, config_name )
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def config_name
|
44
|
+
File.expand_path( File.join('~', '.smsinabox') )
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|