sms 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +45 -0
  2. data/lib/sms.rb +35 -0
  3. metadata +62 -0
@@ -0,0 +1,45 @@
1
+ # sms
2
+
3
+ Send text messages with [Twilio](http://www.twilio.com/). Easily.
4
+
5
+ ## Installation
6
+
7
+ gem install sms
8
+
9
+ Or put `gem 'sms'` in your `Gemfile`.
10
+
11
+
12
+ ## Usage
13
+
14
+ Set the following ENV variables:
15
+
16
+ * `TWILIO_ID`: Your Twilio API id token.
17
+ * `TWILIO_SECRET`: Your Twilio API secret token.
18
+ * `TWILIO_PHONE`: One of your Twilio phone numbers.
19
+
20
+ Then, send some SMS messages:
21
+
22
+ SMS.text :message => "Hello!", :to => "15558675309"
23
+
24
+ Calling `SMS.text` returns true if the message was sent, or false if it wasn’t.
25
+
26
+
27
+ ## Testing
28
+ To run the test suite, put a YAML file with the following keys at `~/.twilio`:
29
+
30
+ * `sid`: Your Twilio API ID token.
31
+ * `secret`: Your Twilio API secret token.
32
+ * `from`: Twilio phone number to send test message from.
33
+ * `to`: Phone number to send test message to.
34
+
35
+ This is a bit of a hack. Unfortunately, Twilio doesn’t offer testing credentials.
36
+
37
+
38
+ ## Credits
39
+ * This is a heavily–modified fork of [sms-rb](https://github.com/nakajima/sms-rb).
40
+
41
+
42
+ ## TODO
43
+ * Consolidate YAML/ENV/options – should be able to set all from any method.
44
+ * Support loading config directly from arbitrary YAML files.
45
+
@@ -0,0 +1,35 @@
1
+ require 'uri'
2
+ require 'net/https'
3
+
4
+ module SMS
5
+ attr_accessor :sid, :secret, :from
6
+
7
+ def self.text(options={})
8
+ @sid = ENV.delete('TWILIO_ID') if ENV.key?('TWILIO_ID')
9
+ @secret = ENV.delete('TWILIO_SECRET') if ENV.key?('TWILIO_SECRET')
10
+ @from = ENV.delete('TWILIO_PHONE') if ENV.key?('TWILIO_PHONE')
11
+ @from = options[:from] if options.key?(:from)
12
+ return false if @from.nil? or @from == ''
13
+ return false unless options.key?(:message)
14
+ return false unless options.key?(:to)
15
+
16
+ url = URI.parse "https://api.twilio.com/2010-04-01/Accounts/#{@sid}/SMS/Messages"
17
+ http = Net::HTTP.new(url.host, url.port)
18
+ http.use_ssl = true
19
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
20
+
21
+ request = Net::HTTP::Post.new(url.path)
22
+ request.basic_auth @sid, @secret
23
+ request.set_form_data({
24
+ 'From' => @from,
25
+ 'To' => options[:to],
26
+ 'Body' => options[:message],
27
+ })
28
+
29
+ response = http.start do |http|
30
+ http.request(request)
31
+ end
32
+ response.code[0..0] == '2' # eg, 2xx
33
+ end
34
+ end
35
+
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sms
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ version: "0.1"
9
+ platform: ruby
10
+ authors:
11
+ - Bill Williams
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2011-08-03 00:00:00 -04:00
17
+ default_executable:
18
+ dependencies: []
19
+
20
+ description:
21
+ email: bill@flpatriot.com
22
+ executables: []
23
+
24
+ extensions: []
25
+
26
+ extra_rdoc_files: []
27
+
28
+ files:
29
+ - README.md
30
+ - lib/sms.rb
31
+ has_rdoc: true
32
+ homepage: https://github.com/flpatriot/sms
33
+ licenses: []
34
+
35
+ post_install_message:
36
+ rdoc_options: []
37
+
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ requirements: []
55
+
56
+ rubyforge_project:
57
+ rubygems_version: 1.3.6
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: Send SMS messages with Twilio.
61
+ test_files: []
62
+