penny_sms_muncher 0.0.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.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+ *.gem
21
+
22
+ ## PROJECT::SPECIFIC
@@ -0,0 +1,96 @@
1
+ **BLANK MESSAGE**
2
+ ---
3
+ fault:
4
+ - value:
5
+ - struct:
6
+ - member:
7
+ - name:
8
+ - faultCode
9
+ value:
10
+ - i4:
11
+ - "403"
12
+ - name:
13
+ - faultString
14
+ value:
15
+ - string:
16
+ - "Error: API KEY is not vaild, contact support@pennysms.com"
17
+
18
+ **BAD API KEY**
19
+ ---
20
+ fault:
21
+ - value:
22
+ - struct:
23
+ - member:
24
+ - name:
25
+ - faultCode
26
+ value:
27
+ - i4:
28
+ - "403"
29
+ - name:
30
+ - faultString
31
+ value:
32
+ - string:
33
+ - "Error: API KEY is not vaild, contact support@pennysms.com"
34
+
35
+ **BAD PHONE NUMBER**
36
+ ---
37
+ fault:
38
+ - value:
39
+ - struct:
40
+ - member:
41
+ - name:
42
+ - faultCode
43
+ value:
44
+ - i4:
45
+ - "500"
46
+ - name:
47
+ - faultString
48
+ value:
49
+ - string:
50
+ - "Error: invalid cell number"
51
+
52
+ **INVALID PHONE #**
53
+ <?xml version="1.0" ?><methodResponse><fault><value><struct><member><name>faultCode</name><value><i4>500</i4></value></member><member><name>faultString</name><value><string>Error: unsupported cell number</string></value></member></struct></value></fault></methodResponse>
54
+
55
+ ---
56
+ fault:
57
+ - value:
58
+ - struct:
59
+ - member:
60
+ - name:
61
+ - faultCode
62
+ value:
63
+ - i4:
64
+ - "500"
65
+ - name:
66
+ - faultString
67
+ value:
68
+ - string:
69
+ - "Error: unsupported cell number"
70
+
71
+
72
+ **??? (ALTERNATE BAD PHONE NUMBER?)**
73
+ ---
74
+ fault:
75
+ - value:
76
+ - struct:
77
+ - member:
78
+ - name:
79
+ - faultCode
80
+ value:
81
+ - i4:
82
+ - "501"
83
+ - name:
84
+ - faultString
85
+ value:
86
+ - string:
87
+ - "Error: Try again later"
88
+
89
+ **ALL GOOD**
90
+ ---
91
+ params:
92
+ - param:
93
+ - value:
94
+ - string:
95
+ - OK
96
+
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 chris A
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.
@@ -0,0 +1,46 @@
1
+ h1. PennySMS Muncher
2
+
3
+ A little bit of code to make PennySMS XML requests.
4
+
5
+ <pre><code>
6
+ >> require 'penny_sms'
7
+ >> include PennySMSMuncher
8
+ >> req = PennySMS::XMLRequest.new(penny_sms_api_key, from_email, phone_number, body)
9
+ ...
10
+ >> response = req.send_sms
11
+ ... # PennySMSMuncher::PennySMS::Response object>> response.success?
12
+ => true
13
+ >> response.status
14
+ => "OK"
15
+ >> req = PennySMS::XMLRequest.new(penny_sms_api_key, from_email, '6175551234', body)
16
+ ...
17
+ >> response = req.send_sms
18
+ ... # PennySMSMuncher::PennySMS::Response object
19
+ >> response.status
20
+ => error"
21
+ >> response.success?
22
+ => false
23
+ >> response.fault_code
24
+ => "500"
25
+ >> response.fault_name
26
+ => "Error: unsupported cell number"
27
+ >> response.raw
28
+ => <Net::HTTPOK 200 OK readbody=true>
29
+ >> response.raw.body
30
+ => "<?xml version="1.0" ?><methodResponse><fault><value><struct><member><name>faultCode</name><value><i4>500</i4></value></member><member><name>faultString</name><value><string>Error: unsupported cell number</string></value></member></struct></value></fault></methodResponse>\n"
31
+ >> response.data
32
+ ... # LibXML::XML::Document object
33
+ </code>
34
+ </pre>
35
+
36
+
37
+ Here is the minimalist PennySMS doc: https://www.pennysms.com/docs_xml
38
+
39
+ h2. Note on Patches/Pull Requests
40
+
41
+ * Go ahead and make the JSON work.
42
+ * And feel free to chat me up.
43
+
44
+ h2. Copyright
45
+
46
+ Copyright (c) 2010 chris A. See LICENSE for details.
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "penny_sms_muncher"
8
+ gem.summary = %Q{A little bit of code to make PennySMS XML requests.}
9
+ gem.description = %Q{A little bit of code to make PennySMS XML requests. But not JSON requests right now.}
10
+ gem.email = "chris@whatbirdthings.com"
11
+ gem.homepage = "http://github.com/whatbird/penny_sms_muncher"
12
+ gem.authors = ["chris A", "Matthew Shanley"]
13
+
14
+ gem.add_development_dependency "rspec", ">= 1.2.9"
15
+
16
+ gem.add_dependency('addressable', '>= 2.1.1')
17
+ gem.add_dependency('libxml-ruby', '>= 1.1.3')
18
+
19
+
20
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
21
+ end
22
+ Jeweler::GemcutterTasks.new
23
+ rescue LoadError
24
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
25
+ end
26
+
27
+ require 'spec/rake/spectask'
28
+ Spec::Rake::SpecTask.new(:spec) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.spec_files = FileList['spec/**/*_spec.rb']
31
+ end
32
+
33
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
34
+ spec.libs << 'lib' << 'spec'
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :spec => :check_dependencies
40
+
41
+ task :default => :spec
42
+
43
+ require 'rake/rdoctask'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "penny_sms_muncher #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,124 @@
1
+ require 'net/http'
2
+ require 'erb'
3
+
4
+ require 'addressable/uri'
5
+ require 'xml'
6
+
7
+ module PennySMSMuncher
8
+ module PennySMS
9
+ class Request
10
+ attr_accessor :api_key, :text, :url, :from_email, :phone_number, :response
11
+
12
+ def initialize(api_key, from_email, phone_number, text, api_url=nil)
13
+ self.url = Addressable::URI.parse(api_url || @api_url)
14
+ self.phone_number = phone_number
15
+ self.from_email = from_email
16
+ self.text = text
17
+ self.api_key = api_key
18
+ self.from_email = from_email
19
+ end
20
+
21
+ def request
22
+ req = Net::HTTP::Post.new url.path,
23
+ initheader = {'Content-Type' => @content_type}
24
+ req.body = template
25
+ req
26
+ end
27
+
28
+ def send_sms
29
+ resp = Net::HTTP.new(url.host).start {|http| http.request(request) }
30
+
31
+ if resp.is_a? Net::HTTPSuccess
32
+ self.response = Response.new(resp)
33
+ else
34
+ raise APIError, "PennySMS API changed or busted. Or gem obsolete."
35
+ end
36
+ end
37
+ end
38
+
39
+ class Response
40
+ attr_accessor :data, :raw, :status
41
+
42
+ def initialize(raw)
43
+ self.raw = raw
44
+ self.data = XML::Parser.string(raw.body).parse # JSON?
45
+ self.set_status
46
+ self
47
+ end
48
+
49
+ def success?
50
+ !fault_code
51
+ end
52
+
53
+ def set_status
54
+ if fault
55
+ self.status = 'error'
56
+ else
57
+ self.status = data.find('//params//string').first.content
58
+ end
59
+ end
60
+
61
+ def fault_code
62
+ fault.find('//i4').first.content if fault
63
+ end
64
+
65
+ def fault_name
66
+ fault.find('//string').first.content if fault
67
+ end
68
+
69
+ def fault
70
+ return unless data && !data.find('//fault').empty?
71
+ data.find('//fault//member')[0]
72
+ end
73
+ end
74
+
75
+ class XMLRequest < Request
76
+ def initialize(*args)
77
+ @api_url = 'http://api.pennysms.com/xmlrpc'
78
+ @rpc_method = 'send'
79
+ @content_type = 'text/xml'
80
+ super
81
+ end
82
+
83
+ def template
84
+ ERB.new(%q{<?xml version="1.0"?>
85
+ <methodCall>
86
+ <methodName><%= @rpc_method %></methodName>
87
+ <params>
88
+ <param>
89
+ <value><string><%= api_key %></string></value>
90
+ </param>
91
+ <param>
92
+ <value><string><%= from_email %></string></value>
93
+ </param>
94
+ <param>
95
+ <value><string><%= phone_number %></string></value>
96
+ </param>
97
+ <param>
98
+ <value><string><%= text %></string></value>
99
+ </param>
100
+ </params>
101
+ </methodCall>}.gsub(/^ /, '')).result(binding)
102
+ end
103
+ end
104
+
105
+ # DOES NOT WORK 2009-12-22
106
+ class JSONRequest < Request
107
+ def initialize(*args)
108
+ raise NoMethodError, "JSONRequest not working. Figure it out though and let me know"
109
+ @api_url = 'http://api.pennysms.com/jsonrpc'
110
+ @rpc_method = 'send'
111
+ @content_type = 'text/json'
112
+ super
113
+ end
114
+
115
+ def template
116
+ {:method => @rpc_method,
117
+ :params => [api_key,from_email,phone_number,text]
118
+ }.to_json
119
+ end
120
+ end
121
+
122
+ class APIError < Exception; end
123
+ end
124
+ end
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{penny_sms_muncher}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["chris A", "Matthew Shanley"]
12
+ s.date = %q{2010-01-12}
13
+ s.description = %q{A little bit of code to make PennySMS XML requests. But not JSON requests right now.}
14
+ s.email = %q{chris@whatbirdthings.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.textile"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "API_RESPONSES.txt",
23
+ "LICENSE",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/penny_sms.rb",
27
+ "penny_sms_muncher.gemspec",
28
+ "spec/penny_sms_muncher_spec.rb",
29
+ "spec/spec.opts",
30
+ "spec/spec_helper.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/whatbird/penny_sms_muncher}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.5}
36
+ s.summary = %q{A little bit of code to make PennySMS XML requests.}
37
+ s.test_files = [
38
+ "spec/penny_sms_muncher_spec.rb",
39
+ "spec/spec_helper.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
48
+ s.add_runtime_dependency(%q<addressable>, [">= 2.1.1"])
49
+ s.add_runtime_dependency(%q<libxml-ruby>, [">= 1.1.3"])
50
+ else
51
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
52
+ s.add_dependency(%q<addressable>, [">= 2.1.1"])
53
+ s.add_dependency(%q<libxml-ruby>, [">= 1.1.3"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
57
+ s.add_dependency(%q<addressable>, [">= 2.1.1"])
58
+ s.add_dependency(%q<libxml-ruby>, [">= 1.1.3"])
59
+ end
60
+ end
61
+
@@ -0,0 +1,148 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__)) + "/../lib/penny_sms.rb"
3
+ include PennySMSMuncher
4
+
5
+
6
+ module PennySMSHelper
7
+ def failing_sms
8
+ @phone = '5555555555'
9
+ @email = 'mouse house'
10
+ @message = "Mouse is in the house!"
11
+ @req = PennySMS::XMLRequest.new('api_key', @email, @phone,@message)
12
+ end
13
+
14
+ def fault_body
15
+ '<?xml version="1.0" ?><methodResponse><fault><value><struct><member><name>faultCode</name><value><i4>500</i4></value></member><member><name>faultString</name><value><string>Error: unsupported cell number</string></value></member></struct></value></fault></methodResponse>'
16
+ end
17
+
18
+ def success_body
19
+ '<?xml version="1.0" ?><methodResponse><params><param><value><string>OK</string></value></param></params></methodResponse>'
20
+ end
21
+ end
22
+
23
+
24
+ describe "PennySMSMuncher::PennySms" do
25
+ include PennySMSHelper
26
+
27
+ describe 'creating' do
28
+
29
+ describe 'XMLRequest' do
30
+ it 'should set the url' do
31
+ req = PennySMS::XMLRequest.new('api_key', nil, nil,nil)
32
+ req.url.path.should match(/xml/)
33
+ end
34
+ end
35
+
36
+ describe 'JSONRequest' do
37
+ it 'should set the url'
38
+ end
39
+ end
40
+
41
+ describe 'template' do
42
+ describe 'XMLRequest' do
43
+ before(:each) do
44
+ failing_sms
45
+ end
46
+
47
+ it 'should include the phone_number' do
48
+ @req.template.should match(@phone)
49
+ end
50
+ it 'should include the email' do
51
+ @req.template.should match(@email)
52
+ end
53
+ it 'should include the message' do
54
+ @req.template.should match(@message)
55
+ end
56
+ it 'should include the api_key' do
57
+ @req.template.should match('api_key')
58
+ end
59
+
60
+ end
61
+ describe 'JSONRequest' do
62
+ it 'should include the phone_number'
63
+ it 'should include the email'
64
+ it 'should include the message'
65
+ it 'should include the api_key'
66
+ end
67
+ end
68
+
69
+ describe 'making the API call' do
70
+ describe 'fails' do
71
+ it 'should raise an error if the API call fails' do
72
+ failing_sms
73
+ Net::HTTP.any_instance.stubs(:start).returns "bogus"
74
+ lambda{@req.send_sms}.should raise_error(PennySMS::APIError)
75
+ end
76
+ end
77
+
78
+ describe 'succeeds' do
79
+ describe 'with errors' do
80
+ before(:each) do
81
+ failing_sms
82
+ http_mock = mock('Net::HTTPSuccess')
83
+ http_mock.stubs( :code => '200',
84
+ :message => "OK",
85
+ :content_type => "text/xml",
86
+ :body => fault_body,
87
+ :is_a? => Net::HTTPSuccess)
88
+ Net::HTTP.any_instance.stubs(:start).returns http_mock
89
+ @response = @req.send_sms
90
+ end
91
+
92
+ it "should return a response object" do
93
+ @response.class.should == PennySMS::Response
94
+ end
95
+
96
+ it 'should set the status' do
97
+ @response.status.should == 'error'
98
+ end
99
+
100
+ it 'should not be successful' do
101
+ @response.should_not be_success
102
+ end
103
+
104
+ it 'should set the fault_code' do
105
+ @response.fault_code.should == '500'
106
+ end
107
+
108
+ it 'should set the fault_name' do
109
+ @response.fault_name.should match(/unsupported cell/)
110
+ end
111
+ end
112
+
113
+ describe 'with no errors' do
114
+ before(:each) do
115
+ failing_sms
116
+ http_mock = mock('Net::HTTPSuccess')
117
+ http_mock.stubs( :code => '200',
118
+ :message => "OK",
119
+ :content_type => "text/xml",
120
+ :body => success_body,
121
+ :is_a? => Net::HTTPSuccess)
122
+ Net::HTTP.any_instance.stubs(:start).returns http_mock
123
+ @response = @req.send_sms
124
+ end
125
+
126
+ it "should return a response object" do
127
+ @response.class.should == PennySMS::Response
128
+ end
129
+
130
+ it 'should set the status' do
131
+ @response.status.downcase.should == 'ok'
132
+ end
133
+
134
+ it 'should be successful' do
135
+ @response.should be_success
136
+ end
137
+
138
+ it 'should not set the fault_code' do
139
+ @response.fault_code.should be_nil
140
+ end
141
+
142
+ it 'should not set the fault_name' do
143
+ @response.fault_name.should be_nil
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'penny_sms'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+ config.mock_with :mocha
9
+ end
10
+
11
+
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: penny_sms_muncher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - chris A
8
+ - Matthew Shanley
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2010-01-12 00:00:00 -05:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ type: :development
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 1.2.9
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: addressable
28
+ type: :runtime
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 2.1.1
35
+ version:
36
+ - !ruby/object:Gem::Dependency
37
+ name: libxml-ruby
38
+ type: :runtime
39
+ version_requirement:
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 1.1.3
45
+ version:
46
+ description: A little bit of code to make PennySMS XML requests. But not JSON requests right now.
47
+ email: chris@whatbirdthings.com
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - LICENSE
54
+ - README.textile
55
+ files:
56
+ - .document
57
+ - .gitignore
58
+ - API_RESPONSES.txt
59
+ - LICENSE
60
+ - Rakefile
61
+ - VERSION
62
+ - lib/penny_sms.rb
63
+ - penny_sms_muncher.gemspec
64
+ - spec/penny_sms_muncher_spec.rb
65
+ - spec/spec.opts
66
+ - spec/spec_helper.rb
67
+ - README.textile
68
+ has_rdoc: true
69
+ homepage: http://github.com/whatbird/penny_sms_muncher
70
+ licenses: []
71
+
72
+ post_install_message:
73
+ rdoc_options:
74
+ - --charset=UTF-8
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.3.5
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: A little bit of code to make PennySMS XML requests.
96
+ test_files:
97
+ - spec/penny_sms_muncher_spec.rb
98
+ - spec/spec_helper.rb