telenorsms 0.0.1
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/Manifest +7 -0
- data/README +14 -0
- data/Rakefile +10 -0
- data/lib/telenorsms.rb +48 -0
- data/sendsms.rb +14 -0
- data/telenorsms.gemspec +30 -0
- data/test/telenorsms_spec.rb +43 -0
- metadata +80 -0
data/Manifest
ADDED
data/README
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
A library for sending SMS using Telenor's website.
|
|
2
|
+
Note: You have to be a customer of Telenor in order to login.
|
|
3
|
+
|
|
4
|
+
This library was inspired by http://github.com/fossmo/kjappsms
|
|
5
|
+
|
|
6
|
+
How to install?
|
|
7
|
+
Not a gem yet. Code must be forked
|
|
8
|
+
|
|
9
|
+
How to use?
|
|
10
|
+
sms_sender = TelenorSMS.new "91919191" "password"
|
|
11
|
+
sms_sender.send "hello world", "99999999"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
require 'echoe'
|
|
4
|
+
|
|
5
|
+
Echoe.new("telenorsms", "0.0.1") do |p|
|
|
6
|
+
p.description = "Send sms from Telenor's webpage www.telenor.no with Ruby. This lib is screen scraping the web page."
|
|
7
|
+
p.url = "http://github.com/goeran/telenorsms"
|
|
8
|
+
p.author = "Gøran Hansen"
|
|
9
|
+
p.email = "mail@goeran.no"
|
|
10
|
+
end
|
data/lib/telenorsms.rb
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'open-uri'
|
|
3
|
+
require 'mechanize'
|
|
4
|
+
|
|
5
|
+
module Guard
|
|
6
|
+
def Guard.require expression, message
|
|
7
|
+
if expression == false then raise message end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class TelenorSMS
|
|
12
|
+
def initialize username, password
|
|
13
|
+
Guard::require username != nil && username != "", "username must be specified"
|
|
14
|
+
Guard::require password != nil && password != "", "password must be specified"
|
|
15
|
+
|
|
16
|
+
@agent = Mechanize.new
|
|
17
|
+
@agent.user_agent_alias = "Windows IE 6"
|
|
18
|
+
@login_url = "https://telenormobil.no/minesider/login.do"
|
|
19
|
+
login username, password
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def login username, password
|
|
23
|
+
forms = @agent.get(@login_url).forms
|
|
24
|
+
login_form = nil
|
|
25
|
+
forms.each {|form| login_form = form if form.action == "https://telenormobil.no/minesider/login.do" }
|
|
26
|
+
login_form.j_username = username
|
|
27
|
+
login_form.j_password = password
|
|
28
|
+
@agent.submit(login_form)
|
|
29
|
+
|
|
30
|
+
if @agent.page.uri.to_s == @login_url then
|
|
31
|
+
error = @agent.page / "div[id='main_content']" / "div[class='section error']" / "span"
|
|
32
|
+
if error != nil then raise error.inner_html end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def send message, recipients
|
|
37
|
+
Guard::require message != nil && message != "", "Must contain message"
|
|
38
|
+
Guard::require recipients != nil && recipients != "", "Must contain recipients"
|
|
39
|
+
|
|
40
|
+
@agent.get "https://telenormobil.no/norm/telenor/sms/send.do"
|
|
41
|
+
sms_form = nil
|
|
42
|
+
@agent.page.forms.each{|form| sms_form = form if form.action == "/norm/telenor/sms/send/process.do" }
|
|
43
|
+
sms_form.toAddress = recipients
|
|
44
|
+
sms_form.message = message
|
|
45
|
+
sms_form.click_button
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
data/sendsms.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'lib/telenorsms'
|
|
2
|
+
|
|
3
|
+
username = ARGV[0]
|
|
4
|
+
password = ARGV[1]
|
|
5
|
+
message = ARGV[2]
|
|
6
|
+
recipients = ARGV[3]
|
|
7
|
+
|
|
8
|
+
Guard::require username != nil, "Username must be specified (first arg)"
|
|
9
|
+
Guard::require password != nil, "Password must be specified (second arg)"
|
|
10
|
+
Guard::require message != nil, "Message must be specified (third arg)"
|
|
11
|
+
Guard::require recipients != nil, "Recipients must be specified (forth arg)"
|
|
12
|
+
|
|
13
|
+
sms_sender = TelenorSMS.new username, password
|
|
14
|
+
sms_sender.send message, recipients
|
data/telenorsms.gemspec
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |s|
|
|
4
|
+
s.name = %q{telenorsms}
|
|
5
|
+
s.version = "0.0.1"
|
|
6
|
+
|
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
|
8
|
+
s.authors = ["G\303\270ran Hansen"]
|
|
9
|
+
s.date = %q{2010-09-30}
|
|
10
|
+
s.description = %q{Send sms from Telenor's webpage www.telenor.no with Ruby. This lib is screen scraping the web page.}
|
|
11
|
+
s.email = %q{mail@goeran.no}
|
|
12
|
+
s.extra_rdoc_files = ["README", "lib/telenorsms.rb"]
|
|
13
|
+
s.files = ["README", "Rakefile", "lib/telenorsms.rb", "sendsms.rb", "telenorsms.gemspec", "test/telenorsms_spec.rb", "Manifest"]
|
|
14
|
+
s.homepage = %q{http://github.com/goeran/telenorsms}
|
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Telenorsms", "--main", "README"]
|
|
16
|
+
s.require_paths = ["lib"]
|
|
17
|
+
s.rubyforge_project = %q{telenorsms}
|
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
|
19
|
+
s.summary = %q{Send sms from Telenor's webpage www.telenor.no with Ruby. This lib is screen scraping the web page.}
|
|
20
|
+
|
|
21
|
+
if s.respond_to? :specification_version then
|
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
23
|
+
s.specification_version = 3
|
|
24
|
+
|
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
26
|
+
else
|
|
27
|
+
end
|
|
28
|
+
else
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'spec'
|
|
3
|
+
require 'lib/telenorsms'
|
|
4
|
+
|
|
5
|
+
describe TelenorSMS, "when creating object" do
|
|
6
|
+
it "should validate username argument" do
|
|
7
|
+
lambda { TelenorSMS.new nil, "a password" }.should raise_exception
|
|
8
|
+
lambda { TelenorSMS.new "", "a password" }.should raise_exception
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should validate password argument" do
|
|
12
|
+
lambda { TelenorSMS.new "username", nil }.should raise_exception
|
|
13
|
+
lambda { TelenorSMS.new "username", "" }.should raise_exception
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe TelenorSMS, "when providing wrong credentials" do
|
|
18
|
+
it "should raise exception" do
|
|
19
|
+
lambda { TelenorSMS.new "99999999", "wrongpass" }.should raise_exception
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe TelenorSMS, "when sending message" do
|
|
24
|
+
class TelenorSMSFake < TelenorSMS
|
|
25
|
+
def login username, password
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
before :all do
|
|
31
|
+
@sms_sender = TelenorSMSFake.new "99999999", "password"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should validate message argument" do
|
|
35
|
+
lambda { @sms_sender.send nil, "91919191" }.should raise_exception "Must contain message"
|
|
36
|
+
lambda { @sms_sender.send "", "91919191" }.should raise_exception "Must contain message"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should validate recipients argument" do
|
|
40
|
+
lambda { @sms_sender.send "hello", nil }.should raise_exception "Must contain recipients"
|
|
41
|
+
lambda { @sms_sender.send "hello", "" }.should raise_exception "Must contain recipients"
|
|
42
|
+
end
|
|
43
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: telenorsms
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 29
|
|
5
|
+
prerelease: false
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 0
|
|
9
|
+
- 1
|
|
10
|
+
version: 0.0.1
|
|
11
|
+
platform: ruby
|
|
12
|
+
authors:
|
|
13
|
+
- "G\xC3\xB8ran Hansen"
|
|
14
|
+
autorequire:
|
|
15
|
+
bindir: bin
|
|
16
|
+
cert_chain: []
|
|
17
|
+
|
|
18
|
+
date: 2010-09-30 00:00:00 +02:00
|
|
19
|
+
default_executable:
|
|
20
|
+
dependencies: []
|
|
21
|
+
|
|
22
|
+
description: Send sms from Telenor's webpage www.telenor.no with Ruby. This lib is screen scraping the web page.
|
|
23
|
+
email: mail@goeran.no
|
|
24
|
+
executables: []
|
|
25
|
+
|
|
26
|
+
extensions: []
|
|
27
|
+
|
|
28
|
+
extra_rdoc_files:
|
|
29
|
+
- README
|
|
30
|
+
- lib/telenorsms.rb
|
|
31
|
+
files:
|
|
32
|
+
- README
|
|
33
|
+
- Rakefile
|
|
34
|
+
- lib/telenorsms.rb
|
|
35
|
+
- sendsms.rb
|
|
36
|
+
- telenorsms.gemspec
|
|
37
|
+
- test/telenorsms_spec.rb
|
|
38
|
+
- Manifest
|
|
39
|
+
has_rdoc: true
|
|
40
|
+
homepage: http://github.com/goeran/telenorsms
|
|
41
|
+
licenses: []
|
|
42
|
+
|
|
43
|
+
post_install_message:
|
|
44
|
+
rdoc_options:
|
|
45
|
+
- --line-numbers
|
|
46
|
+
- --inline-source
|
|
47
|
+
- --title
|
|
48
|
+
- Telenorsms
|
|
49
|
+
- --main
|
|
50
|
+
- README
|
|
51
|
+
require_paths:
|
|
52
|
+
- lib
|
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
|
+
none: false
|
|
55
|
+
requirements:
|
|
56
|
+
- - ">="
|
|
57
|
+
- !ruby/object:Gem::Version
|
|
58
|
+
hash: 3
|
|
59
|
+
segments:
|
|
60
|
+
- 0
|
|
61
|
+
version: "0"
|
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
|
+
none: false
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
hash: 11
|
|
68
|
+
segments:
|
|
69
|
+
- 1
|
|
70
|
+
- 2
|
|
71
|
+
version: "1.2"
|
|
72
|
+
requirements: []
|
|
73
|
+
|
|
74
|
+
rubyforge_project: telenorsms
|
|
75
|
+
rubygems_version: 1.3.7
|
|
76
|
+
signing_key:
|
|
77
|
+
specification_version: 3
|
|
78
|
+
summary: Send sms from Telenor's webpage www.telenor.no with Ruby. This lib is screen scraping the web page.
|
|
79
|
+
test_files: []
|
|
80
|
+
|