esendex 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/esendex/account.rb +4 -3
- data/lib/esendex/api_connection.rb +2 -2
- data/lib/esendex/exceptions.rb +3 -0
- data/lib/esendex/message.rb +1 -2
- data/lib/esendex/railtie.rb +1 -1
- data/lib/esendex/version.rb +1 -1
- data/spec/account_spec.rb +16 -6
- data/spec/message_spec.rb +19 -0
- data/tasks/esendex.rake +29 -0
- metadata +38 -6
data/lib/esendex/account.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'nestful'
|
2
1
|
require 'nokogiri'
|
3
2
|
|
4
3
|
module Esendex
|
@@ -14,9 +13,11 @@ module Esendex
|
|
14
13
|
end
|
15
14
|
|
16
15
|
def messages_remaining
|
17
|
-
response = api_connection.get "/v1.0/accounts
|
16
|
+
response = api_connection.get "/v1.0/accounts"
|
18
17
|
doc = Nokogiri::XML(response.body)
|
19
|
-
|
18
|
+
node = doc.at_xpath("//api:account[api:reference='#{@reference}']/api:messagesremaining", 'api' => Esendex::API_NAMESPACE)
|
19
|
+
raise AccountReferenceError.new() if node.nil?
|
20
|
+
node.content.to_i
|
20
21
|
end
|
21
22
|
|
22
23
|
def send_message(args={})
|
@@ -16,13 +16,13 @@ class ApiConnection
|
|
16
16
|
def get(url)
|
17
17
|
@connection.get url, default_headers
|
18
18
|
rescue => e
|
19
|
-
raise ApiErrorFactory.new.get_api_error(e)
|
19
|
+
raise Esendex::ApiErrorFactory.new.get_api_error(e)
|
20
20
|
end
|
21
21
|
|
22
22
|
def post(url, body)
|
23
23
|
@connection.post url, body, default_headers
|
24
24
|
rescue => e
|
25
|
-
raise ApiErrorFactory.new.get_api_error(e)
|
25
|
+
raise Esendex::ApiErrorFactory.new.get_api_error(e)
|
26
26
|
end
|
27
27
|
|
28
28
|
end
|
data/lib/esendex/exceptions.rb
CHANGED
data/lib/esendex/message.rb
CHANGED
data/lib/esendex/railtie.rb
CHANGED
data/lib/esendex/version.rb
CHANGED
data/spec/account_spec.rb
CHANGED
@@ -6,13 +6,13 @@ describe Account do
|
|
6
6
|
let(:messages_remaining) { random_integer }
|
7
7
|
let(:account_xml) {
|
8
8
|
"<?xml version=\"1.0\" encoding=\"utf-8\"?>
|
9
|
-
<accounts>
|
9
|
+
<accounts xmlns=\"http://api.esendex.com/ns/\">
|
10
10
|
<account id=\"2b4a326c-41de-4a57-a577-c7d742dc145c\" uri=\"http://api.esendex.com/v1.0/accounts/2b4a326c-41de-4a57-a577-c7d742dc145c\">
|
11
11
|
<balanceremaining domesticmessages=\"100\" internationalmessages=\"100\">$0.00</balanceremaining>
|
12
|
-
<reference
|
12
|
+
<reference>not this one</reference>
|
13
13
|
<address>447786204254</address>
|
14
14
|
<type>Professional</type>
|
15
|
-
<messagesremaining
|
15
|
+
<messagesremaining>1234</messagesremaining>
|
16
16
|
<expireson>2015-12-31T00:00:00</expireson>
|
17
17
|
<role>PowerUser</role>
|
18
18
|
<defaultdialcode>44</defaultdialcode>
|
@@ -34,7 +34,7 @@ describe Account do
|
|
34
34
|
let(:api_connection) { mock("Connection", :get => mock('Response', :body => account_xml), :post => true )}
|
35
35
|
|
36
36
|
before(:each) do
|
37
|
-
account.stub(:api_connection) { api_connection}
|
37
|
+
account.stub(:api_connection) { api_connection }
|
38
38
|
end
|
39
39
|
|
40
40
|
describe "#messages_remaining" do
|
@@ -42,13 +42,23 @@ describe Account do
|
|
42
42
|
subject { account.messages_remaining }
|
43
43
|
|
44
44
|
it "should get the account resource" do
|
45
|
-
api_connection.should_receive(:get).with("/v1.0/accounts
|
45
|
+
api_connection.should_receive(:get).with("/v1.0/accounts")
|
46
46
|
subject
|
47
47
|
end
|
48
|
-
it "should get the messages remaining from the
|
48
|
+
it "should get the messages remaining from the document" do
|
49
49
|
subject.should eq(messages_remaining)
|
50
50
|
end
|
51
51
|
end
|
52
|
+
|
53
|
+
describe "#messages_remaining_invalid_reference" do
|
54
|
+
before(:each) do
|
55
|
+
account.reference = "invalid"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should raise AccountReferenceError" do
|
59
|
+
expect { account.messages_remaining }.to raise_error(AccountReferenceError)
|
60
|
+
end
|
61
|
+
end
|
52
62
|
|
53
63
|
describe "#send_message" do
|
54
64
|
let(:batch_id) { random_string }
|
data/spec/message_spec.rb
CHANGED
@@ -1,6 +1,25 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Message do
|
4
|
+
describe "#initialize" do
|
5
|
+
let(:to) { random_mobile }
|
6
|
+
let(:from) { random_mobile }
|
7
|
+
let(:body) { random_string }
|
8
|
+
let(:message) { Esendex::Message.new(to, body, from) }
|
9
|
+
|
10
|
+
it "should have to set" do
|
11
|
+
message.to.should eq(to)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should have from set" do
|
15
|
+
message.from.should eq(from)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should have body set" do
|
19
|
+
message.body.should eq(body)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
4
23
|
describe "#xml_node" do
|
5
24
|
let(:to) { random_mobile }
|
6
25
|
let(:body) { random_string }
|
data/tasks/esendex.rake
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative '../lib/esendex'
|
2
|
+
include Esendex
|
3
|
+
|
4
|
+
namespace :esendex do
|
5
|
+
task :validate, [:username, :password, :account_reference] do |t, args|
|
6
|
+
begin
|
7
|
+
Esendex.configure do |config|
|
8
|
+
config.username = args.username
|
9
|
+
config.password = args.password
|
10
|
+
config.account_reference = args.account_reference
|
11
|
+
end
|
12
|
+
account = Account.new
|
13
|
+
messages_remaining = account.messages_remaining
|
14
|
+
puts "Validated user #{Esendex.username} on account #{account.reference}. #{messages_remaining} messages remaining"
|
15
|
+
rescue => e
|
16
|
+
puts "Failed to validate credentials #{e.message}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
task :send_message, [:to, :body, :from] do |t, args|
|
21
|
+
begin
|
22
|
+
account = Account.new
|
23
|
+
batch_id = account.send_message(args)
|
24
|
+
puts "Message sent to #{args.to}. Batch ID: #{batch_id}"
|
25
|
+
rescue => e
|
26
|
+
puts "Failed to send message #{e.message}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: esendex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,9 +9,41 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
13
|
-
dependencies:
|
14
|
-
|
12
|
+
date: 2013-02-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nestful
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.0.6
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.0.6
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: nokogiri
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.4.4.1
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.4.4.1
|
46
|
+
description: Send SMS from you application using the Esendex API
|
15
47
|
email:
|
16
48
|
- support@esendex.com
|
17
49
|
executables: []
|
@@ -28,6 +60,7 @@ files:
|
|
28
60
|
- lib/esendex/railtie.rb
|
29
61
|
- lib/esendex/version.rb
|
30
62
|
- lib/esendex.rb
|
63
|
+
- tasks/esendex.rake
|
31
64
|
- LICENSE.txt
|
32
65
|
- readme.md
|
33
66
|
- spec/account_spec.rb
|
@@ -35,7 +68,7 @@ files:
|
|
35
68
|
- spec/message_batch_submission_spec.rb
|
36
69
|
- spec/message_spec.rb
|
37
70
|
- spec/spec_helper.rb
|
38
|
-
homepage: http://
|
71
|
+
homepage: http://developers.esendex.com
|
39
72
|
licenses: []
|
40
73
|
post_install_message:
|
41
74
|
rdoc_options: []
|
@@ -65,4 +98,3 @@ test_files:
|
|
65
98
|
- spec/message_batch_submission_spec.rb
|
66
99
|
- spec/message_spec.rb
|
67
100
|
- spec/spec_helper.rb
|
68
|
-
has_rdoc:
|