cn_sms 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ config/sms.yml
2
+ .rvmrc
3
+ pkg/
data/.rvmrc.sample ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.2@cn_sms
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rbraspag.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cn_sms (0.0.4)
5
+ active_support
6
+ routo
7
+ sms_xchange
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ active_support (3.0.0)
13
+ activesupport (= 3.0.0)
14
+ activesupport (3.0.0)
15
+ archive-tar-minitar (0.5.2)
16
+ columnize (0.3.4)
17
+ diff-lcs (1.1.2)
18
+ fakeweb (1.3.0)
19
+ guard (0.5.1)
20
+ thor (~> 0.14.6)
21
+ guard-bundler (0.1.3)
22
+ bundler (>= 1.0.0)
23
+ guard (>= 0.2.2)
24
+ guard-rspec (0.4.0)
25
+ guard (>= 0.4.0)
26
+ i18n (0.6.0)
27
+ linecache19 (0.5.12)
28
+ ruby_core_source (>= 0.1.4)
29
+ mail (2.3.0)
30
+ i18n (>= 0.4.0)
31
+ mime-types (~> 1.16)
32
+ treetop (~> 1.4.8)
33
+ mime-types (1.16)
34
+ polyglot (0.3.1)
35
+ pony (1.3)
36
+ mail (> 2.0)
37
+ routo (0.0.4)
38
+ pony (>= 1.0.0)
39
+ rspec (2.6.0)
40
+ rspec-core (~> 2.6.0)
41
+ rspec-expectations (~> 2.6.0)
42
+ rspec-mocks (~> 2.6.0)
43
+ rspec-core (2.6.4)
44
+ rspec-expectations (2.6.0)
45
+ diff-lcs (~> 1.1.2)
46
+ rspec-mocks (2.6.0)
47
+ ruby-debug-base19 (0.11.25)
48
+ columnize (>= 0.3.1)
49
+ linecache19 (>= 0.5.11)
50
+ ruby_core_source (>= 0.1.4)
51
+ ruby-debug19 (0.11.6)
52
+ columnize (>= 0.3.1)
53
+ linecache19 (>= 0.5.11)
54
+ ruby-debug-base19 (>= 0.11.19)
55
+ ruby_core_source (0.1.5)
56
+ archive-tar-minitar (>= 0.5.2)
57
+ shoulda-matchers (1.0.0.beta3)
58
+ sms_xchange (0.1.0)
59
+ thor (0.14.6)
60
+ treetop (1.4.9)
61
+ polyglot (>= 0.3.1)
62
+
63
+ PLATFORMS
64
+ ruby
65
+
66
+ DEPENDENCIES
67
+ cn_sms!
68
+ fakeweb
69
+ guard-bundler
70
+ guard-rspec
71
+ rspec
72
+ ruby-debug19
73
+ shoulda-matchers
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ guard 'bundler' do
2
+ watch('Gemfile')
3
+ end
4
+
5
+ guard 'rspec', :version => 2, :bundler => false do
6
+ watch(%r{^spec/(.*)_spec\.rb$})
7
+ watch(%r{^lib/cn_sms.rb$}) { "spec" }
8
+ watch(%r{^lib/cn_sms/(.*)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
9
+ watch('spec/spec_helper.rb') { "spec" }
10
+ end
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Chuck Norris SMS
2
+
3
+ SMS Adapter for all gems
4
+
5
+ # Instalation
6
+
7
+ gem install cn_cms
8
+
9
+ create your sms.yml in APP/config
10
+
11
+ production:
12
+ type: smsxchange
13
+ username: 220000521135
14
+ password: 12345
15
+ from: "+1192253300"
16
+
17
+ development:
18
+ type: mock
19
+
20
+ test:
21
+ type: mock
22
+
23
+ # Example
24
+
25
+ CnSms::SMS.send("551165659898","teste")
26
+
27
+ # License
28
+
29
+ (The MIT License)
30
+
31
+ Copyright (c) 2010
32
+
33
+ Permission is hereby granted, free of charge, to any person obtaining
34
+ a copy of this software and associated documentation files (the
35
+ 'Software'), to deal in the Software without restriction, including
36
+ without limitation the rights to use, copy, modify, merge, publish,
37
+ distribute, sublicense, and/or sell copies of the Software, and to
38
+ permit persons to whom the Software is furnished to do so, subject to
39
+ the following conditions:
40
+
41
+ The above copyright notice and this permission notice shall be
42
+ included in all copies or substantial portions of the Software.
43
+
44
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
45
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
46
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
47
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
48
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
49
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
50
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
51
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/cn_sms.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "cn_sms/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "cn_sms"
7
+ s.version = CnSms::VERSION
8
+ s.authors = [ "Renato Elias", "Fernando Chucre"]
9
+ s.email = %w[renato.elias@gmail.com fernandochucre@gmail.com]
10
+ s.homepage = "http://github.com/renatoelias/cn_braspag"
11
+ s.summary = "SMS Adapter for all gems"
12
+ s.description = "SMS Adapter for all gems"
13
+
14
+ s.rubyforge_project = "cn_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
+ s.add_dependency 'active_support'
22
+ s.add_dependency 'routo'
23
+ s.add_dependency 'sms_xchange'
24
+
25
+ s.add_development_dependency "rspec"
26
+ s.add_development_dependency "fakeweb"
27
+ s.add_development_dependency "shoulda-matchers"
28
+ s.add_development_dependency "guard-rspec"
29
+ s.add_development_dependency "guard-bundler"
30
+ s.add_development_dependency "ruby-debug19"
31
+ end
@@ -0,0 +1,17 @@
1
+ sandbox:
2
+ type: routo
3
+ username: 1263421
4
+ password: abcdefg
5
+ from: "1192253300"
6
+
7
+ production:
8
+ type: smsxchange
9
+ username: 220000521135
10
+ password: 12345
11
+ from: "+1192253300"
12
+
13
+ development:
14
+ type: mock
15
+
16
+ test:
17
+ type: mock
@@ -0,0 +1,19 @@
1
+ module CnSms
2
+ module Adapter
3
+ class Base
4
+ def initialize(config)
5
+ raise RuntimeError("must implement")
6
+ end
7
+
8
+ def send(phone,msg)
9
+ if (msg.size > 160)
10
+ raise SMSError, "text to long"
11
+ end
12
+ match_phone = phone.to_s =~ /55[0-9]{10}/
13
+ if (match_phone.nil?)
14
+ raise SMSError, "phone number incorrect format (#{phone})"
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ module CnSms
2
+ module Adapter
3
+ class Mock < Base
4
+ mattr_accessor :sent_sms
5
+ @@sent_sms = nil
6
+
7
+ def initialize(config)
8
+ @@sent_sms = []
9
+ end
10
+
11
+ def send(phone,msg)
12
+ super(phone,msg)
13
+ @@sent_sms += [{:phone=>phone,:msg=>msg}]
14
+ puts "sms sent phone:#{phone}. Message:#{msg}"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ module CnSms
2
+ module Adapter
3
+ class Routo < Base
4
+ def initialize(config)
5
+ Routo.username = config['username']
6
+ Routo.password = config['password']
7
+ Routo.ownnum = config["from"]
8
+ Routo.type = "SMS"
9
+ end
10
+
11
+ def send(phone,msg)
12
+ super(phone,msg)
13
+ phone = phone.delete "+"
14
+ Routo.send_sms msg,phone
15
+ puts "sms sent phone:#{phone}. Message:#{msg}"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ module CnSms
2
+ module Adapter
3
+ class Smsxchange < Base
4
+ @client = nil
5
+
6
+ def initialize(config)
7
+ @client = SmsXchange.new(:username=>config['username'],:password=>config['password'],:from=>config["from"])
8
+ end
9
+
10
+ def send(phone,msg)
11
+ super(phone,msg)
12
+ @client.send(phone,msg)
13
+ puts "sms sent phone:#{phone}. Message:#{msg}"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ module CnSms
2
+ class SMS
3
+ @@sms_sender = nil
4
+
5
+ def self.send(phone,msg)
6
+ initialize_sms_sender
7
+ @@sms_sender.send(phone,msg)
8
+ end
9
+
10
+ protected
11
+ def self.initialize_sms_sender
12
+ if (@@sms_sender.nil?)
13
+ options = YAML.load_file("config/sms.yml")
14
+ adapter = options[ENV["RACK_ENV"]]["type"].capitalize
15
+ sms_adapter = "CnSms::Adapter::#{adapter}".constantize
16
+ @@sms_sender = sms_adapter.new(options[ENV["RACK_ENV"]])
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module CnSms
2
+ class SMSError < RuntimeError ; end
3
+ end
@@ -0,0 +1,4 @@
1
+ module CnSms
2
+ class Utils
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module CnSms
2
+ VERSION = "0.0.5"
3
+ end
data/lib/cn_sms.rb ADDED
@@ -0,0 +1,25 @@
1
+ require "cn_sms/version"
2
+
3
+ ENV["RACK_ENV"] ||= "development"
4
+
5
+ require 'bundler'
6
+
7
+ Bundler.setup
8
+
9
+ require 'net/http'
10
+ require 'uri'
11
+ require 'active_support'
12
+ require 'routo'
13
+ require 'sms_xchange'
14
+
15
+ Bundler.require(:default, ENV["RACK_ENV"].to_sym)
16
+
17
+
18
+ require 'cn_sms/connection'
19
+ require 'cn_sms/errors'
20
+ require 'cn_sms/utils'
21
+
22
+ require "cn_sms/adapter/base"
23
+ require "cn_sms/adapter/mock"
24
+ require "cn_sms/adapter/routo"
25
+ require "cn_sms/adapter/smsxchange"
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'cn_sms'
3
+ require 'fakeweb'
4
+
5
+ RSpec.configure do |config|
6
+ config.mock_with :rspec
7
+
8
+ HTTPI.log = false
9
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cn_sms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Renato Elias
9
+ - Fernando Chucre
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2011-07-21 00:00:00.000000000 -03:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: active_support
18
+ requirement: &2151853540 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *2151853540
27
+ - !ruby/object:Gem::Dependency
28
+ name: routo
29
+ requirement: &2151852660 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *2151852660
38
+ - !ruby/object:Gem::Dependency
39
+ name: sms_xchange
40
+ requirement: &2151851800 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: *2151851800
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ requirement: &2151849980 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *2151849980
60
+ - !ruby/object:Gem::Dependency
61
+ name: fakeweb
62
+ requirement: &2151848060 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *2151848060
71
+ - !ruby/object:Gem::Dependency
72
+ name: shoulda-matchers
73
+ requirement: &2151847000 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *2151847000
82
+ - !ruby/object:Gem::Dependency
83
+ name: guard-rspec
84
+ requirement: &2151844620 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: *2151844620
93
+ - !ruby/object:Gem::Dependency
94
+ name: guard-bundler
95
+ requirement: &2151841900 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ type: :development
102
+ prerelease: false
103
+ version_requirements: *2151841900
104
+ - !ruby/object:Gem::Dependency
105
+ name: ruby-debug19
106
+ requirement: &2151840700 !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: *2151840700
115
+ description: SMS Adapter for all gems
116
+ email:
117
+ - renato.elias@gmail.com
118
+ - fernandochucre@gmail.com
119
+ executables: []
120
+ extensions: []
121
+ extra_rdoc_files: []
122
+ files:
123
+ - .gitignore
124
+ - .rvmrc.sample
125
+ - Gemfile
126
+ - Gemfile.lock
127
+ - Guardfile
128
+ - README.md
129
+ - Rakefile
130
+ - cn_sms.gemspec
131
+ - config/sms_sample.yml
132
+ - lib/cn_sms.rb
133
+ - lib/cn_sms/adapter/base.rb
134
+ - lib/cn_sms/adapter/mock.rb
135
+ - lib/cn_sms/adapter/routo.rb
136
+ - lib/cn_sms/adapter/smsxchange.rb
137
+ - lib/cn_sms/connection.rb
138
+ - lib/cn_sms/errors.rb
139
+ - lib/cn_sms/utils.rb
140
+ - lib/cn_sms/version.rb
141
+ - spec/spec_helper.rb
142
+ has_rdoc: true
143
+ homepage: http://github.com/renatoelias/cn_braspag
144
+ licenses: []
145
+ post_install_message:
146
+ rdoc_options: []
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ! '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubyforge_project: cn_sms
163
+ rubygems_version: 1.6.2
164
+ signing_key:
165
+ specification_version: 3
166
+ summary: SMS Adapter for all gems
167
+ test_files:
168
+ - spec/spec_helper.rb