esendex 0.4.0 → 0.5.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.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/esendex/application_controller.rb +4 -4
  3. data/app/controllers/esendex/inbound_messages_controller.rb +11 -11
  4. data/app/controllers/esendex/message_delivered_events_controller.rb +11 -11
  5. data/app/controllers/esendex/message_failed_events_controller.rb +11 -11
  6. data/app/controllers/esendex/push_notification_handler.rb +41 -41
  7. data/config/routes.rb +5 -5
  8. data/lib/esendex.rb +63 -62
  9. data/lib/esendex/account.rb +44 -44
  10. data/lib/esendex/api_connection.rb +29 -29
  11. data/lib/esendex/dispatcher_result.rb +25 -25
  12. data/lib/esendex/engine.rb +4 -4
  13. data/lib/esendex/exceptions.rb +25 -25
  14. data/lib/esendex/hash_serialisation.rb +23 -23
  15. data/lib/esendex/inbound_message.rb +30 -30
  16. data/lib/esendex/message.rb +38 -38
  17. data/lib/esendex/message_batch_submission.rb +50 -50
  18. data/lib/esendex/message_delivered_event.rb +29 -29
  19. data/lib/esendex/message_failed_event.rb +29 -29
  20. data/lib/esendex/railtie.rb +11 -11
  21. data/lib/esendex/version.rb +3 -3
  22. data/lib/esendex/voice_message.rb +25 -0
  23. data/lib/tasks/esendex.rake +29 -29
  24. data/licence.txt +23 -23
  25. data/readme.md +186 -186
  26. data/spec/account_spec.rb +211 -211
  27. data/spec/api_connection_spec.rb +78 -78
  28. data/spec/controllers/message_delivered_events_controller_spec.rb +29 -29
  29. data/spec/controllers/push_notification_handler_spec.rb +96 -96
  30. data/spec/dummy/README.rdoc +261 -261
  31. data/spec/dummy/Rakefile +7 -7
  32. data/spec/dummy/app/assets/javascripts/application.js +15 -15
  33. data/spec/dummy/app/assets/stylesheets/application.css +13 -13
  34. data/spec/dummy/app/controllers/application_controller.rb +3 -3
  35. data/spec/dummy/app/helpers/application_helper.rb +2 -2
  36. data/spec/dummy/app/views/layouts/application.html.erb +14 -14
  37. data/spec/dummy/config.ru +4 -4
  38. data/spec/dummy/config/application.rb +66 -66
  39. data/spec/dummy/config/boot.rb +9 -9
  40. data/spec/dummy/config/environment.rb +5 -5
  41. data/spec/dummy/config/environments/development.rb +37 -37
  42. data/spec/dummy/config/environments/production.rb +67 -67
  43. data/spec/dummy/config/environments/test.rb +39 -39
  44. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -7
  45. data/spec/dummy/config/initializers/inflections.rb +15 -15
  46. data/spec/dummy/config/initializers/mime_types.rb +5 -5
  47. data/spec/dummy/config/initializers/secret_token.rb +7 -7
  48. data/spec/dummy/config/initializers/session_store.rb +8 -8
  49. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
  50. data/spec/dummy/config/locales/en.yml +5 -5
  51. data/spec/dummy/config/routes.rb +4 -4
  52. data/spec/dummy/public/404.html +26 -26
  53. data/spec/dummy/public/422.html +26 -26
  54. data/spec/dummy/public/500.html +25 -25
  55. data/spec/dummy/script/rails +6 -6
  56. data/spec/hash_serialisation_spec.rb +52 -52
  57. data/spec/inbound_message_spec.rb +42 -42
  58. data/spec/message_batch_submission_spec.rb +54 -54
  59. data/spec/message_delivered_event_spec.rb +32 -32
  60. data/spec/message_failed_event_spec.rb +32 -32
  61. data/spec/message_spec.rb +49 -49
  62. data/spec/spec_helper.rb +41 -41
  63. data/spec/voice_message_spec.rb +29 -0
  64. metadata +12 -9
@@ -1,43 +1,43 @@
1
- require 'spec_helper'
2
-
3
- describe InboundMessage do
4
- describe ".from_xml" do
5
- let(:id) { random_string }
6
- let(:message_id) { random_string }
7
- let(:account_id) { random_string }
8
- let(:message_text) { random_string }
9
- let(:from) { random_mobile }
10
- let(:to) { random_mobile }
11
- let(:source) {
12
- "<InboundMessage>
13
- <Id>#{id}</Id>
14
- <MessageId>#{message_id}</MessageId>
15
- <AccountId>#{account_id}</AccountId>
16
- <MessageText>#{message_text}</MessageText>
17
- <From>#{from}</From>
18
- <To>#{to}</To>
19
- </InboundMessage>"
20
- }
21
-
22
- subject { InboundMessage.from_xml source }
23
-
24
- it "should set the id" do
25
- subject.id.should eq(id)
26
- end
27
- it "should set the message_id" do
28
- subject.message_id.should eq(message_id)
29
- end
30
- it "should set the account_id" do
31
- subject.account_id.should eq(account_id)
32
- end
33
- it "should set the message_text" do
34
- subject.message_text.should eq(message_text)
35
- end
36
- it "should set the from" do
37
- subject.from.should eq(from)
38
- end
39
- it "should set the to" do
40
- subject.to.should eq(to)
41
- end
42
- end
1
+ require 'spec_helper'
2
+
3
+ describe InboundMessage do
4
+ describe ".from_xml" do
5
+ let(:id) { random_string }
6
+ let(:message_id) { random_string }
7
+ let(:account_id) { random_string }
8
+ let(:message_text) { random_string }
9
+ let(:from) { random_mobile }
10
+ let(:to) { random_mobile }
11
+ let(:source) {
12
+ "<InboundMessage>
13
+ <Id>#{id}</Id>
14
+ <MessageId>#{message_id}</MessageId>
15
+ <AccountId>#{account_id}</AccountId>
16
+ <MessageText>#{message_text}</MessageText>
17
+ <From>#{from}</From>
18
+ <To>#{to}</To>
19
+ </InboundMessage>"
20
+ }
21
+
22
+ subject { InboundMessage.from_xml source }
23
+
24
+ it "should set the id" do
25
+ subject.id.should eq(id)
26
+ end
27
+ it "should set the message_id" do
28
+ subject.message_id.should eq(message_id)
29
+ end
30
+ it "should set the account_id" do
31
+ subject.account_id.should eq(account_id)
32
+ end
33
+ it "should set the message_text" do
34
+ subject.message_text.should eq(message_text)
35
+ end
36
+ it "should set the from" do
37
+ subject.from.should eq(from)
38
+ end
39
+ it "should set the to" do
40
+ subject.to.should eq(to)
41
+ end
42
+ end
43
43
  end
@@ -1,55 +1,55 @@
1
- require 'spec_helper'
2
-
3
- describe MessageBatchSubmission do
4
- let(:account) { "EX1234556" }
5
-
6
- describe "#xml_node" do
7
- let(:messages) { [ Message.new(random_mobile, random_string), Message.new(random_mobile, random_string)] }
8
- let(:message_batch) { MessageBatchSubmission.new(account, messages) }
9
-
10
- subject { message_batch.xml_node }
11
-
12
- it "creates message nodes" do
13
- subject.xpath('//messages/message').count.should eq(messages.count)
14
- end
15
-
16
- it "sets the message to" do
17
- (0..1).each do |i|
18
- subject.xpath('//messages/message/to')[i].content.should eq(messages[i].to)
19
- end
20
- end
21
-
22
- it "sets the message body" do
23
- (0..1).each do |i|
24
- subject.xpath('//messages/message/body')[i].content.should eq(messages[i].body)
25
- end
26
- end
27
-
28
- context "when #send_at set" do
29
- let(:target_time) { Time.local(2011, 4, 7, 15, 0, 0) }
30
-
31
- before(:each) do
32
- message_batch.send_at = target_time
33
- end
34
-
35
- it "creates a properly formatted sendat node" do
36
- subject.at_xpath('//messages/sendat').content.should eq("2011-04-07T15:00:00")
37
- end
38
- end
39
- end
40
-
41
- describe "#initialize" do
42
- context "with nil account reference" do
43
- it "raises AccountReferenceError" do
44
- messages = [Message.new(random_mobile, random_string)]
45
- expect { MessageBatchSubmission.new nil, messages }.to raise_error(AccountReferenceError)
46
- end
47
- end
48
-
49
- context "with empty message array" do
50
- it "raises expected error" do
51
- expect { MessageBatchSubmission.new account, [] }.to raise_error("Need at least one message")
52
- end
53
- end
54
- end
1
+ require 'spec_helper'
2
+
3
+ describe MessageBatchSubmission do
4
+ let(:account) { "EX1234556" }
5
+
6
+ describe "#xml_node" do
7
+ let(:messages) { [ Message.new(random_mobile, random_string), Message.new(random_mobile, random_string)] }
8
+ let(:message_batch) { MessageBatchSubmission.new(account, messages) }
9
+
10
+ subject { message_batch.xml_node }
11
+
12
+ it "creates message nodes" do
13
+ subject.xpath('//messages/message').count.should eq(messages.count)
14
+ end
15
+
16
+ it "sets the message to" do
17
+ (0..1).each do |i|
18
+ subject.xpath('//messages/message/to')[i].content.should eq(messages[i].to)
19
+ end
20
+ end
21
+
22
+ it "sets the message body" do
23
+ (0..1).each do |i|
24
+ subject.xpath('//messages/message/body')[i].content.should eq(messages[i].body)
25
+ end
26
+ end
27
+
28
+ context "when #send_at set" do
29
+ let(:target_time) { Time.local(2011, 4, 7, 15, 0, 0) }
30
+
31
+ before(:each) do
32
+ message_batch.send_at = target_time
33
+ end
34
+
35
+ it "creates a properly formatted sendat node" do
36
+ subject.at_xpath('//messages/sendat').content.should eq("2011-04-07T15:00:00")
37
+ end
38
+ end
39
+ end
40
+
41
+ describe "#initialize" do
42
+ context "with nil account reference" do
43
+ it "raises AccountReferenceError" do
44
+ messages = [Message.new(random_mobile, random_string)]
45
+ expect { MessageBatchSubmission.new nil, messages }.to raise_error(AccountReferenceError)
46
+ end
47
+ end
48
+
49
+ context "with empty message array" do
50
+ it "raises expected error" do
51
+ expect { MessageBatchSubmission.new account, [] }.to raise_error("Need at least one message")
52
+ end
53
+ end
54
+ end
55
55
  end
@@ -1,33 +1,33 @@
1
- require 'spec_helper'
2
-
3
- describe MessageDeliveredEvent do
4
- describe ".from_xml" do
5
- let(:id) { random_string }
6
- let(:message_id) { random_string }
7
- let(:account_id) { random_string }
8
- let(:occurred_at) { random_time.utc }
9
- let(:source) {
10
- "<MessageDelivered>
11
- <Id>#{id}</Id>
12
- <MessageId>#{message_id}</MessageId>
13
- <AccountId>#{account_id}</AccountId>
14
- <OccurredAt>#{occurred_at.strftime("%Y-%m-%dT%H:%M:%S")}</OccurredAt>
15
- </MessageDelivered>"
16
- }
17
-
18
- subject { MessageDeliveredEvent.from_xml source }
19
-
20
- it "should set the id" do
21
- subject.id.should eq(id)
22
- end
23
- it "should set the message_id" do
24
- subject.message_id.should eq(message_id)
25
- end
26
- it "should set the account_id" do
27
- subject.account_id.should eq(account_id)
28
- end
29
- it "should set the occurred_at" do
30
- subject.occurred_at.to_i.should eq(occurred_at.to_i)
31
- end
32
- end
1
+ require 'spec_helper'
2
+
3
+ describe MessageDeliveredEvent do
4
+ describe ".from_xml" do
5
+ let(:id) { random_string }
6
+ let(:message_id) { random_string }
7
+ let(:account_id) { random_string }
8
+ let(:occurred_at) { random_time.utc }
9
+ let(:source) {
10
+ "<MessageDelivered>
11
+ <Id>#{id}</Id>
12
+ <MessageId>#{message_id}</MessageId>
13
+ <AccountId>#{account_id}</AccountId>
14
+ <OccurredAt>#{occurred_at.strftime("%Y-%m-%dT%H:%M:%S")}</OccurredAt>
15
+ </MessageDelivered>"
16
+ }
17
+
18
+ subject { MessageDeliveredEvent.from_xml source }
19
+
20
+ it "should set the id" do
21
+ subject.id.should eq(id)
22
+ end
23
+ it "should set the message_id" do
24
+ subject.message_id.should eq(message_id)
25
+ end
26
+ it "should set the account_id" do
27
+ subject.account_id.should eq(account_id)
28
+ end
29
+ it "should set the occurred_at" do
30
+ subject.occurred_at.to_i.should eq(occurred_at.to_i)
31
+ end
32
+ end
33
33
  end
@@ -1,33 +1,33 @@
1
- require 'spec_helper'
2
-
3
- describe MessageFailedEvent do
4
- describe ".from_xml" do
5
- let(:id) { random_string }
6
- let(:message_id) { random_string }
7
- let(:account_id) { random_string }
8
- let(:occurred_at) { random_time.utc }
9
- let(:source) {
10
- "<MessageFailed>
11
- <Id>#{id}</Id>
12
- <MessageId>#{message_id}</MessageId>
13
- <AccountId>#{account_id}</AccountId>
14
- <OccurredAt>#{occurred_at.strftime("%Y-%m-%dT%H:%M:%S")}</OccurredAt>
15
- </MessageFailed>"
16
- }
17
-
18
- subject { MessageFailedEvent.from_xml source }
19
-
20
- it "should set the id" do
21
- subject.id.should eq(id)
22
- end
23
- it "should set the message_id" do
24
- subject.message_id.should eq(message_id)
25
- end
26
- it "should set the account_id" do
27
- subject.account_id.should eq(account_id)
28
- end
29
- it "should set the occurred_at" do
30
- subject.occurred_at.to_i.should eq(occurred_at.to_i)
31
- end
32
- end
1
+ require 'spec_helper'
2
+
3
+ describe MessageFailedEvent do
4
+ describe ".from_xml" do
5
+ let(:id) { random_string }
6
+ let(:message_id) { random_string }
7
+ let(:account_id) { random_string }
8
+ let(:occurred_at) { random_time.utc }
9
+ let(:source) {
10
+ "<MessageFailed>
11
+ <Id>#{id}</Id>
12
+ <MessageId>#{message_id}</MessageId>
13
+ <AccountId>#{account_id}</AccountId>
14
+ <OccurredAt>#{occurred_at.strftime("%Y-%m-%dT%H:%M:%S")}</OccurredAt>
15
+ </MessageFailed>"
16
+ }
17
+
18
+ subject { MessageFailedEvent.from_xml source }
19
+
20
+ it "should set the id" do
21
+ subject.id.should eq(id)
22
+ end
23
+ it "should set the message_id" do
24
+ subject.message_id.should eq(message_id)
25
+ end
26
+ it "should set the account_id" do
27
+ subject.account_id.should eq(account_id)
28
+ end
29
+ it "should set the occurred_at" do
30
+ subject.occurred_at.to_i.should eq(occurred_at.to_i)
31
+ end
32
+ end
33
33
  end
@@ -1,49 +1,49 @@
1
- require 'spec_helper'
2
-
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
-
23
- describe "#xml_node" do
24
- let(:to) { random_mobile }
25
- let(:body) { random_string }
26
- let(:message) { Esendex::Message.new(to, body) }
27
-
28
- subject { message.xml_node }
29
-
30
- it "contains a to node" do
31
- subject.at_xpath('//message/to').content.should eq(to)
32
- end
33
- it "contains a body node" do
34
- subject.at_xpath('//message/body').content.should eq(body)
35
- end
36
-
37
- context "when #from set" do
38
- let(:from) { random_string }
39
-
40
- before(:each) do
41
- message.from = from
42
- end
43
-
44
- it "contains a from node" do
45
- subject.at_xpath('//message/from').content.should eq(from)
46
- end
47
- end
48
- end
49
- end
1
+ require 'spec_helper'
2
+
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
+
23
+ describe "#xml_node" do
24
+ let(:to) { random_mobile }
25
+ let(:body) { random_string }
26
+ let(:message) { Esendex::Message.new(to, body) }
27
+
28
+ subject { message.xml_node }
29
+
30
+ it "contains a to node" do
31
+ subject.at_xpath('//message/to').content.should eq(to)
32
+ end
33
+ it "contains a body node" do
34
+ subject.at_xpath('//message/body').content.should eq(body)
35
+ end
36
+
37
+ context "when #from set" do
38
+ let(:from) { random_string }
39
+
40
+ before(:each) do
41
+ message.from = from
42
+ end
43
+
44
+ it "contains a from node" do
45
+ subject.at_xpath('//message/from').content.should eq(from)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,41 +1,41 @@
1
- require 'rake'
2
- require 'rspec'
3
-
4
- # Configure Rails Environment
5
- ENV["RAILS_ENV"] = "test"
6
-
7
- require File.expand_path("../dummy/config/environment.rb", __FILE__)
8
- require 'rspec/rails'
9
-
10
- Rails.backtrace_cleaner.remove_silencers!
11
-
12
- require_relative "../lib/esendex"
13
- include Esendex
14
-
15
- RSpec.configure do |config|
16
- config.color = true
17
- end
18
-
19
- def random_string
20
- (0...24).map{ ('a'..'z').to_a[rand(26)] }.join
21
- end
22
-
23
- def random_email
24
- "#{random_string}@#{random_string}.com"
25
- end
26
-
27
- def random_integer
28
- rand(9999)
29
- end
30
-
31
- def random_mobile
32
- "447#{"%09d" % rand(999999999)}"
33
- end
34
-
35
- def random_time
36
- Time.now + rand(9999)
37
- end
38
-
39
- def random_guid
40
- SecureRandom.uuid
41
- end
1
+ require 'rake'
2
+ require 'rspec'
3
+
4
+ # Configure Rails Environment
5
+ ENV["RAILS_ENV"] = "test"
6
+
7
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
8
+ require 'rspec/rails'
9
+
10
+ Rails.backtrace_cleaner.remove_silencers!
11
+
12
+ require_relative "../lib/esendex"
13
+ include Esendex
14
+
15
+ RSpec.configure do |config|
16
+ config.color = true
17
+ end
18
+
19
+ def random_string
20
+ (0...24).map{ ('a'..'z').to_a[rand(26)] }.join
21
+ end
22
+
23
+ def random_email
24
+ "#{random_string}@#{random_string}.com"
25
+ end
26
+
27
+ def random_integer
28
+ rand(9999)
29
+ end
30
+
31
+ def random_mobile
32
+ "447#{"%09d" % rand(999999999)}"
33
+ end
34
+
35
+ def random_time
36
+ Time.now + rand(9999)
37
+ end
38
+
39
+ def random_guid
40
+ SecureRandom.uuid
41
+ end