suls-smsr 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ # require 'autotest/rspec'
2
+ require 'autotest/redgreen'
3
+ require 'autotest/growl'
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ coverage/
3
+ doc/
4
+ pkg/
@@ -0,0 +1,5 @@
1
+ === Version 0.1.0
2
+
3
+ This is the first preview release of SmsR.
4
+
5
+ * Added main bin/smsr file
@@ -0,0 +1,38 @@
1
+ .autotest
2
+ .gitignore
3
+ History.txt
4
+ Manifest.txt
5
+ README.txt
6
+ Rakefile
7
+ bin/smsr
8
+ bin/smsr-config
9
+ bin/smsr-send
10
+ lib/providers/hispeed.rb
11
+ lib/providers/o2.rb
12
+ lib/providers/orange.rb
13
+ lib/providers/swisscom.rb
14
+ lib/smsr.rb
15
+ lib/smsr/actions.rb
16
+ lib/smsr/actions/config.rb
17
+ lib/smsr/actions/list.rb
18
+ lib/smsr/actions/send.rb
19
+ lib/smsr/config.rb
20
+ lib/smsr/extensions.rb
21
+ lib/smsr/providers.rb
22
+ lib/smsr/providers/provider.rb
23
+ lib/smsr/smsr.rb
24
+ lib/smsr/version.rb
25
+ smsr.gemspec
26
+ spec/providers/hispeed_spec.rb
27
+ spec/providers/orange_spec.rb
28
+ spec/providers/provider_helper.rb
29
+ spec/providers/swisscom_spec.rb
30
+ spec/smsr/actions/config_spec.rb
31
+ spec/smsr/actions/send_spec.rb
32
+ spec/smsr/actions_requirements_spec.rb
33
+ spec/smsr/actions_spec.rb
34
+ spec/smsr/config_spec.rb
35
+ spec/smsr/providers_spec.rb
36
+ spec/smsr/version_spec.rb
37
+ spec/smsr_spec.rb
38
+ spec/spec_helper.rb
@@ -0,0 +1,70 @@
1
+ = SmsR
2
+
3
+ * http://sulsarts.ch/p/smsr
4
+
5
+ == DESCRIPTION:
6
+
7
+ SmsR is a simple command line SMS sender utility.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * lots
12
+
13
+ == SYNOPSIS:
14
+
15
+ Add a new provider like this:
16
+
17
+ desc "my sample operator"
18
+ provider :sample_operator do |user, password, number, text|
19
+ # login on the website and send SMS
20
+ end
21
+
22
+ Setup the provider by providing username and password:
23
+
24
+ smsr-config sample_operator my_username my_password
25
+
26
+ Your provider is now available:
27
+
28
+ smsr-send sample_operator +41XXXXXXXXX "this is your text message"
29
+
30
+ == INSTALL:
31
+
32
+ [sudo] gem install rspec
33
+
34
+ or
35
+
36
+ git clone git://github.com/suls/smsr.git
37
+ cd smsr
38
+ rake gem
39
+ rake install_gem
40
+
41
+ == ACKNOWLEDGEMENTS:
42
+
43
+ Thanks to Mirko Stocker for the idea (http://blog.misto.ch/archives/606) and
44
+ to Gui for the Swisscom provider
45
+ (http://giu.me/01-09-2008-sms-senden-leicht-gemacht-swisscom.html).
46
+
47
+ == LICENSE:
48
+
49
+ (The MIT License)
50
+
51
+ Copyright (c) 2008 Mathias Sulser
52
+
53
+ Permission is hereby granted, free of charge, to any person obtaining
54
+ a copy of this software and associated documentation files (the
55
+ 'Software'), to deal in the Software without restriction, including
56
+ without limitation the rights to use, copy, modify, merge, publish,
57
+ distribute, sublicense, and/or sell copies of the Software, and to
58
+ permit persons to whom the Software is furnished to do so, subject to
59
+ the following conditions:
60
+
61
+ The above copyright notice and this permission notice shall be
62
+ included in all copies or substantial portions of the Software.
63
+
64
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
65
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
66
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
67
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
68
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
69
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
70
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,70 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
+
3
+ require 'rake'
4
+ require 'hoe'
5
+ require 'spec/rake/spectask'
6
+ require 'spec/rake/verify_rcov'
7
+ require 'smsr/version'
8
+
9
+
10
+ desc "Clean up everything"
11
+ task :clean => ["spec:clobber_rcov", "hoe:clean"] do
12
+ end
13
+
14
+ namespace :hoe do
15
+ $hoe = Hoe.new('smsr', SmsR::VERSION::STRING) do |p|
16
+ p.summary = SmsR::VERSION::SUMMARY
17
+ p.url = 'http://sulsarts.ch/p/smsr'
18
+ p.description = "Simple commandline utility for sending sms."
19
+ p.developer('Mathias Sulser', 'suls@suls.org')
20
+ p.extra_deps << ["mechanize", ">= 0.7.8"] << ["rspec", ">= 1.1.4"]
21
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
22
+ end
23
+
24
+ ['audit','test','test_deps','default','publish_docs',
25
+ 'announce', 'post_blog', 'post_news'].
26
+ map{ |tsk| 'hoe:'+tsk}.
27
+ each do |task|
28
+ Rake.application.instance_variable_get('@tasks').delete(task)
29
+ end
30
+ end
31
+
32
+ namespace :spec do
33
+ desc "Run all specs with rcov"
34
+ Spec::Rake::SpecTask.new('rcov') do |t|
35
+ t.spec_files = FileList['spec/**/*_spec.rb']
36
+
37
+ t.rcov = true
38
+ t.rcov_opts <<
39
+ '--exclude' <<
40
+ 'spec,gems' <<
41
+ "--text-report"
42
+ end
43
+
44
+ desc "Check spec coverage"
45
+ RCov::VerifyTask.new(:coverage => "spec:rcov") do |t|
46
+ t.threshold = 90.0 # Make sure you have rcov 0.7 or higher!
47
+ t.index_html = File.dirname(__FILE__) + '/coverage/index.html'
48
+
49
+ system "open coverage/index.html" if RUBY_PLATFORM =~ /darwin/
50
+ end
51
+
52
+ desc "Run all specs"
53
+ Spec::Rake::SpecTask.new('run') do |t|
54
+ t.spec_files = FileList['spec/**/*.rb']
55
+ end
56
+ end
57
+
58
+ namespace :gemspec do
59
+ desc 'Refresh smsr.gemspec to include ALL files'
60
+ task :refresh => 'manifest:refresh' do
61
+ File.open('smsr.gemspec', 'w') {|io| io.write($hoe.spec.to_ruby)}
62
+ end
63
+ end
64
+
65
+ namespace :manifest do
66
+ desc 'Recreate Manifest.txt to include ALL files'
67
+ task :refresh do
68
+ `rake hoe:check_manifest | patch -p0 > Manifest.txt`
69
+ end
70
+ end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby -wKU
2
+ require File.dirname(__FILE__) + '/../lib/smsr'
3
+
4
+ SmsR.start ARGV
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../lib/smsr'
3
+
4
+ SmsR.start ["config", *ARGV]
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../lib/smsr'
3
+
4
+ SmsR.start ["send", *ARGV]
@@ -0,0 +1,35 @@
1
+ require "rubygems"
2
+ require "mechanize"
3
+
4
+ provider :hispeed do |user, password, number, message|
5
+ SmsR.debug "args: ", user, password, number, message
6
+
7
+ WWW::Mechanize.new do |agent|
8
+ SmsR.debug "logging in .."
9
+ agent.get('https://your.hispeed.ch/') do |page|
10
+ find_form_with_field(page, 'mail') do |f|
11
+ f.mail = user
12
+ f.password = password
13
+ f.submit
14
+ end
15
+ end
16
+ SmsR.debug ".. done"
17
+
18
+ agent.get('https://your.hispeed.ch/de/apps/messenger/') do |page|
19
+ SmsR.debug "start sending .."
20
+
21
+ iframe = page.iframes.text('external_application')
22
+ agent.get(iframe.src) do |inner_page|
23
+ form = inner_page.form('smsBean')
24
+ form.recipient = number
25
+ form.checkboxes.name('recipientChecked').check
26
+ form.message = message
27
+ form.submit
28
+ end
29
+
30
+ SmsR.debug ".. done"
31
+ end
32
+
33
+ SmsR.info "SMS '#{message}' sent to #{number}"
34
+ end
35
+ end
@@ -0,0 +1,28 @@
1
+ require "rubygems"
2
+ require "mechanize"
3
+
4
+ provider :o2 do |user, password, number, message|
5
+ SmsR.debug "args: ", user, password, number, message
6
+ WWW::Mechanize.new do |agent|
7
+ SmsR.debug "logging in .."
8
+ site = "http://www.o2.co.uk/login?dest=http://sendtxt.o2.co.uk/sendtxt/action/compose"
9
+ agent.get(site) do |page|
10
+ form = page.form("o2portal_sign_in_form")
11
+ form["USERNAME"] = user
12
+ form["PASSWORD"] = password
13
+ form.submit
14
+ end
15
+ SmsR.debug ".. done"
16
+
17
+ agent.get("http://sendtxt.o2.co.uk/sendtxt/action/compose") do |page|
18
+
19
+ form = page.form("sendtxtform")
20
+ form["compose.to"] = number
21
+ form["compose.message"] = message
22
+ # pp form.buttons[-2]
23
+ form.click_button form.buttons[-2]
24
+ SmsR.debug "start sending .."
25
+ end
26
+ SmsR.debug ".. done"
27
+ end
28
+ end
@@ -0,0 +1,34 @@
1
+ require "rubygems"
2
+ require "mechanize"
3
+
4
+ # from Mirko
5
+ # http://blog.misto.ch/archives/606
6
+ provider :orange do |user, password, number, message|
7
+ SmsR.debug "args: ", user, password, number, message
8
+
9
+ WWW::Mechanize.new do |agent|
10
+ SmsR.debug "logging in .."
11
+ agent.get('https://www.orange.ch/footer/login') do |page|
12
+ find_form_with_field(page, 'username') do |f|
13
+ f.username = user
14
+ f.password = password
15
+ f.submit
16
+ end
17
+ end
18
+ SmsR.debug ".. done"
19
+
20
+ agent.get('https://www.orange.ch/myorange/sms') do |page|
21
+ SmsR.debug "start sending .."
22
+ find_form_with_field(page, 'messageInput') do |f|
23
+ f.destinationNumberInput = number
24
+ f.messageInput = to_ISO_8859_1(message)
25
+ f.wui_target_id = 'sendButton'
26
+ f.wui_event_id = 'onclick'
27
+ f.submit
28
+ end
29
+ SmsR.debug ".. done"
30
+ end
31
+
32
+ SmsR.info "SMS '#{message}' sent to #{number}"
33
+ end
34
+ end
@@ -0,0 +1,41 @@
1
+ require "rubygems"
2
+ require "mechanize"
3
+
4
+ # from Gui
5
+ # http://giu.me/01-09-2008-sms-senden-leicht-gemacht-swisscom.html
6
+ provider :swisscom do |user, password, number, message|
7
+ SmsR.debug "args: ", user, password, number, message
8
+ WWW::Mechanize.new do |agent|
9
+ SmsR.debug "logging in .."
10
+ agent.get('https://www.swisscom-mobile.ch/selfreg/SelfRegistration?'+
11
+ 'uri=/youth/youth_zone_home-de.aspx') do |page|
12
+
13
+ find_form_with_field(page, 'isiwebuserid') do |f|
14
+ f.isiwebuserid = username
15
+ f.isiwebpasswd = password
16
+ f.submit
17
+ end
18
+ end
19
+ SmsR.debug ".. done"
20
+
21
+
22
+ agent.get('https://www.swisscom-mobile.ch'+
23
+ '/youth/sms_senden-de.aspx') do |page|
24
+ SmsR.debug "start sending .."
25
+ find_form_with_field(page, 'CobYouthSMSSenden:txtMessage') do |f|
26
+ f['CobYouthSMSSenden:txtNewReceiver']= number
27
+ f['CobYouthSMSSenden:txtMessage']= message
28
+ submit_button= nil
29
+ #finde den richtigen submit-button
30
+ f.buttons.each do |button|
31
+ if button.name = 'CobYouthSMSSenden:btnSend' then
32
+ submit_button= button
33
+ break
34
+ end
35
+ end
36
+ f.submit(submit_button)
37
+ end
38
+ end
39
+ SmsR.debug ".. done"
40
+ end
41
+ end
@@ -0,0 +1,12 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require "smsr/extensions"
4
+ require "smsr/smsr"
5
+ require "smsr/version"
6
+ require "smsr/config"
7
+ require "smsr/actions"
8
+ require "smsr/actions/config"
9
+ require "smsr/actions/send"
10
+ require "smsr/actions/list"
11
+ require "smsr/providers"
12
+ require "smsr/providers/provider"
@@ -0,0 +1,110 @@
1
+ module SmsR
2
+ module Actions
3
+
4
+ class RunnableAction
5
+ attr_writer :provider_name
6
+ class << self
7
+
8
+ def inherited(child)
9
+ child.instance_eval do
10
+ initialize_class
11
+ def self.run(*args)
12
+ args.flatten!
13
+ SmsR.debug "running #{self.name} .. (#run_#{args.size})",
14
+ "with args: #{args.join(',')}"
15
+ runner = self.new(args.first)
16
+
17
+ if runner.respond_to? :"run_#{args.size}"
18
+ SmsR.info runner.error unless runner.
19
+ send(:"run_#{args.size}", *args)
20
+ else
21
+ SmsR.info ".. doesn't know what to do.", "Please check 'smsr -h' ad see the available options."
22
+ end
23
+ end
24
+ end
25
+ super
26
+ end
27
+
28
+ def initialize_class
29
+
30
+ self.class_eval do
31
+ include SmsR::Actions.requirements
32
+ attr_reader :error
33
+ attr_accessor :requirements
34
+ define_method(:initialize) do |provider|
35
+ @provider_name = provider.to_sym if provider
36
+ @error = []
37
+ @requirements = []
38
+ end
39
+ end
40
+ end
41
+
42
+ def runnable(*reqs, &block)
43
+ n_of_block_args = if block.arity > 0
44
+ block.arity
45
+ else
46
+ 0
47
+ end
48
+
49
+ define_method(:"run_#{n_of_block_args}") do |*params|
50
+ self.requirements = reqs
51
+
52
+ SmsR.debug "defining #{self.class}.run method with params: ",
53
+ " #{params.join(',')}"
54
+ if check
55
+ instance_exec(*params, &block) if block_given?
56
+ return true
57
+ end
58
+ false
59
+ end
60
+
61
+ define_method(:check) do
62
+ requirements.inject(true) do |succ, req|
63
+ succ = self.send req.to_sym if succ
64
+ succ
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+ end
71
+
72
+ end
73
+
74
+ module Requirements
75
+
76
+ def config
77
+ @config = SmsR.config[@provider_name]
78
+ unless !!@config
79
+ @error << ["No config for #{provider_name} found. Run:",
80
+ "", " smsr-config #{provider_name} username password",
81
+ "", "to set up the config for the selected provider."]
82
+ end
83
+ !!@config
84
+ end
85
+
86
+ def provider
87
+ @provider = SmsR::Providers.providers[@provider_name]
88
+ unless !!@config
89
+ @error << ["Provider '#{@provider_name}' not found."]
90
+ end
91
+ !!@provider
92
+ end
93
+
94
+ def load_providers
95
+ require "rubygems"
96
+ require "rake"
97
+ providers = FileList["#{SmsR::Providers::DEFAULT_PROVIDERS}/*.rb"]
98
+ providers << ENV['HOME']+'/.smsr_providers'
99
+ SmsR.debug providers
100
+ @error = SmsR::Providers.load(*providers)
101
+ end
102
+ end
103
+ # module requirements
104
+ # included in Concr.Action
105
+
106
+ def self.requirements
107
+ Requirements
108
+ end
109
+ end
110
+ end