esendex 0.1.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.
- data/.document +5 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +30 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +49 -0
- data/Rakefile +60 -0
- data/VERSION +1 -0
- data/esendex.gemspec +96 -0
- data/lib/esendex.rb +8 -0
- data/lib/esendex/account.rb +46 -0
- data/lib/esendex/exceptions.rb +23 -0
- data/lib/esendex/message.rb +39 -0
- data/lib/esendex/message_batch_submission.rb +49 -0
- data/test/helper.rb +21 -0
- data/test/integration/test_account.rb +26 -0
- data/test/test_account.rb +63 -0
- data/test/test_message.rb +24 -0
- data/test/test_message_batch.rb +22 -0
- data/test/test_nokogiri.rb +19 -0
- metadata +258 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem "nestful", ">= 0.0.6"
|
6
|
+
gem "i18n"
|
7
|
+
gem "nokogiri", ">=1.4.4"
|
8
|
+
|
9
|
+
# Add dependencies to develop your gem here.
|
10
|
+
# Include everything needed to run rake, tests, features, etc.
|
11
|
+
group :development do
|
12
|
+
gem "shoulda", ">= 0"
|
13
|
+
gem "bundler", "~> 1.0.0"
|
14
|
+
gem "jeweler", "~> 1.5.2"
|
15
|
+
gem "rcov", ">= 0"
|
16
|
+
gem "mocha", ">=0.9.12"
|
17
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.0.5)
|
5
|
+
git (1.2.5)
|
6
|
+
i18n (0.5.0)
|
7
|
+
jeweler (1.5.2)
|
8
|
+
bundler (~> 1.0.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
mocha (0.9.12)
|
12
|
+
nestful (0.0.6)
|
13
|
+
activesupport (>= 3.0.0.beta)
|
14
|
+
nokogiri (1.4.4)
|
15
|
+
rake (0.8.7)
|
16
|
+
rcov (0.9.9)
|
17
|
+
shoulda (2.11.3)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
bundler (~> 1.0.0)
|
24
|
+
i18n
|
25
|
+
jeweler (~> 1.5.2)
|
26
|
+
mocha (>= 0.9.12)
|
27
|
+
nestful (>= 0.0.6)
|
28
|
+
nokogiri (>= 1.4.4)
|
29
|
+
rcov
|
30
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Esendex
|
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,49 @@
|
|
1
|
+
= esendex.gem
|
2
|
+
|
3
|
+
Gem for interacting with the Esendex API
|
4
|
+
|
5
|
+
This is in very early stages of development but supports sending one
|
6
|
+
|
7
|
+
== Usage
|
8
|
+
|
9
|
+
=== Setting up
|
10
|
+
|
11
|
+
gem install esendex
|
12
|
+
|
13
|
+
=== Sending Messages
|
14
|
+
|
15
|
+
First instantiate an Account with your credentials
|
16
|
+
|
17
|
+
account = Account.new("EX123456", "user@company.com", "yourpassword")
|
18
|
+
|
19
|
+
then, call the send method on the account object with a message. The return value is a batch_id you can use to obtain the status of the messages you have sent.
|
20
|
+
|
21
|
+
batch_id = account.send_message(Message.new("07777111222", "Saying hello to the world with the help of Esendex"))
|
22
|
+
|
23
|
+
Multiple messages are sent by passing an array of Messages to the send_messages method
|
24
|
+
|
25
|
+
batch_id = account.send_messages([Message.new("07777111222", "Hello"), Message.new("07777111333", "Hi")])
|
26
|
+
|
27
|
+
== Building
|
28
|
+
|
29
|
+
The plan is to publish this so you can perform gem install but if you can't wait then feel free to download
|
30
|
+
|
31
|
+
=== Testing
|
32
|
+
|
33
|
+
rake test
|
34
|
+
|
35
|
+
will run unit tests, ie those in the root of the test folder
|
36
|
+
|
37
|
+
rake integration_test
|
38
|
+
|
39
|
+
will run integration tests, ie only those in the /test/integration folder
|
40
|
+
|
41
|
+
== Contributing
|
42
|
+
|
43
|
+
Please fork as you see fit and let us know when you have something that should be part of the gem.
|
44
|
+
|
45
|
+
== Copyright
|
46
|
+
|
47
|
+
Copyright (c) 2011 Esendex Ltd. See LICENSE.txt for
|
48
|
+
further details.
|
49
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "esendex"
|
16
|
+
gem.homepage = "http://github.com/esendex/esendex.gem"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = "for interacting with the Esendex API"
|
19
|
+
gem.description = ""
|
20
|
+
gem.email = "support@esendex.com"
|
21
|
+
gem.authors = ["Adam Bird"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
gem.add_dependency 'nokogiri', '>=1.4.4'
|
25
|
+
gem.add_dependency 'i18n'
|
26
|
+
gem.add_dependency 'nestful', '>= 0.0.6'
|
27
|
+
end
|
28
|
+
Jeweler::RubygemsDotOrgTasks.new
|
29
|
+
|
30
|
+
require 'rake/testtask'
|
31
|
+
Rake::TestTask.new(:test) do |test|
|
32
|
+
test.libs << 'lib' << 'test'
|
33
|
+
test.pattern = 'test/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
|
37
|
+
Rake::TestTask.new(:integration_test) do |test|
|
38
|
+
test.libs << 'lib' << 'test'
|
39
|
+
test.pattern = 'test/integration/test_*.rb'
|
40
|
+
test.verbose = true
|
41
|
+
end
|
42
|
+
|
43
|
+
require 'rcov/rcovtask'
|
44
|
+
Rcov::RcovTask.new do |test|
|
45
|
+
test.libs << 'test'
|
46
|
+
test.pattern = 'test/**/test_*.rb'
|
47
|
+
test.verbose = true
|
48
|
+
end
|
49
|
+
|
50
|
+
task :default => :test
|
51
|
+
|
52
|
+
require 'rake/rdoctask'
|
53
|
+
Rake::RDocTask.new do |rdoc|
|
54
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
55
|
+
|
56
|
+
rdoc.rdoc_dir = 'rdoc'
|
57
|
+
rdoc.title = "esendex #{version}"
|
58
|
+
rdoc.rdoc_files.include('README*')
|
59
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
60
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/esendex.gemspec
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{esendex}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Adam Bird"]
|
12
|
+
s.date = %q{2011-05-05}
|
13
|
+
s.description = %q{}
|
14
|
+
s.email = %q{support@esendex.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"esendex.gemspec",
|
28
|
+
"lib/esendex.rb",
|
29
|
+
"lib/esendex/account.rb",
|
30
|
+
"lib/esendex/exceptions.rb",
|
31
|
+
"lib/esendex/message.rb",
|
32
|
+
"lib/esendex/message_batch_submission.rb",
|
33
|
+
"test/helper.rb",
|
34
|
+
"test/integration/test_account.rb",
|
35
|
+
"test/test_account.rb",
|
36
|
+
"test/test_message.rb",
|
37
|
+
"test/test_message_batch.rb",
|
38
|
+
"test/test_nokogiri.rb"
|
39
|
+
]
|
40
|
+
s.homepage = %q{http://github.com/esendex/esendex.gem}
|
41
|
+
s.licenses = ["MIT"]
|
42
|
+
s.require_paths = ["lib"]
|
43
|
+
s.rubygems_version = %q{1.6.2}
|
44
|
+
s.summary = %q{for interacting with the Esendex API}
|
45
|
+
s.test_files = [
|
46
|
+
"test/helper.rb",
|
47
|
+
"test/integration/test_account.rb",
|
48
|
+
"test/test_account.rb",
|
49
|
+
"test/test_message.rb",
|
50
|
+
"test/test_message_batch.rb",
|
51
|
+
"test/test_nokogiri.rb"
|
52
|
+
]
|
53
|
+
|
54
|
+
if s.respond_to? :specification_version then
|
55
|
+
s.specification_version = 3
|
56
|
+
|
57
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
58
|
+
s.add_runtime_dependency(%q<nestful>, [">= 0.0.6"])
|
59
|
+
s.add_runtime_dependency(%q<i18n>, [">= 0"])
|
60
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.4"])
|
61
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
62
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
63
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
64
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
65
|
+
s.add_development_dependency(%q<mocha>, [">= 0.9.12"])
|
66
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.4"])
|
67
|
+
s.add_runtime_dependency(%q<i18n>, [">= 0"])
|
68
|
+
s.add_runtime_dependency(%q<nestful>, [">= 0.0.6"])
|
69
|
+
else
|
70
|
+
s.add_dependency(%q<nestful>, [">= 0.0.6"])
|
71
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
72
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
|
73
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
74
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
75
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
76
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
77
|
+
s.add_dependency(%q<mocha>, [">= 0.9.12"])
|
78
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
|
79
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
80
|
+
s.add_dependency(%q<nestful>, [">= 0.0.6"])
|
81
|
+
end
|
82
|
+
else
|
83
|
+
s.add_dependency(%q<nestful>, [">= 0.0.6"])
|
84
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
85
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
|
86
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
87
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
88
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
89
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
90
|
+
s.add_dependency(%q<mocha>, [">= 0.9.12"])
|
91
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
|
92
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
93
|
+
s.add_dependency(%q<nestful>, [">= 0.0.6"])
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
data/lib/esendex.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'nestful'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module Esendex
|
5
|
+
class Account
|
6
|
+
attr_accessor :account_reference, :username, :password
|
7
|
+
attr_reader :messages_remaining
|
8
|
+
|
9
|
+
def initialize(account_reference, username, password, connection = Nestful::Connection.new('https://api.esendex.com'))
|
10
|
+
@account_reference = account_reference
|
11
|
+
@username = username
|
12
|
+
@password = password
|
13
|
+
|
14
|
+
@connection = connection
|
15
|
+
@connection.user = @username
|
16
|
+
@connection.password = @password
|
17
|
+
@connection.auth_type = :basic
|
18
|
+
|
19
|
+
begin
|
20
|
+
response = @connection.get "/v0.1/accounts/#{@account_reference}"
|
21
|
+
doc = Nokogiri::XML(response.body)
|
22
|
+
@messages_remaining = doc.at_xpath('//api:accounts/api:account/api:messagesremaining', 'api' => Esendex::API_NAMESPACE).content.to_i
|
23
|
+
rescue Exception => exception
|
24
|
+
raise ApiErrorFactory.new.get_api_error(exception)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def send_message(message)
|
29
|
+
self.send_messages([message])
|
30
|
+
end
|
31
|
+
|
32
|
+
def send_messages(messages)
|
33
|
+
|
34
|
+
batch_submission = MessageBatchSubmission.new(@account_reference, messages)
|
35
|
+
|
36
|
+
begin
|
37
|
+
response = @connection.post "/v1.0/messagedispatcher", batch_submission.to_s
|
38
|
+
doc = Nokogiri::XML(response.body)
|
39
|
+
doc.at_xpath('//api:messageheaders', 'api' => Esendex::API_NAMESPACE)['batchid']
|
40
|
+
rescue Exception => exception
|
41
|
+
raise ApiErrorFactory.new.get_api_error(exception)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Esendex
|
2
|
+
class ApiErrorFactory
|
3
|
+
def get_api_error(source_error)
|
4
|
+
case source_error
|
5
|
+
when Nestful::ForbiddenAccess
|
6
|
+
return ForbiddenError.new
|
7
|
+
when Nestful::UnauthorizedAccess
|
8
|
+
return NotAuthorizedError.new
|
9
|
+
else
|
10
|
+
return ApiError.new(source_error)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class ApiError < StandardError
|
16
|
+
end
|
17
|
+
|
18
|
+
class NotAuthorizedError < ApiError
|
19
|
+
end
|
20
|
+
|
21
|
+
class ForbiddenError < ApiError
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'nokogiri'
|
3
|
+
include REXML
|
4
|
+
|
5
|
+
# <message>
|
6
|
+
# <to>$TO</to>
|
7
|
+
# <body>$BODY</body>
|
8
|
+
# </message>
|
9
|
+
|
10
|
+
module Esendex
|
11
|
+
class Message
|
12
|
+
attr_accessor :to, :body, :from
|
13
|
+
|
14
|
+
def initialize(to, body)
|
15
|
+
self.to = to
|
16
|
+
self.body = body
|
17
|
+
end
|
18
|
+
|
19
|
+
def xml_node
|
20
|
+
doc = Nokogiri::XML('<message/>')
|
21
|
+
|
22
|
+
to = Nokogiri::XML::Node.new 'to', doc
|
23
|
+
to.content = self.to
|
24
|
+
doc.root.add_child(to)
|
25
|
+
|
26
|
+
body = Nokogiri::XML::Node.new 'body', doc
|
27
|
+
body.content = self.body
|
28
|
+
doc.root.add_child(body)
|
29
|
+
|
30
|
+
if self.from
|
31
|
+
from = Nokogiri::XML::Node.new 'from', doc
|
32
|
+
from.content = self.from
|
33
|
+
doc.root.add_child(from)
|
34
|
+
end
|
35
|
+
|
36
|
+
doc.root
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
#<messages>
|
4
|
+
# <accountreference>EX000000</accountreference>
|
5
|
+
# <message>
|
6
|
+
# <to>someone</to>
|
7
|
+
# <body>$BODY</body>
|
8
|
+
# </message>
|
9
|
+
# <message>
|
10
|
+
# <to>$TO_</to>
|
11
|
+
# <body>$BODY</body>
|
12
|
+
# </message>
|
13
|
+
#</messages>
|
14
|
+
|
15
|
+
module Esendex
|
16
|
+
class MessageBatchSubmission
|
17
|
+
attr_accessor :account_reference, :messages, :send_at
|
18
|
+
|
19
|
+
def initialize(account_reference, messages)
|
20
|
+
@account_reference = account_reference
|
21
|
+
@messages = messages
|
22
|
+
@send_at = send_at
|
23
|
+
end
|
24
|
+
|
25
|
+
def xml_node
|
26
|
+
doc = Nokogiri::XML'<messages/>'
|
27
|
+
|
28
|
+
account_reference = Nokogiri::XML::Node.new 'accountreference', doc
|
29
|
+
account_reference.content = self.account_reference
|
30
|
+
doc.root.add_child(account_reference)
|
31
|
+
|
32
|
+
if self.send_at
|
33
|
+
send_at = Nokogiri::XML::Node.new 'sendat', doc
|
34
|
+
send_at.content = self.send_at.strftime("%Y-%m-%dT%H:%M:%S")
|
35
|
+
doc.root.add_child(send_at)
|
36
|
+
end
|
37
|
+
|
38
|
+
@messages.each do |message|
|
39
|
+
doc.root.add_child(message.xml_node)
|
40
|
+
end
|
41
|
+
|
42
|
+
doc.root
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_s
|
46
|
+
self.xml_node.to_s
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
require 'test/unit'
|
12
|
+
require 'shoulda'
|
13
|
+
require 'mocha'
|
14
|
+
|
15
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
16
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
17
|
+
|
18
|
+
require 'esendex'
|
19
|
+
|
20
|
+
class Test::Unit::TestCase
|
21
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'helper'
|
2
|
+
include Esendex
|
3
|
+
|
4
|
+
class TestAccount < Test::Unit::TestCase
|
5
|
+
should "validate account when a new one is created" do
|
6
|
+
code_challenge_account = Account.new("EX0068832", "codechallenge@esendex.com", "c0d3cha113ng3")
|
7
|
+
|
8
|
+
assert code_challenge_account.messages_remaining > 0
|
9
|
+
end
|
10
|
+
|
11
|
+
should "fail authorisation" do
|
12
|
+
begin
|
13
|
+
code_challenge_account = Account.new("EX0068832", "bilge", "bilge")
|
14
|
+
rescue Esendex::ForbiddenError
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
should "send a message" do
|
20
|
+
code_challenge_account = Account.new("EX0068832", "codechallenge@esendex.com", "c0d3cha113ng3")
|
21
|
+
|
22
|
+
batch_id = code_challenge_account.send_message(Message.new("447700900000", "Hello from the Esendex Ruby Gem"))
|
23
|
+
|
24
|
+
assert batch_id
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'nestful'
|
3
|
+
include Esendex
|
4
|
+
|
5
|
+
class TestAccount < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def raw_mock_connection
|
8
|
+
@user = "codechallenge@esendex.com"
|
9
|
+
@password = "c0d3cha113ng3"
|
10
|
+
@account_reference = "EX0068832"
|
11
|
+
connection = mock()
|
12
|
+
connection.expects(:user=).with(@user)
|
13
|
+
connection.expects(:password=).with(@password)
|
14
|
+
connection.expects(:auth_type=).with(:basic)
|
15
|
+
connection
|
16
|
+
end
|
17
|
+
|
18
|
+
def mock_connection
|
19
|
+
connection = raw_mock_connection
|
20
|
+
account_initialisation_response = mock()
|
21
|
+
account_initialisation_response.expects(:body).returns("<?xml version=\"1.0\" encoding=\"utf-8\"?><accounts xmlns=\"http://api.esendex.com/ns/\"><account id=\"2b4a326c-41de-4a57-a577-c7d742dc145c\" uri=\"http://api.esendex.com/v1.0/accounts/2b4a326c-41de-4a57-a577-c7d742dc145c\"><balanceremaining domesticmessages=\"100\" internationalmessages=\"100\">$0.00</balanceremaining><reference>EX0068832</reference><address>447786204254</address><type>Professional</type><messagesremaining>100</messagesremaining><expireson>2015-12-31T00:00:00</expireson><role>PowerUser</role><defaultdialcode>44</defaultdialcode><settings uri=\"http://api.esendex.com/v1.0/accounts/2b4a326c-41de-4a57-a577-c7d742dc145c/settings\" /></account></accounts>")
|
22
|
+
|
23
|
+
connection.expects(:get).with("/v0.1/accounts/#{@account_reference}").returns(account_initialisation_response)
|
24
|
+
connection
|
25
|
+
end
|
26
|
+
|
27
|
+
should "validate account when a new one is created" do
|
28
|
+
connection = mock_connection
|
29
|
+
|
30
|
+
code_challenge_account = Account.new(@account_reference, @user, @password, connection)
|
31
|
+
|
32
|
+
assert_equal 100, code_challenge_account.messages_remaining
|
33
|
+
end
|
34
|
+
|
35
|
+
should "raise an ForbiddenError when a 403 is returned from API" do
|
36
|
+
connection = raw_mock_connection
|
37
|
+
connection.stubs(:get).raises(Nestful::ForbiddenAccess.new nil)
|
38
|
+
|
39
|
+
begin
|
40
|
+
account = Account.new(@account_reference, @user, @password, connection)
|
41
|
+
rescue Esendex::ForbiddenError
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
should "send a message" do
|
46
|
+
connection = mock_connection
|
47
|
+
batch_id = "2b4a326c-41de-4a57-a577-c7d742dc145c"
|
48
|
+
|
49
|
+
message_send_response = mock()
|
50
|
+
message_send_response.expects(:body).returns("<?xml version=\"1.0\" encoding=\"utf-8\"?> <messageheaders batchid=\"#{batch_id}\" xmlns=\"http://api.esendex.com/ns/\"> <messageheader\ uri=\"http://api.esendex.com/v1.0/MessageHeaders/00000000-0000-0000-0000-000000000000\" id=\"00000000-0000-0000-0000-000000000000\" /></messageheaders>")
|
51
|
+
connection.expects(:post).with("/v1.0/messagedispatcher", anything).returns(message_send_response)
|
52
|
+
|
53
|
+
code_challenge_account = Account.new(@account_reference, @user, @password, connection)
|
54
|
+
|
55
|
+
result = code_challenge_account.send_message(Message.new("447815777555", "Hello from the Esendex Ruby Gem"))
|
56
|
+
|
57
|
+
assert_equal batch_id, result
|
58
|
+
end
|
59
|
+
|
60
|
+
should "return populated inbox" do
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestMessage < Test::Unit::TestCase
|
4
|
+
should "create a valid xml representation of a message" do
|
5
|
+
target = Esendex::Message.new("07777111333", "Hello World")
|
6
|
+
|
7
|
+
actual = target.xml_node
|
8
|
+
|
9
|
+
assert_equal "07777111333", actual.at_xpath('//message/to').content
|
10
|
+
assert_equal "Hello World", actual.at_xpath('//message/body').content
|
11
|
+
end
|
12
|
+
|
13
|
+
should "create a valid xml representation if from specified" do
|
14
|
+
target = Esendex::Message.new("07777111333", "Hello World")
|
15
|
+
target.from = "BilgeInc"
|
16
|
+
|
17
|
+
actual = target.xml_node
|
18
|
+
|
19
|
+
assert_equal "07777111333", actual.at_xpath('//message/to').content
|
20
|
+
assert_equal "Hello World", actual.at_xpath('//message/body').content
|
21
|
+
assert_equal "BilgeInc", actual.at_xpath('//message/from').content
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestMessageBatchSubmission < Test::Unit::TestCase
|
4
|
+
should "format scheduled date time correctly" do
|
5
|
+
# yyyy-MM-ddThh:mm:ss
|
6
|
+
|
7
|
+
target_time = Time.local(2011, 4, 7, 15, 0, 0)
|
8
|
+
|
9
|
+
submission = MessageBatchSubmission.new("EX1234556", [Message.new("0777111222", "I'm sending this in the future")])
|
10
|
+
submission.send_at = target_time
|
11
|
+
|
12
|
+
assert_equal "2011-04-07T15:00:00", submission.xml_node.at_xpath('//messages/sendat').content
|
13
|
+
end
|
14
|
+
|
15
|
+
should "contain multiple messages" do
|
16
|
+
submission = MessageBatchSubmission.new("EX1234556", [Message.new("0777111222", "I'm sending this in the future"), Message.new("0777111333", "I'm sending this in the future")])
|
17
|
+
|
18
|
+
message_elements = submission.xml_node.xpath('//messages/message')
|
19
|
+
|
20
|
+
assert_equal 2, message_elements.count
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'Nokogiri'
|
3
|
+
|
4
|
+
class TestNokogiri < Test::Unit::TestCase
|
5
|
+
should "get same from Nokogiri using XPath or CSS syntax" do
|
6
|
+
|
7
|
+
xml_source = "<?xml version=\"1.0\" encoding=\"utf-8\"?><accounts xmlns=\"http://api.esendex.com/ns/\"><account id=\"2b4a326c-41de-4a57-a577-c7d742dc145c\" uri=\"http://api.esendex.com/v1.0/accounts/2b4a326c-41de-4a57-a577-c7d742dc145c\"><messagesremaining>100</messagesremaining></account></accounts>"
|
8
|
+
|
9
|
+
ndoc = Nokogiri::XML(xml_source)
|
10
|
+
|
11
|
+
node_value = ndoc.css("accounts account messagesremaining").count
|
12
|
+
assert_equal 1, node_value
|
13
|
+
|
14
|
+
node_value = ndoc.xpath('//api:accounts/api:account/api:messagesremaining', 'api' => 'http://api.esendex.com/ns/').count
|
15
|
+
assert_equal 1, node_value
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
metadata
ADDED
@@ -0,0 +1,258 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: esendex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Adam Bird
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-05 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 19
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
- 6
|
32
|
+
version: 0.0.6
|
33
|
+
name: nestful
|
34
|
+
version_requirements: *id001
|
35
|
+
prerelease: false
|
36
|
+
type: :runtime
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
name: i18n
|
48
|
+
version_requirements: *id002
|
49
|
+
prerelease: false
|
50
|
+
type: :runtime
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 15
|
58
|
+
segments:
|
59
|
+
- 1
|
60
|
+
- 4
|
61
|
+
- 4
|
62
|
+
version: 1.4.4
|
63
|
+
name: nokogiri
|
64
|
+
version_requirements: *id003
|
65
|
+
prerelease: false
|
66
|
+
type: :runtime
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
name: shoulda
|
78
|
+
version_requirements: *id004
|
79
|
+
prerelease: false
|
80
|
+
type: :development
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 23
|
88
|
+
segments:
|
89
|
+
- 1
|
90
|
+
- 0
|
91
|
+
- 0
|
92
|
+
version: 1.0.0
|
93
|
+
name: bundler
|
94
|
+
version_requirements: *id005
|
95
|
+
prerelease: false
|
96
|
+
type: :development
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
hash: 7
|
104
|
+
segments:
|
105
|
+
- 1
|
106
|
+
- 5
|
107
|
+
- 2
|
108
|
+
version: 1.5.2
|
109
|
+
name: jeweler
|
110
|
+
version_requirements: *id006
|
111
|
+
prerelease: false
|
112
|
+
type: :development
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
hash: 3
|
120
|
+
segments:
|
121
|
+
- 0
|
122
|
+
version: "0"
|
123
|
+
name: rcov
|
124
|
+
version_requirements: *id007
|
125
|
+
prerelease: false
|
126
|
+
type: :development
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
hash: 35
|
134
|
+
segments:
|
135
|
+
- 0
|
136
|
+
- 9
|
137
|
+
- 12
|
138
|
+
version: 0.9.12
|
139
|
+
name: mocha
|
140
|
+
version_requirements: *id008
|
141
|
+
prerelease: false
|
142
|
+
type: :development
|
143
|
+
- !ruby/object:Gem::Dependency
|
144
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
hash: 15
|
150
|
+
segments:
|
151
|
+
- 1
|
152
|
+
- 4
|
153
|
+
- 4
|
154
|
+
version: 1.4.4
|
155
|
+
name: nokogiri
|
156
|
+
version_requirements: *id009
|
157
|
+
prerelease: false
|
158
|
+
type: :runtime
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
hash: 3
|
166
|
+
segments:
|
167
|
+
- 0
|
168
|
+
version: "0"
|
169
|
+
name: i18n
|
170
|
+
version_requirements: *id010
|
171
|
+
prerelease: false
|
172
|
+
type: :runtime
|
173
|
+
- !ruby/object:Gem::Dependency
|
174
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
175
|
+
none: false
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
hash: 19
|
180
|
+
segments:
|
181
|
+
- 0
|
182
|
+
- 0
|
183
|
+
- 6
|
184
|
+
version: 0.0.6
|
185
|
+
name: nestful
|
186
|
+
version_requirements: *id011
|
187
|
+
prerelease: false
|
188
|
+
type: :runtime
|
189
|
+
description: ""
|
190
|
+
email: support@esendex.com
|
191
|
+
executables: []
|
192
|
+
|
193
|
+
extensions: []
|
194
|
+
|
195
|
+
extra_rdoc_files:
|
196
|
+
- LICENSE.txt
|
197
|
+
- README.rdoc
|
198
|
+
files:
|
199
|
+
- .document
|
200
|
+
- Gemfile
|
201
|
+
- Gemfile.lock
|
202
|
+
- LICENSE.txt
|
203
|
+
- README.rdoc
|
204
|
+
- Rakefile
|
205
|
+
- VERSION
|
206
|
+
- esendex.gemspec
|
207
|
+
- lib/esendex.rb
|
208
|
+
- lib/esendex/account.rb
|
209
|
+
- lib/esendex/exceptions.rb
|
210
|
+
- lib/esendex/message.rb
|
211
|
+
- lib/esendex/message_batch_submission.rb
|
212
|
+
- test/helper.rb
|
213
|
+
- test/integration/test_account.rb
|
214
|
+
- test/test_account.rb
|
215
|
+
- test/test_message.rb
|
216
|
+
- test/test_message_batch.rb
|
217
|
+
- test/test_nokogiri.rb
|
218
|
+
has_rdoc: true
|
219
|
+
homepage: http://github.com/esendex/esendex.gem
|
220
|
+
licenses:
|
221
|
+
- MIT
|
222
|
+
post_install_message:
|
223
|
+
rdoc_options: []
|
224
|
+
|
225
|
+
require_paths:
|
226
|
+
- lib
|
227
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
228
|
+
none: false
|
229
|
+
requirements:
|
230
|
+
- - ">="
|
231
|
+
- !ruby/object:Gem::Version
|
232
|
+
hash: 3
|
233
|
+
segments:
|
234
|
+
- 0
|
235
|
+
version: "0"
|
236
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
237
|
+
none: false
|
238
|
+
requirements:
|
239
|
+
- - ">="
|
240
|
+
- !ruby/object:Gem::Version
|
241
|
+
hash: 3
|
242
|
+
segments:
|
243
|
+
- 0
|
244
|
+
version: "0"
|
245
|
+
requirements: []
|
246
|
+
|
247
|
+
rubyforge_project:
|
248
|
+
rubygems_version: 1.6.2
|
249
|
+
signing_key:
|
250
|
+
specification_version: 3
|
251
|
+
summary: for interacting with the Esendex API
|
252
|
+
test_files:
|
253
|
+
- test/helper.rb
|
254
|
+
- test/integration/test_account.rb
|
255
|
+
- test/test_account.rb
|
256
|
+
- test/test_message.rb
|
257
|
+
- test/test_message_batch.rb
|
258
|
+
- test/test_nokogiri.rb
|