SMS 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sms.gemspec
4
+ gemspec
@@ -0,0 +1,49 @@
1
+ # SMS
2
+
3
+ Add a Kernel#sms method so you can SMS at any point
4
+
5
+ ## Installation
6
+
7
+ Add
8
+
9
+ gem 'SMS'
10
+
11
+ to your `Gemfile` or `gem install SMS`
12
+
13
+ ## Usage
14
+
15
+ require 'sms'
16
+
17
+ sms "Hello", 4151231234
18
+ sms "Hello", "4151231234"
19
+ sms "Hello", ["4151231234", "4157657651"]
20
+ sms ["Hello", "there"], 4151231234
21
+
22
+ You must have three environment variables set, `TWILIO_ACCOUNT_SID`, `TWILIO_AUTH_TOKEN` and `TWILIO_FROM`. To do so, add this to your .bash_profile (or some thing that sets up some env vars for you):
23
+
24
+ export TWILIO_RECIPIENTS=4151231234
25
+ export TWILIO_FROM=4151231234
26
+ export TWILIO_ACCOUNT_ID=ACxxxxxxx
27
+ export TWILIO_AUTH_TOKEN=xxxxx
28
+
29
+ If you wish to programically setup those variables, do the following:
30
+
31
+ require 'sms'
32
+
33
+ SMS.twilio_account_sid = "AC818237237282aadff88d7ef8c"
34
+ SMS.twilio_auth_token = "xxxx"
35
+ SMS.twilio_from = "1231231234"
36
+
37
+ sms "hi", "4151231234"
38
+
39
+ As well, you can have default recipients (via the , so you can leave off the number all the time
40
+
41
+ SMS.default_recipients = "4151231234"
42
+ sms "hello there!"
43
+
44
+
45
+ ## Binary usage
46
+
47
+ There is also an `sms` binary. Just call it with the message you wish to send! All arguments past the first one are treated like recipients.
48
+
49
+ #> sms "hello there" 4151231234
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/sms ADDED
@@ -0,0 +1,15 @@
1
+ require 'sms'
2
+
3
+ if ARGV[0].nil?
4
+ warn "You must supply a message"
5
+ warn "Usage:"
6
+ warn "sms [message]"
7
+ exit 1
8
+ end
9
+
10
+ message = ARGV.shift
11
+ if ARGV.empty?
12
+ sms message
13
+ else
14
+ sms message, ARGV
15
+ end
@@ -0,0 +1,75 @@
1
+ require "sms/version"
2
+ require 'twilio-ruby'
3
+
4
+ class SMS
5
+
6
+ INSTANCE = SMS.new
7
+
8
+ class << self
9
+ def method_missing(m, *args, &blk)
10
+ INSTANCE.send(m, *args, &blk)
11
+ end
12
+ end
13
+
14
+ attr_writer :twilio_account_id, :twilio_auth_token, :default_recipients, :twilio_from
15
+
16
+ def client
17
+ @client ||= begin
18
+ setup!
19
+ Twilio::REST::Client.new(twilio_account_id, twilio_auth_token)
20
+ end
21
+ end
22
+
23
+ def default_recipients
24
+ @default_recipients ||= ENV['TWILIO_RECIPIENTS']
25
+ end
26
+
27
+ def twilio_from
28
+ @twilio_from ||= ENV['TWILIO_FROM']
29
+ end
30
+
31
+ def twilio_account_id
32
+ @twilio_account_id ||= ENV['TWILIO_ACCOUNT_ID']
33
+ end
34
+
35
+ def twilio_auth_token
36
+ @twilio_auth_token ||= ENV['TWILIO_AUTH_TOKEN']
37
+ end
38
+
39
+ def message(messages, *more)
40
+ opts = more.last.is_a?(Hash) ? more.pop : nil
41
+ recipients = opts && (opts[:recipients] || opts[:recipient]) || more.first || default_recipients
42
+ raise "You must set a recipient. Please put your recipient number" +
43
+ " in the environment variable as TWILIO_RECIPIENTS or set it with SMS.default_recipients= or " +
44
+ " as it as an option to your #message call." unless recipients
45
+ recipients = Array(recipients)
46
+ recipients.map! { |r| r.to_s }
47
+ from = opts && opts[:from] || twilio_from
48
+ raise "You must set a twlio from number. Please put your from number" +
49
+ " in the environment variable as TWILIO_FROM or set it with SMS.from=" unless from
50
+ messages = Array(messages)
51
+ messages.map! { |m| m.to_s }
52
+ messages.each do |message|
53
+ message_parameters = { :body => message }
54
+ recipients.each do |recipient|
55
+ message_parameters[:to] = recipient
56
+ message_parameters[:from] = from
57
+ client.account.sms.messages.create(message_parameters)
58
+ end
59
+ end
60
+ end
61
+
62
+ private
63
+ def setup!
64
+ !twilio_account_id.nil? or raise "You must set a twlio account id. Please put your account id" +
65
+ " in the environment variable as TWILIO_ACCOUNT_ID or set it with SMS.twilio_account_id="
66
+ !twilio_auth_token.nil? or raise "You must set a twlio auth token. Please put your auth token" +
67
+ " in the environment variable as TWILIO_AUTH_TOKEN or set it with SMS.twilio_auth_token="
68
+ end
69
+ end
70
+
71
+ module Kernel
72
+ def sms(message, recipients = nil)
73
+ SMS::INSTANCE.message(message, recipients)
74
+ end
75
+ end
@@ -0,0 +1,3 @@
1
+ class SMS
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "sms/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "SMS"
7
+ s.version = SMS::VERSION
8
+ s.authors = ["Josh Hull"]
9
+ s.email = ["joshbuddy@gmail.com"]
10
+ s.homepage = "https://github.com/joshbuddy/sms"
11
+ s.summary = %q{Add an sms method to Kernel, because sms is the new puts}
12
+ s.description = %q{Add an sms method to Kernel, because sms is the new puts.}
13
+
14
+ s.rubyforge_project = "sms"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "twilio-ruby", '>= 3.5.1'
24
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: SMS
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Josh Hull
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-16 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: twilio-ruby
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 17
29
+ segments:
30
+ - 3
31
+ - 5
32
+ - 1
33
+ version: 3.5.1
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: Add an sms method to Kernel, because sms is the new puts.
37
+ email:
38
+ - joshbuddy@gmail.com
39
+ executables:
40
+ - sms
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - .gitignore
47
+ - Gemfile
48
+ - README.md
49
+ - Rakefile
50
+ - bin/sms
51
+ - lib/sms.rb
52
+ - lib/sms/version.rb
53
+ - sms.gemspec
54
+ homepage: https://github.com/joshbuddy/sms
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options: []
59
+
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ hash: 3
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ requirements: []
81
+
82
+ rubyforge_project: sms
83
+ rubygems_version: 1.8.15
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Add an sms method to Kernel, because sms is the new puts
87
+ test_files: []
88
+
89
+ has_rdoc: