exetel_sms 1.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/CHANGELOG ADDED
@@ -0,0 +1 @@
1
+ v1.0. Initial commit
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2010, Andrew Snow
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ * this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright
10
+ * notice, this list of conditions and the following disclaimer in the
11
+ * documentation and/or other materials provided with the distribution.
12
+ * Neither the name of the author nor the names of its
13
+ * contributors may be used to endorse or promote products derived from
14
+ * this software without specific prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
+ POSSIBILITY OF SUCH DAMAGE.
data/Manifest ADDED
@@ -0,0 +1,11 @@
1
+ CHANGELOG
2
+ LICENSE
3
+ README
4
+ Rakefile
5
+ class_methods.rb
6
+ client.rb
7
+ config.rb
8
+ deleter.rb
9
+ receiver.rb
10
+ sender.rb
11
+ Manifest
data/README ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'echoe'
2
+ Echoe.new('exetel_sms') do |g|
3
+ g.summary = "Ruby gem to send and receive SMS via Exetel's API"
4
+ g.author = 'Andrew Snow'
5
+ g.email = 'andrew@modulus.org'
6
+ end
7
+
8
+
data/class_methods.rb ADDED
@@ -0,0 +1,32 @@
1
+
2
+ require 'uri'
3
+
4
+ module ExetelSms
5
+ module ClassMethods
6
+ def new_reference_number(ident='')
7
+ @@counter ||= 0
8
+ @@counter += 1
9
+ ident + ('%04X%02X%04X' % [Time.now.to_i, $$, @@counter])
10
+ end
11
+
12
+ def build_url(params_hash)
13
+ exetel_url + request_fields.map do |field|
14
+ raise "Missing field: #{field}" unless params_hash.has_key?(field)
15
+ encode(field.to_s) + '=' + encode(params_hash[field].to_s)
16
+ end.join('&')
17
+ end
18
+
19
+ def encode(str)
20
+ URI.encode(URI.encode(str), /=|&|\?/)
21
+ end
22
+
23
+ def response_to_hash(fields)
24
+ raise 'Missing fields in response body' unless fields.length >= response_fields.length
25
+ ret = {}
26
+ response_fields.each {|field| ret[field] = fields.shift }
27
+ ret[:other] = fields
28
+ ret
29
+ end
30
+
31
+ end
32
+ end
data/client.rb ADDED
@@ -0,0 +1,27 @@
1
+
2
+
3
+ require 'net/http'
4
+ require 'net/https'
5
+ require 'uri'
6
+
7
+ module ExetelSms
8
+ class Client
9
+ class << self
10
+
11
+ def request(url)
12
+ uri = URI.parse(url)
13
+ h = Net::HTTP.new(uri.host, uri.port)
14
+ h.use_ssl = true
15
+ h.verify_mode = OpenSSL::SSL::VERIFY_NONE
16
+ #h.set_debug_output $stderr
17
+ body = ''
18
+ h.start do |http|
19
+ response = http.request_get(uri.request_uri)
20
+ body = response.body
21
+ end
22
+ raise "No body" unless body && body =~ /|/
23
+ body.chomp.gsub(/<br>$/i, '').split('|').map {|str| str.strip }
24
+ end
25
+ end
26
+ end
27
+ end
data/config.rb ADDED
@@ -0,0 +1,13 @@
1
+
2
+ module ExetelSms
3
+ class Config
4
+
5
+ attr_reader :username, :password, :mvn
6
+
7
+ def initialize(username, password, mvn=nil)
8
+ @username = username
9
+ @password = password
10
+ @mvn = mvn
11
+ end
12
+ end
13
+ end
data/deleter.rb ADDED
@@ -0,0 +1,42 @@
1
+
2
+ require 'exetel_sms/client'
3
+ require 'exetel_sms/class_methods'
4
+
5
+ module ExetelSms
6
+
7
+ class Deleter
8
+ extend ExetelSms::ClassMethods
9
+
10
+ attr_reader :config
11
+ def initialize(config)
12
+ @config = config
13
+ end
14
+
15
+ def delete(from_mobile_number, message_id)
16
+ url = self.class.build_url(
17
+ :username => @config.username,
18
+ :password => @config.password,
19
+ :mobilenumber => from_mobile_number
20
+ :messageid => message_id
21
+ )
22
+
23
+ response_to_hash(ExetelSms::Client.request(url))
24
+ end
25
+
26
+ class << self
27
+
28
+ def response_fields
29
+ [:status, :notes]
30
+ end
31
+
32
+ def request_fields
33
+ [:username, :password, :mobilenumber, :messageid]
34
+ end
35
+
36
+ def exetel_url
37
+ 'https://www.exetel.com.au/sendsms/api_sms_mvn_delete.php?'
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{exetel_sms}
5
+ s.version = "1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Andrew Snow"]
9
+ s.date = %q{2010-08-25}
10
+ s.description = %q{Ruby gem to send and receive SMS via Exetel's API}
11
+ s.email = %q{andrew@modulus.org}
12
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README"]
13
+ s.files = ["CHANGELOG", "LICENSE", "README", "Rakefile", "class_methods.rb", "client.rb", "config.rb", "deleter.rb", "receiver.rb", "sender.rb", "Manifest", "exetel_sms.gemspec"]
14
+ s.homepage = %q{}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Exetel_sms", "--main", "README"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{exetel_sms}
18
+ s.rubygems_version = %q{1.3.7}
19
+ s.summary = %q{Ruby gem to send and receive SMS via Exetel's API}
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
data/receiver.rb ADDED
@@ -0,0 +1,41 @@
1
+
2
+ require 'exetel_sms/client'
3
+ require 'exetel_sms/class_methods'
4
+
5
+ module ExetelSms
6
+
7
+ class Receiver
8
+ extend ExetelSms::ClassMethods
9
+
10
+ attr_reader :config
11
+ def initialize(config)
12
+ @config = config
13
+ end
14
+
15
+ def receive(from_mobile_number)
16
+ url = self.class.build_url(
17
+ :username => @config.username,
18
+ :password => @config.password,
19
+ :mobilenumber => from_mobile_number
20
+ )
21
+
22
+ self.class.response_to_hash(ExetelSms::Client.request(url))
23
+ end
24
+
25
+ class << self
26
+
27
+ def response_fields
28
+ [:status, :exetel_id, :from_mobile_number, :received_at, :notes, :message]
29
+ end
30
+
31
+ def request_fields
32
+ [:username, :password, :mobilenumber]
33
+ end
34
+
35
+ def exetel_url
36
+ 'https://www.exetel.com.au/sendsms/api_sms_mvn_inbox.php?'
37
+ end
38
+
39
+ end
40
+ end
41
+ end
data/sender.rb ADDED
@@ -0,0 +1,46 @@
1
+
2
+ require 'exetel_sms/client'
3
+ require 'exetel_sms/class_methods'
4
+
5
+ module ExetelSms
6
+
7
+ class Sender
8
+ extend ExetelSms::ClassMethods
9
+
10
+ attr_reader :config
11
+ def initialize(config)
12
+ @config = config
13
+ end
14
+
15
+ def send(to_mobile_number, msg, from_mobile_number, reference_number)
16
+ url = self.class.build_url(
17
+ :username => @config.username,
18
+ :password => @config.password,
19
+ :sender => from_mobile_number,
20
+ :message => msg,
21
+ :messagetype => 'Text',
22
+ :referencenumber => reference_number,
23
+ :mobilenumber => to_mobile_number
24
+ )
25
+
26
+ self.class.response_to_hash(ExetelSms::Client.request(url))
27
+ end
28
+
29
+ class << self
30
+
31
+ def response_fields
32
+ [:status, :to_mobile_number, :reference_number, :exetel_id, :notes]
33
+ end
34
+
35
+ def request_fields
36
+ [:username, :password, :mobilenumber, :message, :sender, :messagetype, :referencenumber]
37
+ end
38
+
39
+ def exetel_url
40
+ 'https://www.exetel.com.au/sendsms/api_sms.php?'
41
+ #username=xxxxxxxx&password=xxxxxxxx&mobilenumber=xxxxxxxx&message=xxxxxxxx&sender=xxxxxxxxx&messagetype=Text&referencenumber=xxxxxx'
42
+ end
43
+
44
+ end
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exetel_sms
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ version: "1.0"
10
+ platform: ruby
11
+ authors:
12
+ - Andrew Snow
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-25 00:00:00 +10:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Ruby gem to send and receive SMS via Exetel's API
22
+ email: andrew@modulus.org
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - CHANGELOG
29
+ - LICENSE
30
+ - README
31
+ files:
32
+ - CHANGELOG
33
+ - LICENSE
34
+ - README
35
+ - Rakefile
36
+ - class_methods.rb
37
+ - client.rb
38
+ - config.rb
39
+ - deleter.rb
40
+ - receiver.rb
41
+ - sender.rb
42
+ - Manifest
43
+ - exetel_sms.gemspec
44
+ has_rdoc: true
45
+ homepage: ""
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --line-numbers
51
+ - --inline-source
52
+ - --title
53
+ - Exetel_sms
54
+ - --main
55
+ - README
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ hash: 3
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 11
73
+ segments:
74
+ - 1
75
+ - 2
76
+ version: "1.2"
77
+ requirements: []
78
+
79
+ rubyforge_project: exetel_sms
80
+ rubygems_version: 1.3.7
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Ruby gem to send and receive SMS via Exetel's API
84
+ test_files: []
85
+