kennethkalmer-smsinabox 0.0.3 → 0.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/bin/sms-credit CHANGED
@@ -12,6 +12,10 @@ end
12
12
  require 'smsinabox'
13
13
  require 'optparse'
14
14
 
15
+ OPTIONS = {
16
+ :config => nil
17
+ }
18
+
15
19
  parser = OptionParser.new do |opts|
16
20
  opts.banner = <<BANNER
17
21
  Retrieve the number of credits in the account
@@ -21,12 +25,14 @@ Usage: #{File.basename($0)} [options]
21
25
  Options are:
22
26
  BANNER
23
27
  opts.separator ""
28
+ opts.on("-c", "--config=path/to/config", String,
29
+ "Path to alternate config file (defaults to ~/.smsinabox)") { |m| OPTIONS[:config] = m }
24
30
  opts.on("-h", "--help",
25
31
  "Show this help message.") { puts opts; exit }
26
32
  opts.parse!(ARGV)
27
33
 
28
34
  end
29
35
 
30
- Smsinabox.configure!
36
+ Smsinabox.configure!( OPTIONS[:config] )
31
37
 
32
38
  puts "Credits left: #{Smsinabox.credits}"
data/bin/sms-send CHANGED
@@ -14,9 +14,11 @@ require 'optparse'
14
14
 
15
15
  OPTIONS = {
16
16
  :recipient => nil,
17
- :message => nil
17
+ :message => nil,
18
+ :pipe => false,
19
+ :config => nil
18
20
  }
19
- MANDATORY_OPTIONS = %w( recipient message)
21
+ MANDATORY_OPTIONS = %w( recipient )
20
22
 
21
23
  parser = OptionParser.new do |opts|
22
24
  opts.banner = <<BANNER
@@ -31,6 +33,10 @@ BANNER
31
33
  "The recipient of the SMS") { |r| OPTIONS[:recipient] = r }
32
34
  opts.on("-m", "--message=MESSAGE", String,
33
35
  "The body of the message (wrap in quotes)") { |m| OPTIONS[:message] = m }
36
+ opts.on("-c", "--config=path/to/config", String,
37
+ "Path to alternate config file (defaults to ~/.smsinabox)") { |m| OPTIONS[:config] = m }
38
+ opts.on("-p", "--pipe",
39
+ "Read message text from STDIN") { OPTIONS[:pipe] = true }
34
40
  opts.on("-h", "--help",
35
41
  "Show this help message.") { puts opts; exit }
36
42
  opts.parse!(ARGV)
@@ -38,16 +44,33 @@ BANNER
38
44
  if MANDATORY_OPTIONS && MANDATORY_OPTIONS.find { |option| OPTIONS[option.to_sym].nil? }
39
45
  puts opts; exit
40
46
  end
47
+
48
+ if OPTIONS[:message].nil? && !OPTIONS[:pipe]
49
+ puts opts; exit
50
+ end
51
+ end
52
+
53
+ # Figure out our message
54
+ message = if !OPTIONS[:message].nil?
55
+ OPTIONS[:message]
56
+ else
57
+ require 'fcntl'
58
+ if STDIN.fcntl(Fcntl::F_GETFL, 0) == 0
59
+ STDIN.read
60
+ else
61
+ puts "Nothing to read from STDIN!"
62
+ exit 1
63
+ end
41
64
  end
42
65
 
43
- Smsinabox.configure!
44
- id = Smsinabox.send(
66
+ Smsinabox.configure!( OPTIONS[:config] )
67
+ id = Smsinabox.send(
45
68
  Smsinabox::Message.new(
46
- :recipient => OPTIONS[:recipient], :body => OPTIONS[:message]
69
+ :recipient => OPTIONS[:recipient], :body => message
47
70
  )
48
71
  )
49
72
 
50
73
  puts "Message sent"
51
74
  puts "Reference: #{id}"
52
75
  puts "Recipient: #{OPTIONS[:recipient]}"
53
- puts "Message: #{OPTIONS[:message]}"
76
+ puts "Message: #{message}"
data/bin/sms-setup CHANGED
@@ -14,7 +14,8 @@ require 'optparse'
14
14
 
15
15
  OPTIONS = {
16
16
  :username => nil,
17
- :password => nil
17
+ :password => nil,
18
+ :config => nil
18
19
  }
19
20
  MANDATORY_OPTIONS = %w( username password )
20
21
 
@@ -34,6 +35,8 @@ BANNER
34
35
  "Username to use") { |u| OPTIONS[:username] = u }
35
36
  opts.on("-p", "--password=PASSWORD", String,
36
37
  "Password to use") { |p| OPTIONS[:password] = p }
38
+ opts.on("-c", "--config=path/to/config", String,
39
+ "Path to alternate config file (defaults to ~/.smsinabox)") { |m| OPTIONS[:config] = m }
37
40
  opts.on("-h", "--help",
38
41
  "Show this help message.") { puts opts; exit }
39
42
  opts.parse!(ARGV)
@@ -43,7 +46,7 @@ BANNER
43
46
  end
44
47
  end
45
48
 
46
- config = Smsinabox::Configuration.new
49
+ config = Smsinabox::Configuration.new( OPTIONS[:config] )
47
50
  config[:username] = OPTIONS[:username]
48
51
  config[:password] = OPTIONS[:password]
49
52
  config.save
data/lib/smsinabox.rb CHANGED
@@ -34,9 +34,9 @@ module Smsinabox
34
34
  )
35
35
  end
36
36
 
37
- # Set our username and password from ~/.smsinabox
38
- def configure!
39
- c = Configuration.new
37
+ # Set our username and password from #Smsinabox::Configuration
38
+ def configure!( config_file = nil )
39
+ c = Configuration.new( config_file )
40
40
  @username = c["username"]
41
41
  @password = c["password"]
42
42
  nil
@@ -1,9 +1,14 @@
1
1
  require 'yaml'
2
2
 
3
3
  module Smsinabox
4
+
5
+ # Wrapper around our YAML configuration file, which lives in ~/.smsinabox by
6
+ # default
4
7
  class Configuration
5
8
 
6
- def initialize
9
+ def initialize( config_file = nil )
10
+ @config_file = config_file
11
+
7
12
  check_file!
8
13
  load_config
9
14
  end
@@ -44,7 +49,7 @@ module Smsinabox
44
49
  end
45
50
 
46
51
  def config_name
47
- File.expand_path( File.join('~', '.smsinabox') )
52
+ @config_file || File.expand_path( File.join('~', '.smsinabox') )
48
53
  end
49
54
  end
50
55
  end
@@ -1,8 +1,8 @@
1
1
  module Smsinabox
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 0
5
- TINY = 3
4
+ MINOR = 1
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  self
data/smsinabox.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{smsinabox}
3
- s.version = "0.0.3"
3
+ s.version = "0.1.0"
4
4
 
5
5
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
6
  s.authors = ["Kenneth Kalmer"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kennethkalmer-smsinabox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenneth Kalmer