reddavis-clickatell 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
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
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 reddavis
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.
data/README.rdoc ADDED
@@ -0,0 +1,26 @@
1
+ = Clickatell
2
+
3
+ This is a wrapper for http://www.clickatell.com
4
+
5
+ == Install
6
+
7
+ gem sources -a -http://gemcutter.org
8
+ sudo gem install reddavis-clickatell
9
+
10
+ == How To Use
11
+
12
+ Sending Texts
13
+
14
+ require 'rubygems'
15
+ require 'clickatell'
16
+
17
+ a = Clickatell::Text.new('username', 'password', 'api_id')
18
+ a.send(number, 'this is the message')
19
+
20
+ == TODO
21
+
22
+ * Receive texts
23
+
24
+ == Copyright
25
+
26
+ Copyright (c) 2009 Red Davis. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "reddavis-clickatell"
8
+ gem.summary = %Q{Wrapper for clickatell.com}
9
+ gem.description = %Q{Wrapper for clickatell.com}
10
+ gem.email = "reddavis@gmail.com"
11
+ gem.homepage = "http://github.com/reddavis/clickatell"
12
+ gem.authors = ["reddavis"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_dependency('typhoeus')
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "clickatell #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,42 @@
1
+ module Clickatell
2
+
3
+ class AuthenticationFailed < Exception
4
+ end
5
+
6
+ class UnknownUsernameOrPassword < Exception
7
+ end
8
+
9
+ class AccountFrozen < Exception
10
+ end
11
+
12
+ class IPLockdownViolation < Exception
13
+ end
14
+
15
+ class InvalidNumber < Exception
16
+ end
17
+
18
+ class EmptyMessage < Exception
19
+ end
20
+
21
+ class InvalidAPIID < Exception
22
+ end
23
+
24
+ class MessageTooLong < Exception
25
+ end
26
+
27
+ class NumberBlocked < Exception
28
+ end
29
+
30
+ class NumberDelisted < Exception
31
+ end
32
+
33
+ class NoCreditLeft < Exception
34
+ end
35
+
36
+ class MaxAllowedCredit < Exception
37
+ end
38
+
39
+ class UnknownError < Exception
40
+ end
41
+
42
+ end
@@ -0,0 +1,56 @@
1
+ require 'uri'
2
+
3
+ module Clickatell
4
+
5
+ class Text
6
+ def initialize(username, password, api_id)
7
+ @username, @password, @api_id = username, password, api_id
8
+ end
9
+
10
+ def send(to, message)
11
+ url = send_url(to, message)
12
+ response = Typhoeus::Request.get(url)
13
+ respond(response)
14
+ end
15
+
16
+ private
17
+
18
+ def send_url(to, message)
19
+ "https://api.clickatell.com/http/sendmsg?user=#{@username}&password=#{@password}&api_id=#{@api_id}&to=#{to}&text=#{URI.escape(message)}"
20
+ end
21
+
22
+ def respond(response)
23
+ case response.code
24
+ when 200
25
+ true
26
+ when 001
27
+ raise AuthenticationFailed.new(response.body)
28
+ when 002
29
+ raise UnknownUsernameOrPassword.new(response.body)
30
+ when 004
31
+ raise AccountFrozen.new(response.body)
32
+ when 007
33
+ raise IPLockdownViolation.new(response.body)
34
+ when 106
35
+ raise InvalidNumber.new(response.body)
36
+ when 107
37
+ raise EmptyMessage.new(response.body)
38
+ when 108
39
+ raise InvalidAPIID.new(response.body)
40
+ when 113
41
+ raise MessageTooLong.new(response.body)
42
+ when 121
43
+ raise NumberBlocked.new(response.body)
44
+ when 128
45
+ raise NumberDelisted.new(response.body)
46
+ when 301
47
+ raise NoCreditLeft.new(response.body)
48
+ when 302
49
+ raise MaxAllowedCredit.new(response.body)
50
+ else
51
+ raise UnknownError.new("#{response.code} - #{response.body}")
52
+ end
53
+ end
54
+ end
55
+
56
+ end
data/lib/clickatell.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'typhoeus'
2
+
3
+ require 'clickatell/text'
4
+ require 'clickatell/exceptions'
@@ -0,0 +1,60 @@
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{reddavis-clickatell}
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 = ["reddavis"]
12
+ s.date = %q{2009-11-23}
13
+ s.description = %q{Wrapper for clickatell.com}
14
+ s.email = %q{reddavis@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/clickatell.rb",
27
+ "lib/clickatell/exceptions.rb",
28
+ "lib/clickatell/text.rb",
29
+ "reddavis-clickatell.gemspec",
30
+ "spec/clickatell_spec.rb",
31
+ "spec/spec.opts",
32
+ "spec/spec_helper.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/reddavis/clickatell}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.5}
38
+ s.summary = %q{Wrapper for clickatell.com}
39
+ s.test_files = [
40
+ "spec/clickatell_spec.rb",
41
+ "spec/spec_helper.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
50
+ s.add_runtime_dependency(%q<typhoeus>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
53
+ s.add_dependency(%q<typhoeus>, [">= 0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
57
+ s.add_dependency(%q<typhoeus>, [">= 0"])
58
+ end
59
+ end
60
+
@@ -0,0 +1,218 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Clickatell" do
4
+
5
+ describe "Sending Texts" do
6
+ before do
7
+ response = Typhoeus::Response.new(:code => 200)
8
+ Typhoeus::Request.stub!(:get).and_return(response)
9
+ @a = start_clickatell
10
+ end
11
+
12
+ it "should send text" do
13
+ Typhoeus::Request.should_receive(:get)
14
+ @a.send(444, 'sometext')
15
+ end
16
+
17
+ it "should return true" do
18
+ @a.send(444, 'yer').should be_true
19
+ end
20
+ end
21
+
22
+ describe "Error Handling" do
23
+
24
+ describe "Authentication Fail" do
25
+ before do
26
+ response = build_response(001)
27
+ Typhoeus::Request.stub!(:get).and_return(response)
28
+ @a = start_clickatell
29
+ end
30
+
31
+ it "should raise an AuthenticationFailed exception" do
32
+ lambda do
33
+ @a.send(444, 'test')
34
+ end.should raise_error(Clickatell::AuthenticationFailed)
35
+ end
36
+ end
37
+
38
+ describe "Unknown Username or Password" do
39
+ before do
40
+ response = build_response(002)
41
+ Typhoeus::Request.stub!(:get).and_return(response)
42
+ @a = start_clickatell
43
+ end
44
+
45
+ it "should raise an UnknownUsernameOrPassword exception" do
46
+ lambda do
47
+ @a.send(444, 'test')
48
+ end.should raise_error(Clickatell::UnknownUsernameOrPassword)
49
+ end
50
+ end
51
+
52
+ describe "Account Frozen" do
53
+ before do
54
+ response = build_response(004)
55
+ Typhoeus::Request.stub!(:get).and_return(response)
56
+ @a = start_clickatell
57
+ end
58
+
59
+ it "should raise an AccountFrozen exception" do
60
+ lambda do
61
+ @a.send(444, 'test')
62
+ end.should raise_error(Clickatell::AccountFrozen)
63
+ end
64
+ end
65
+
66
+ describe "IP Lockdown Violation" do
67
+ before do
68
+ response = build_response(007)
69
+ Typhoeus::Request.stub!(:get).and_return(response)
70
+ @a = start_clickatell
71
+ end
72
+
73
+ it "should raise an IPLockdownViolation exception" do
74
+ lambda do
75
+ @a.send(444, 'test')
76
+ end.should raise_error(Clickatell::IPLockdownViolation)
77
+ end
78
+ end
79
+
80
+ describe "Invalid Number" do
81
+ before do
82
+ response = build_response(106)
83
+ Typhoeus::Request.stub!(:get).and_return(response)
84
+ @a = start_clickatell
85
+ end
86
+
87
+ it "should raise an InvalidNumber exception" do
88
+ lambda do
89
+ @a.send(444, 'test')
90
+ end.should raise_error(Clickatell::InvalidNumber)
91
+ end
92
+ end
93
+
94
+ describe "Empty Message" do
95
+ before do
96
+ response = build_response(107)
97
+ Typhoeus::Request.stub!(:get).and_return(response)
98
+ @a = start_clickatell
99
+ end
100
+
101
+ it "should raise an EmptyMessage exception" do
102
+ lambda do
103
+ @a.send(444, 'test')
104
+ end.should raise_error(Clickatell::EmptyMessage)
105
+ end
106
+ end
107
+
108
+ describe "Invalid Or Missing API ID" do
109
+ before do
110
+ response = build_response(108)
111
+ Typhoeus::Request.stub!(:get).and_return(response)
112
+ @a = start_clickatell
113
+ end
114
+
115
+ it "should raise an InvalidAPIID exception" do
116
+ lambda do
117
+ @a.send(444, 'test')
118
+ end.should raise_error(Clickatell::InvalidAPIID)
119
+ end
120
+ end
121
+
122
+ describe "Message Too Long" do
123
+ before do
124
+ response = build_response(113)
125
+ Typhoeus::Request.stub!(:get).and_return(response)
126
+ @a = start_clickatell
127
+ end
128
+
129
+ it "should raise an MessageTooLong exception" do
130
+ lambda do
131
+ @a.send(444, 'test')
132
+ end.should raise_error(Clickatell::MessageTooLong)
133
+ end
134
+ end
135
+
136
+ describe "Number Blocked" do
137
+ before do
138
+ response = build_response(121)
139
+ Typhoeus::Request.stub!(:get).and_return(response)
140
+ @a = start_clickatell
141
+ end
142
+
143
+ it "should raise an NumberBlocked exception" do
144
+ lambda do
145
+ @a.send(444, 'test')
146
+ end.should raise_error(Clickatell::NumberBlocked)
147
+ end
148
+ end
149
+
150
+ describe "Number Delisted" do
151
+ before do
152
+ response = build_response(128)
153
+ Typhoeus::Request.stub!(:get).and_return(response)
154
+ @a = start_clickatell
155
+ end
156
+
157
+ it "should raise an NumberDelisted exception" do
158
+ lambda do
159
+ @a.send(444, 'test')
160
+ end.should raise_error(Clickatell::NumberDelisted)
161
+ end
162
+ end
163
+
164
+ describe "No Credit Left" do
165
+ before do
166
+ response = build_response(301)
167
+ Typhoeus::Request.stub!(:get).and_return(response)
168
+ @a = start_clickatell
169
+ end
170
+
171
+ it "should raise an NoCreditLeft exception" do
172
+ lambda do
173
+ @a.send(444, 'test')
174
+ end.should raise_error(Clickatell::NoCreditLeft)
175
+ end
176
+ end
177
+
178
+ describe "Max Allowed Credit" do
179
+ before do
180
+ response = build_response(302)
181
+ Typhoeus::Request.stub!(:get).and_return(response)
182
+ @a = start_clickatell
183
+ end
184
+
185
+ it "should raise an MaxAllowedCredit exception" do
186
+ lambda do
187
+ @a.send(444, 'test')
188
+ end.should raise_error(Clickatell::MaxAllowedCredit)
189
+ end
190
+ end
191
+
192
+ describe "Unknown Error" do
193
+ before do
194
+ response = build_response(999)
195
+ Typhoeus::Request.stub!(:get).and_return(response)
196
+ @a = start_clickatell
197
+ end
198
+
199
+ it "should raise an UnknownError exception" do
200
+ lambda do
201
+ @a.send(444, 'test')
202
+ end.should raise_error(Clickatell::UnknownError)
203
+ end
204
+ end
205
+
206
+ end
207
+
208
+ private
209
+
210
+ def start_clickatell
211
+ Clickatell::Text.new('username', 'password', 'api_id')
212
+ end
213
+
214
+ def build_response(code)
215
+ Typhoeus::Response.new(:code => code)
216
+ end
217
+
218
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
4
+ require 'clickatell'
5
+ require 'spec'
6
+ require 'spec/autorun'
7
+
8
+ Spec::Runner.configure do |config|
9
+
10
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reddavis-clickatell
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - reddavis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-23 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.9
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: typhoeus
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Wrapper for clickatell.com
36
+ email: reddavis@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - lib/clickatell.rb
52
+ - lib/clickatell/exceptions.rb
53
+ - lib/clickatell/text.rb
54
+ - reddavis-clickatell.gemspec
55
+ - spec/clickatell_spec.rb
56
+ - spec/spec.opts
57
+ - spec/spec_helper.rb
58
+ has_rdoc: true
59
+ homepage: http://github.com/reddavis/clickatell
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.5
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Wrapper for clickatell.com
86
+ test_files:
87
+ - spec/clickatell_spec.rb
88
+ - spec/spec_helper.rb