pswincom 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,6 +20,13 @@ This piece of code demonstrates how to send a simple SMS message:
20
20
  api = PSWinCom::API.new 'username', 'password'
21
21
  api.send_sms 4712345678, 'This is a test SMS'
22
22
 
23
+ You can also send multiple messages in a single request, like this:
24
+
25
+ api = PSWinCom::API.new 'username', 'password'
26
+ api.add_sms 4712345678, 'This is a test SMS'
27
+ api.add_sms 4712345679, 'This is another test SMS'
28
+ api.send_sms
29
+
23
30
  Properties
24
31
  ----------
25
32
  Receiver and message text are the two mandatory properties when sending a message. You may specify additional properties by using a hash as the last argument to `send_sms`.
@@ -52,6 +59,23 @@ For testing purposes the API provides a couple of modes you can set globally to
52
59
 
53
60
  .. will make the API output debug information to standard out.
54
61
 
62
+ Command-line SMS tool
63
+ ---------------------
64
+ The PSWinCom gem also comes with a command-line tool that will allow you to send an SMS directly from the command-line.
65
+
66
+ To simplify the usage of the tool you may create a YAML configuration file in your home directory, in a file called .pswincom that resembles the following:
67
+
68
+ username: your_username
69
+ password: your_password
70
+ from: your_nick_or_something
71
+ host: optionally_override_api_host
72
+
73
+ If you don't provide these options in the .pswincom file, you can specify them directly at the command-line.And only username and password are required. Run 'sms' without any arguments for a full list of options.
74
+
75
+ You can then use the sms tool to send a message:
76
+
77
+ sms 4712345678 "Message from PSWinCom"
78
+
55
79
  License
56
80
  -------
57
81
  This code is free to use under the terms of the MIT license.
data/bin/sms ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ local_libs = [
4
+ File.join(File.dirname(__FILE__), *%w[../lib/pswincom]),
5
+ File.join(File.dirname(__FILE__), *%w[../lib/pswincom/utility/options])
6
+ ]
7
+
8
+ if File.exist?(local_libs.first)
9
+ local_libs.each { |lib| require lib }
10
+ else
11
+ require 'rubygems'
12
+ require 'pswincom'
13
+ require 'pswincom/utility/options'
14
+ end
15
+
16
+ # parse command line options
17
+ options = PSWinCom::Utility::Options.parse(ARGV)
18
+
19
+ PSWinCom::API.api_host = options.host if options.host
20
+
21
+ # authenticate and load the API
22
+ api = PSWinCom::API.new options.username, options.password
23
+
24
+ begin
25
+ puts "Sending '#{options.message}' to #{options.recipient}.."
26
+ additional_opts = {}
27
+ additional_opts[:sender] = options.from if options.from
28
+ result = api.send_sms options.recipient, options.message, additional_opts
29
+ puts result.body
30
+ exit 0
31
+
32
+ rescue StandardError => e
33
+ puts e
34
+
35
+ end
@@ -17,6 +17,9 @@ module PSWinCom
17
17
  self.debug_mode = false;
18
18
 
19
19
  def initialize user, password
20
+ if user.to_s.empty? or password.to_s.empty?
21
+ raise ArgumentError, "You must specify username and password"
22
+ end
20
23
  @user, @password = user, password
21
24
  @request = Request.new :user => @user, :passwd => @password
22
25
  end
@@ -0,0 +1,94 @@
1
+ require 'optparse'
2
+ require 'ostruct'
3
+ require 'yaml'
4
+
5
+ module PSWinCom
6
+ module Utility
7
+ class Options
8
+ class << self
9
+
10
+ def parse(args)
11
+ @options = self.default_options
12
+ parser = OptionParser.new do |opts|
13
+ opts.banner = "Usage: sms [options] recipient(s) message"
14
+ opts.separator " Recipients can be a comma-separated list, up to 100 max."
15
+ opts.separator ""
16
+ opts.separator "Specific options:"
17
+
18
+ opts.on('-u', '--username USERNAME',
19
+ "Specify the pswincom username (overrides ~/.pswincom setting)") do |username|
20
+ @options.username = username
21
+ end
22
+
23
+ opts.on('-p', '--password PASSWORD',
24
+ "Specify the pswincom password (overrides ~/.pswincom setting)") do |password|
25
+ @options.password = password
26
+ end
27
+
28
+ opts.on('-f', '--from NAME_OR_NUMBER',
29
+ "Specify the name or number that the SMS will appear from") do |from|
30
+ @options.from = from
31
+ end
32
+
33
+ opts.on('-s', '--host URL',
34
+ "Specify the gateway endpoint to use") do |host|
35
+ @options.host = host
36
+ end
37
+
38
+ opts.on('-d', '--debug') do
39
+ PSWinCom::API.debug_mode = true
40
+ end
41
+
42
+ opts.on('-t', '--test') do
43
+ PSWinCom::API.test_mode = true
44
+ end
45
+
46
+ opts.on_tail('-h', '--help', "Show this message") do
47
+ puts opts
48
+ exit
49
+ end
50
+ end
51
+
52
+ #@options.recipient = args[-2].split(',').map { |r| r.gsub(/^\+/, '') } rescue nil
53
+ @options.recipient = args[-2]
54
+ @options.message = args[-1]
55
+
56
+ parser.parse!(args)
57
+
58
+ if (@options.message.nil? || @options.recipient.nil?)
59
+ puts "You must specify a recipient and message!"
60
+ puts parser
61
+ exit
62
+ end
63
+
64
+ return @options
65
+
66
+ rescue OptionParser::MissingArgument => e
67
+ switch_given = e.message.split(':').last.strip
68
+ puts "The #{switch_given} option requires an argument."
69
+ puts parser
70
+ exit
71
+ end
72
+
73
+ def default_options
74
+ options = OpenStruct.new
75
+ config = load_defaults
76
+ options.username = config['username']
77
+ options.password = config['password']
78
+ options.from = config['from']
79
+ options.host = config['host']
80
+ return options
81
+ rescue Errno::ENOENT
82
+ return options
83
+ end
84
+
85
+ def load_defaults
86
+ config_file = File.open(File.join(ENV['HOME'], '.pswincom'))
87
+ YAML.load(config_file)
88
+ end
89
+
90
+ end
91
+ end
92
+ end
93
+ end
94
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pswincom
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - PSWinCom AS
@@ -15,8 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-15 00:00:00 +01:00
19
- default_executable:
18
+ date: 2011-02-16 00:00:00 +01:00
19
+ default_executable: sms
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: builder
@@ -36,17 +36,19 @@ dependencies:
36
36
  version_requirements: *id001
37
37
  description: An easy to use API for the PSWinCom SMS Gateway, allowing you to send SMS messages.
38
38
  email:
39
- - support@pswin.com
40
- executables: []
41
-
39
+ - post@pswin.com
40
+ executables:
41
+ - sms
42
42
  extensions: []
43
43
 
44
44
  extra_rdoc_files: []
45
45
 
46
46
  files:
47
+ - bin/sms
47
48
  - lib/pswincom/api.rb
48
49
  - lib/pswincom/httpsender.rb
49
50
  - lib/pswincom/request.rb
51
+ - lib/pswincom/utility/options.rb
50
52
  - lib/pswincom.rb
51
53
  - LICENSE
52
54
  - README.md