signupto 0.1.0 → 1.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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 YOUR NAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README CHANGED
@@ -1,13 +1,4 @@
1
- == USEAGE
1
+ signupto
2
+ =================
2
3
 
3
- account = Net::SMS::SignupTo::Account.new('YOUR ACCOUNT HASH', 'CUSTOMER NUMBER')
4
- message = Net::SMS::SignupTo::Message.new(RECIPIENT_NUMBER,'NAME OF SENDER (max 12 chars)', 'BODY OF MESSAGE, NON-URI encoded')
5
- send = Net::SMS::SignupTo::Send.new(account, message)
6
-
7
- Thats it.
8
-
9
- == TESTS
10
-
11
- Yes I know there are no tests yet and that its really bad.
12
-
13
- This lib is in early early alpha stages so I am getting there - please bear with me :)
4
+ Signupto SMS gateway client
data/Rakefile CHANGED
@@ -1,104 +1,35 @@
1
1
  require 'rubygems'
2
- require 'rake'
3
- require 'rake/testtask'
4
- require 'rake/rdoctask'
5
- require 'rake/packagetask'
6
2
  require 'rake/gempackagetask'
7
- require 'rake/contrib/rubyforgepublisher'
8
- require File.join(File.dirname(__FILE__), 'lib', 'net', 'sms','signupto')
3
+ require 'lib/signupto/version'
9
4
 
10
- PKG_NAME = 'signupto'
11
- PKG_VERSION = Net::SMS::SignupTo::Version.to_s
12
- PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
13
- RELEASE_NAME = PKG_VERSION
5
+ PLUGIN = "signupto"
6
+ NAME = "signupto"
7
+ VERSION = Signupto::Version::STRING
8
+ AUTHOR = "Tim Perrett"
9
+ EMAIL = "code@timperrett.com"
10
+ HOMEPAGE = "http://blog.timperrett.com"
11
+ SUMMARY = "Core connectivity to the signupto SMS gateway service"
14
12
 
15
- RDOC_TITLE = "SignUpTo SMS API Bindings"
16
- RDOC_EXTRAS = ["README", "CHANGELOG", 'TODO']
17
-
18
-
19
- namespace 'signupto' do
20
-
21
- # Generate the RDoc documentation
22
- Rake::RDocTask.new do |rdoc|
23
- rdoc.rdoc_dir = 'doc'
24
- rdoc.title = RDOC_TITLE
25
- rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
26
- rdoc.rdoc_files.include('README', 'CHANGELOG')
27
- rdoc.rdoc_files.include('lib/**/*.rb')
28
- end
29
-
30
- # gem spec
31
13
  spec = Gem::Specification.new do |s|
32
- s.name = PKG_NAME
33
- s.version = PKG_VERSION
34
- s.summary = 'An API client for sending SMS messages via the Signup.to service'
35
- #s.description = ""
36
- s.author = 'Tim Perrett'
37
- s.email = 'code@timperrett.com'
38
- s.homepage = 'http://www.timperrett.com'
14
+ s.name = NAME
15
+ s.version = VERSION
39
16
  s.platform = Gem::Platform::RUBY
40
- s.require_path = 'lib'
41
- s.autorequire = 'net/sms/signupto'
42
17
  s.has_rdoc = true
43
- s.rdoc_options << '--title' << RDOC_TITLE << '--line-numbers' << '--main' << 'README'
44
- s.extra_rdoc_files = RDOC_EXTRAS
45
- files = FileList['**/*']
46
- files.exclude '**/._*'
47
- files.exclude 'doc'
48
- files.exclude 'examples'
49
- files.exclude 'pkg'
50
- files.exclude '.svn/*'
51
- s.files = files.to_a
52
- end
53
-
54
- # specify the compression required
55
- Rake::GemPackageTask.new(spec) do |p|
56
- p.gem_spec = spec
57
- p.need_tar = true
58
- p.need_zip = true
59
- end
60
-
61
- desc "Uninstall Gem"
62
- task :uninstall_gem do
63
- sh "gem uninstall #{PKG_NAME}" rescue nil
64
- end
65
-
66
- desc "Build and install Gem from source"
67
- task :install_gem => [:package, :uninstall_gem] do
68
- dir = File.join(File.dirname(__FILE__), 'pkg')
69
- chdir(dir) do
70
- latest = Dir["#{PKG_NAME}-*.gem"].last
71
- sh "gem install #{latest}"
72
- end
73
- end
74
-
75
- desc "Display the current version"
76
- task :version do
77
- puts 'Current version of ' + PKG_NAME + ' is ' + PKG_VERSION
18
+ s.extra_rdoc_files = ["README", "LICENSE"]
19
+ s.summary = SUMMARY
20
+ s.description = s.summary
21
+ s.author = AUTHOR
22
+ s.email = EMAIL
23
+ s.homepage = HOMEPAGE
24
+ s.require_path = 'lib'
25
+ s.autorequire = PLUGIN
26
+ s.files = %w(LICENSE README Rakefile) + Dir.glob("{lib,spec}/**/*")
78
27
  end
79
28
 
80
- desc "display total number of lines in the codebase"
81
- task :lines do
82
- lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
83
-
84
- for file_name in FileList["lib/net/sms/**/*.rb"]
85
- # next if file_name =~ /vendor/
86
- f = File.open(file_name)
87
-
88
- while line = f.gets
89
- lines += 1
90
- next if line =~ /^\s*$/
91
- next if line =~ /^\s*#/
92
- codelines += 1
93
- end
94
- puts "L: #{sprintf("%4d", lines)}, LOC #{sprintf("%4d", codelines)} | #{file_name}"
95
-
96
- total_lines += lines
97
- total_codelines += codelines
98
-
99
- lines, codelines = 0, 0
100
- end
101
- puts "Total: Lines #{total_lines}, LOC #{total_codelines}"
29
+ Rake::GemPackageTask.new(spec) do |pkg|
30
+ pkg.gem_spec = spec
102
31
  end
103
32
 
104
- end
33
+ task :install => [:package] do
34
+ sh %{sudo gem install pkg/#{NAME}-#{VERSION}}
35
+ end
@@ -0,0 +1,9 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'signupto/account'
5
+ require 'signupto/message'
6
+ require 'signupto/action/base'
7
+ require 'signupto/action/balance'
8
+ require 'signupto/action/sender'
9
+ require 'signupto/base'
@@ -0,0 +1,19 @@
1
+ module Signupto
2
+ class Account
3
+
4
+ attr_reader :apihash
5
+ attr_reader :customer_number
6
+
7
+ # Pass in your account details to create an account object.
8
+ # Your +apihash+ and +cid+ which will both be found on the signup.to
9
+ # dashboard interface.
10
+ def initialize(apihash, customer_number)
11
+ @apihash, @customer_number = apihash, customer_number
12
+ end
13
+
14
+ def to_http
15
+ URI.encode("cid=#{@customer_number}&hash=#{@apihash}")
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ module Signupto
2
+ module Action
3
+ class Balance < Base
4
+
5
+ def initialize(account)
6
+ if account.is_a?(Account)
7
+ if super(account.apihash, account.customer_number)
8
+ payload = set_payload()
9
+ run_action(payload)
10
+ end
11
+ else
12
+ raise "ERROR"
13
+ end
14
+ end
15
+
16
+ protected
17
+
18
+ def set_payload
19
+ @payload = [@account.to_http, 'mode=balance'].join('&')
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,31 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+
4
+ module Signupto
5
+ module Action
6
+ class Base
7
+
8
+ # Parent class that all specific actions are derived.
9
+ def initialize(account_hash, customer_number)
10
+ @account = Signupto::Account.new(account_hash, customer_number)
11
+ end
12
+
13
+ def to_s
14
+ return @result.body
15
+ end
16
+
17
+ protected
18
+
19
+ # Actually make the call to the api URL. SignUp.to use a
20
+ # PHP response method, so I make a URI encoded GET to there servers
21
+ # and await the response; handling it appropriatly.
22
+ def run_action(payload, page = 'smpp_account')
23
+ Net::HTTP.start('sms.sign-up.to', 80) do |http|
24
+ @result = http.get('/'<< page << '.php?' << payload)
25
+ return @result
26
+ end
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,32 @@
1
+ module Signupto
2
+ module Action
3
+ class Sender < Base
4
+
5
+ def initialize(account, message)
6
+ if message.is_a?(Message) and account.is_a?(Account)
7
+ if super(account.apihash, account.customer_number)
8
+ @message = message
9
+ payload = set_payload()
10
+ run_action(payload, 'smpp_send')
11
+ end
12
+ else
13
+ raise "You can only supply a Message object"
14
+ end
15
+ end
16
+
17
+ protected
18
+
19
+ # Configure the payload to send on this text message.
20
+ # to - Recipient mobile number in full international format (no ‘+’ or ‘00’)
21
+ # message - Message body text
22
+ # from - SMS sender
23
+ # cost - Cost (in pence) to the recipient
24
+ # network - Recipient’s network
25
+ # smsc - ID of client selected SMS route
26
+ def set_payload
27
+ @payload = [@account.to_http, "to=#{@message.to.to_s}", "message=#{@message.body.to_s}", "from=#{@message.from.to_s}"].join('&')
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ module Signupto
2
+ class Base
3
+
4
+ class << self
5
+ # retrives your account balance and returns it as a string
6
+ def balance(options = {})
7
+ if options.has_key?(:account_hash) and options.has_key?(:customer_number)
8
+ account = Account.new(options[:account_hash], options[:customer_number])
9
+ return Action::Balance.new(account).to_s
10
+ end
11
+ end
12
+
13
+ # Upon a sucsesfull send this will return the message number for tracking purposese
14
+ # on the signupto systems.
15
+ def send!(options = {})
16
+ if options.has_key?(:account_hash) and options.has_key?(:customer_number)
17
+ account = Account.new(options[:account_hash], options[:customer_number])
18
+ if options.has_key?(:message) and options.has_key?(:to)
19
+ message = Message.new(options[:to], options[:message], options[:from])
20
+ puts message.to
21
+ return Action::Sender.new(account, message)
22
+ else
23
+ raise ArgumentError, "You must supply a message to send and a place to send it"
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ module Signupto
2
+ class Message
3
+
4
+ # Make the elements of the message accesible.
5
+ # This way you can do @message.from etc to makes debuging the code
6
+ # a lot simpler (I find at least)
7
+ attr_reader :to, :from, :body
8
+
9
+ # Set the recipient (which must be in international format, with no leading +)
10
+ # and the from paramater, and the body. The From paramater will take a string up to
11
+ # 12 characters long, then on the recipients phone it will appear as if it is from
12
+ # someone in there contacts rather than and unknown number.
13
+ def initialize(to, body, from = nil)
14
+ # validate_number(to)
15
+ @to, @body, @from = to, URI.encode(body), from
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ module Signupto
2
+ module Version #:nodoc:
3
+ MAJOR = 1
4
+ MINOR = 0
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
metadata CHANGED
@@ -1,67 +1,66 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: signupto
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2007-10-03 00:00:00 +01:00
8
- summary: An API client for sending SMS messages via the Signup.to service
9
- require_paths:
10
- - lib
11
- email: code@timperrett.com
12
- homepage: http://www.timperrett.com
13
- rubyforge_project:
14
- description:
15
- autorequire: net/sms/signupto
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 1.0.1
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Tim Perrett
31
- files:
32
- - CHANGELOG
33
- - init.rb
34
- - lib
35
- - lib/net
36
- - lib/net/sms
37
- - lib/net/sms/signupto
38
- - lib/net/sms/signupto/account.rb
39
- - lib/net/sms/signupto/action.rb
40
- - lib/net/sms/signupto/balance.rb
41
- - lib/net/sms/signupto/message.rb
42
- - lib/net/sms/signupto/send.rb
43
- - lib/net/sms/signupto.rb
44
- - Rakefile
45
- - README
46
- - test
47
- - TODO
48
- test_files: []
8
+ autorequire: signupto
9
+ bindir: bin
10
+ cert_chain: []
49
11
 
50
- rdoc_options:
51
- - --title
52
- - SignUpTo SMS API Bindings
53
- - --line-numbers
54
- - --main
55
- - README
56
- extra_rdoc_files:
57
- - README
58
- - CHANGELOG
59
- - TODO
12
+ date: 2008-01-10 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Core connectivity to the signupto SMS gateway service
17
+ email: code@timperrett.com
60
18
  executables: []
61
19
 
62
20
  extensions: []
63
21
 
22
+ extra_rdoc_files:
23
+ - README
24
+ - LICENSE
25
+ files:
26
+ - LICENSE
27
+ - README
28
+ - Rakefile
29
+ - lib/signupto
30
+ - lib/signupto/account.rb
31
+ - lib/signupto/action
32
+ - lib/signupto/action/balance.rb
33
+ - lib/signupto/action/base.rb
34
+ - lib/signupto/action/sender.rb
35
+ - lib/signupto/base.rb
36
+ - lib/signupto/message.rb
37
+ - lib/signupto/version.rb
38
+ - lib/signupto.rb
39
+ has_rdoc: true
40
+ homepage: http://blog.timperrett.com
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
64
58
  requirements: []
65
59
 
66
- dependencies: []
60
+ rubyforge_project:
61
+ rubygems_version: 1.0.1
62
+ signing_key:
63
+ specification_version: 2
64
+ summary: Core connectivity to the signupto SMS gateway service
65
+ test_files: []
67
66
 
data/CHANGELOG DELETED
@@ -1 +0,0 @@
1
- == CHANGE LOG
data/TODO DELETED
@@ -1,5 +0,0 @@
1
- == TODO
2
-
3
- * Tests of all kinds!
4
- * Add support for delivery checking
5
- * International number validation and checking
data/init.rb DELETED
@@ -1,2 +0,0 @@
1
- # hook code here
2
- # require File.dirname(__FILE__) + '/action'
@@ -1,40 +0,0 @@
1
- require File.dirname(__FILE__) + '/signupto/account'
2
-
3
- module Net
4
- module SMS
5
- module SignupTo
6
-
7
- # Get the current gem version.
8
- class Version
9
- Major = '0'
10
- Minor = '1'
11
- Tiny = '0'
12
-
13
- def self.to_s
14
- [Major, Minor, Tiny].join('.')
15
- end
16
- end
17
-
18
- end
19
- end
20
- end
21
-
22
-
23
- # class Service
24
- #
25
- # attr_reader :account
26
- #
27
- # def initialize(apihash, customer_number)
28
- # @account = Account.new(apihash, customer_number)
29
- # end
30
- #
31
- # def send_message()
32
- # end
33
- #
34
- # def send()
35
- # end
36
- #
37
- # end
38
- # end
39
- # end
40
- # end
@@ -1,26 +0,0 @@
1
- require 'net/http'
2
- require 'uri'
3
-
4
- module Net
5
- module SMS
6
- module SignupTo
7
- class Account
8
-
9
- # Pass in your account details to create an account object.
10
- # Your +apihash+ and +cid+ which will both be found on the signup.to
11
- # dashboard interface.
12
- def initialize(apihash, customer_number)
13
- @apihash, @customer_number = apihash, customer_number
14
- end
15
-
16
- def to_http
17
- URI.encode("cid=#{@customer_number}&hash=#{@apihash}")
18
- end
19
-
20
- end
21
-
22
- class AccountError < Exception; end
23
-
24
- end
25
- end
26
- end
@@ -1,36 +0,0 @@
1
- require 'net/http'
2
- require 'uri'
3
-
4
- module Net
5
- module SMS
6
- module SignupTo
7
- class Action
8
-
9
- attr_writer :page
10
-
11
- # Parent class that all specific actions are derived.
12
- def initialize(account)
13
- if account.kind_of? Account
14
- @account = account
15
- else
16
- raise ActionError, 'You can only pass an account object to create an action'
17
- end
18
- end
19
-
20
- # Actually make the call to the api URL. SignUp.to use a
21
- # PHP response method, so I make a URI encoded GET to there servers
22
- # and await the response; handling it appropriatly.
23
- def run_action(payload)
24
- Net::HTTP.start('sms.sign-up.to', 80) do |http|
25
- resp = http.get('/'<< @page << '?' << payload)
26
- return resp
27
- end
28
- end
29
-
30
- end
31
-
32
- class ActionError < Exception; end
33
-
34
- end
35
- end
36
- end
@@ -1,32 +0,0 @@
1
- require File.dirname(__FILE__) + '/action'
2
-
3
- module Net
4
- module SMS
5
- module SignupTo
6
- class Balance < Action
7
-
8
- # Get remaining balence of credits left on
9
- # any given account. Returns a number.
10
- def initialize(account)
11
- super(account)
12
- @page = 'smpp_account.php'
13
- set_payload()
14
- @result = run_action(@payload)
15
- end
16
-
17
- def to_s
18
- return @result.body
19
- end
20
-
21
- protected
22
-
23
- def set_payload
24
- @payload = [@account.to_http, 'mode=balance'].join('&')
25
- end
26
-
27
- private
28
-
29
- end
30
- end
31
- end
32
- end
@@ -1,43 +0,0 @@
1
- require 'uri'
2
-
3
- module Net
4
- module SMS
5
- module SignupTo
6
- class Message
7
-
8
- # Make the elements of the message accesible.
9
- # This way you can do @message.from etc to makes debuging the code
10
- # a lot simpler (I find at least)
11
- attr_reader :to, :from, :body
12
-
13
- # Set the recipient (which must be in international format, with no leading +)
14
- # and the from paramater, and the body. The From paramater will take a string up to
15
- # 12 characters long, then on the recipients phone it will appear as if it is from
16
- # someone in there contacts rather than and unknown number.
17
- def initialize(to, from, body)
18
- # validate_number(to)
19
- @to, @from, @body = to, from, URI.encode(body)
20
- end
21
-
22
- private
23
-
24
- # Obsolete method. Doesnt work as yet.
25
- # TODO!!!
26
- def validate_number(number)
27
- if number =~ /^(\+44\s?7\d{3}|\(?07\d{3}\)?)\s?\d{3}\s?\d{3}$/ then
28
- return number
29
- else
30
- raise InvalidNumberError, 'The number ' << number << ' is not a valid UK phone number'
31
- end
32
- # do somethig with number to clean it
33
- end
34
-
35
- end
36
-
37
- # Reserved for the future when the number entered does
38
- # not meet international format.
39
- class InvalidNumberError < Exception; end
40
-
41
- end
42
- end
43
- end
@@ -1,41 +0,0 @@
1
- require File.dirname(__FILE__) + '/action'
2
-
3
- module Net
4
- module SMS
5
- module SignupTo
6
- class Send < Action
7
-
8
- # You need to pass in an account object, and the message you
9
- # wish to send out. The message will be automatically URI encoded
10
- # and replace any unsafe characters.
11
- def initialize(account, message)
12
- super(account)
13
- @page, @message = 'smpp_send.php', message
14
- set_payload()
15
- @result = run_action(@payload)
16
- end
17
-
18
- def to_s #:nodoc:
19
- return @result.body
20
- end
21
-
22
- protected
23
-
24
- # Configure the payload to send on this text message.
25
- def set_payload
26
- # to - Recipient mobile number in full international format (no ‘+’ or ‘00’)
27
- # message - Message body text
28
- # from - SMS sender
29
- # cost - Cost (in pence) to the recipient
30
- # network - Recipient’s network
31
- # smsc - ID of client selected SMS route
32
- #"from=#{@message.from.to_s}"
33
- @payload = [@account.to_http, "to=#{@message.to.to_s}", "message=#{@message.body.to_s}"].join('&')
34
- end
35
-
36
- private
37
-
38
- end
39
- end
40
- end
41
- end