xednese 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0655d51c18e3166feda964a5401798ec46d59900
4
+ data.tar.gz: 31a7d981298f71cf23da411388eb4920aa5291b4
5
+ SHA512:
6
+ metadata.gz: 28015566c69de2d862a79ecff04434badaa1ae2e354ce1dddfbf9b1c28f9b2c3ac37152663879285f78db37b5c1aafb72bdae7c75d01120372fc0a59be59acbc
7
+ data.tar.gz: afa21575f1230639c5a5da75808081638568d8d8b8dc67ac1b886de9567b3179ec07e635fcd1ad412816a3a1f250ebea9ad7e0b8e980727474f480e867143c13
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'seq', '~> 0.2.0'
4
+ gem 'serialisable', '~> 0.0.0'
5
+ gem 'nokogiri', '~> 1.6'
6
+
7
+ gem 'rake', '~> 10.1'
8
+ gem 'minitest', '~> 5.2'
9
+ gem 'mocha', '~> 1.0'
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2014 Joshua Hawxwell
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # Xednese
2
+
3
+ ``` ruby
4
+ require 'xednese'
5
+
6
+ esendex = Esendex.new('me@company.com', 'password', 'account reference')
7
+ p esendex.messages.sent.first.body
8
+ #=> "..."
9
+
10
+ response = esendex.dispatcher.send('Hey guys', '445275XXX')
11
+ p response.message_headers.map(&:id)
12
+ #=> ["..."]
13
+ ```
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new(:test) do |t|
4
+ t.libs << 'lib' << 'spec'
5
+ t.pattern = 'spec/**/*_spec.rb'
6
+ t.verbose = true
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,25 @@
1
+ class Esendex
2
+ class Accounts
3
+ def initialize(credentials)
4
+ @credentials = credentials
5
+ end
6
+
7
+ def reference
8
+ @credentials.account_reference
9
+ end
10
+
11
+ def each(&block)
12
+ Client.get(@credentials, 'v1.0/accounts') {|status, data|
13
+ Responses::Accounts.deserialise(data).accounts
14
+ }.each(&block)
15
+ end
16
+
17
+ include Enumerable
18
+
19
+ def get(id)
20
+ Client.get(@credentials, "v1.0/accounts/#{id}") do |status, data|
21
+ Responses::Account.deserialise(data)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,48 @@
1
+ class Esendex
2
+ class Client
3
+ ROOT = URI('https://api.esendex.com/')
4
+ USER_AGENT = "ruby/xednese-#{VERSION}"
5
+ CONTENT_TYPE = "application/xml"
6
+
7
+ def self.get(credentials, path, args={})
8
+ uri = url(path)
9
+ uri.query = URI.encode_www_form(args)
10
+ request = Net::HTTP::Get.new(uri)
11
+
12
+ code, body = execute(credentials, request)
13
+
14
+ block_given? ? yield(code, body) : [code, body]
15
+ end
16
+
17
+ def self.post(credentials, path, object)
18
+ request = Net::HTTP::Post.new(url(path))
19
+ request.body = object.serialise
20
+ request.content_type = CONTENT_TYPE
21
+
22
+ code, body = execute(credentials, request)
23
+
24
+ block_given? ? yield(code, body) : [code, body]
25
+ end
26
+
27
+ private
28
+
29
+ def self.url(path)
30
+ URI.join(ROOT.to_s, path)
31
+ end
32
+
33
+ def self.execute(credentials, request)
34
+ request["User-Agent"] = USER_AGENT
35
+ request.basic_auth credentials.username, credentials.password
36
+
37
+ code, body = nil, nil
38
+
39
+ Net::HTTP.start(ROOT.host, ROOT.port, use_ssl: true) do |http|
40
+ resp = http.request(request)
41
+ code = resp.code
42
+ body = resp.body
43
+ end
44
+
45
+ [code, body]
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,20 @@
1
+ class Esendex
2
+ class Dispatcher
3
+ def initialize(credentials)
4
+ @credentials = credentials
5
+ end
6
+
7
+ def send(body, to)
8
+ args = {
9
+ account_reference: @credentials.account_reference,
10
+ messages: [{to: to, body: body}]
11
+ }
12
+
13
+ messages = Requests::Messages.new(args)
14
+
15
+ Client.post(@credentials, 'v1.0/messagedispatcher', messages) do |code, body|
16
+ Responses::MessageDispatcherHeaders.deserialise(body)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ class Esendex
2
+ class Messages
3
+ PAGE_COUNT = 25
4
+
5
+ def initialize(credentials)
6
+ @credentials = credentials
7
+ end
8
+
9
+ def sent
10
+ Seq::Paged.new do |page|
11
+ params = {
12
+ startIndex: PAGE_COUNT * page,
13
+ count: PAGE_COUNT
14
+ }
15
+
16
+ Client.get(@credentials, 'v1.0/messageheaders', params) do |status, data|
17
+ Responses::MessageHeaders.deserialise(data).messageheaders
18
+ end
19
+ end
20
+ end
21
+
22
+ def get(id)
23
+ Client.get(@credentials, "v1.0/messageheaders/#{id}") do |status, data|
24
+ Responses::MessageHeader.deserialise(data)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ class Esendex
2
+ module Requests
3
+ class Messages
4
+ def initialize(args)
5
+ @args = args
6
+ end
7
+
8
+ def serialise
9
+ Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
10
+ xml.messages {
11
+ xml.accountreference @args[:account_reference]
12
+
13
+ @args[:messages].each do |message|
14
+ xml.message {
15
+ xml.to message[:to]
16
+ xml.body message[:body]
17
+ }
18
+ end
19
+ }
20
+ end.to_xml
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ class Esendex
2
+ module Responses
3
+ class Account
4
+ extend Serialisable
5
+
6
+ root 'account'
7
+
8
+ attribute :id, 'id'
9
+ attribute :uri, 'uri'
10
+
11
+ element :reference, 'reference'
12
+ element :label, 'label'
13
+ element :address, 'address'
14
+ element :type, 'type'
15
+ element :messages_remaining, 'messagesremaining', Parser.for(&:to_i)
16
+ element :expires_on, 'expireson'
17
+ element :role, 'role'
18
+ element :settings, Class.new {
19
+ extend Serialisable
20
+ root 'settings'
21
+ attribute :uri, 'uri'
22
+ }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,10 @@
1
+ class Esendex
2
+ module Responses
3
+ class Accounts
4
+ extend Serialisable
5
+
6
+ root 'accounts'
7
+ elements :accounts, Account
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ class Esendex
2
+ module Responses
3
+ class MessageDispatcherHeaders
4
+ extend Serialisable
5
+
6
+ root 'messageheaders'
7
+
8
+ attribute :batch_id, 'batchid'
9
+ elements :message_headers, Class.new {
10
+ extend Serialisable
11
+
12
+ root 'messageheader'
13
+ attribute :uri, 'uri'
14
+ attribute :id, 'id'
15
+ }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,33 @@
1
+ class Esendex
2
+ module Responses
3
+ class MessageHeader
4
+ extend Serialisable
5
+
6
+ root 'messageheader'
7
+
8
+ attribute :id, 'id'
9
+ attribute :uri, 'uri'
10
+
11
+ element :status, 'status'
12
+ element :last_status_at, 'laststatusat', Time
13
+ element :submitted_at, 'submittedat', Time
14
+ element :type, 'type'
15
+ element :to, Class.new { extend Serialisable
16
+ root 'to'
17
+ element :phonenumber, 'phonenumber'
18
+ }
19
+ element :from, Class.new { extend Serialisable
20
+ root 'from'
21
+ element :phonenumber, 'phonenumber'
22
+ }
23
+ element :summary, 'summary'
24
+ element :body, Class.new { extend Serialisable
25
+ root 'body'
26
+ attribute :uri, 'uri'
27
+ }
28
+ element :direction, 'direction'
29
+ element :parts, 'parts', Parser.for(&:to_i)
30
+ element :username, 'username'
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ class Esendex
2
+ module Responses
3
+ class MessageHeaders
4
+ extend Serialisable
5
+
6
+ root 'messageheaders'
7
+
8
+ attribute :start_index, 'startindex', Parser.for(&:to_i)
9
+ attribute :count, 'count', Parser.for(&:to_i)
10
+ attribute :total_count, 'totalcount', Parser.for(&:to_i)
11
+
12
+ elements :message_headers, MessageHeader
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ class Esendex
2
+ module Responses
3
+ module Parser
4
+ def self.for(&block)
5
+ Class.new.tap {|klass|
6
+ klass.singleton_class.send(:define_method, :parse) {|s| block.call(s) }
7
+ }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ class Esendex
2
+ class Users
3
+ def initialize(credentials)
4
+ @credentials = credentials
5
+ end
6
+
7
+ def username
8
+ @credentials.username
9
+ end
10
+
11
+ def password
12
+ @credentials.password
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ class Esendex
2
+ VERSION = '0.0.0'
3
+ end
data/lib/xednese.rb ADDED
@@ -0,0 +1,46 @@
1
+ require 'net/http'
2
+ require 'nokogiri'
3
+ require 'seq/paged'
4
+ require 'serialisable'
5
+ require 'time'
6
+
7
+ require_relative 'xednese/version'
8
+ require_relative 'xednese/client'
9
+
10
+ require_relative 'xednese/requests/messages'
11
+
12
+ require_relative 'xednese/responses/parser'
13
+ require_relative 'xednese/responses/account'
14
+ require_relative 'xednese/responses/accounts'
15
+ require_relative 'xednese/responses/message_dispatcher_headers'
16
+ require_relative 'xednese/responses/message_header'
17
+ require_relative 'xednese/responses/message_headers'
18
+
19
+ require_relative 'xednese/accounts'
20
+ require_relative 'xednese/dispatcher'
21
+ require_relative 'xednese/messages'
22
+ require_relative 'xednese/users'
23
+
24
+ class Esendex
25
+ Credentials = Struct.new(:username, :password, :account_reference)
26
+
27
+ def initialize(username, password, account_reference)
28
+ @credentials = Credentials.new(username, password, account_reference)
29
+ end
30
+
31
+ def account
32
+ Accounts.new(@credentials)
33
+ end
34
+
35
+ def dispatcher
36
+ Dispatcher.new(@credentials)
37
+ end
38
+
39
+ def user
40
+ Users.new(@credentials)
41
+ end
42
+
43
+ def messages
44
+ Messages.new(@credentials)
45
+ end
46
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require 'mocha/mini_test'
4
+
5
+ require_relative '../lib/xednese'
6
+
7
+ def dummy_esendex
8
+ Esendex.new('what', 'when', 'really?')
9
+ end
10
+
11
+ def dummy_credentials
12
+ Esendex::Credentials.new('user', 'pass', 'what?')
13
+ end
@@ -0,0 +1,67 @@
1
+ require_relative '../helper'
2
+
3
+ describe Esendex::Accounts do
4
+ let(:credentials) { Esendex::Credentials.new('user', 'pass', 'ref') }
5
+ subject { Esendex::Accounts.new(credentials) }
6
+
7
+ describe '#reference' do
8
+ it 'returns the account reference' do
9
+ subject.reference.must_equal credentials.account_reference
10
+ end
11
+ end
12
+
13
+ describe '#each' do
14
+ let(:data) { mock }
15
+ let(:account_list) { [mock, mock] }
16
+ let(:accounts) { stub(accounts: account_list) }
17
+
18
+ before {
19
+ Esendex::Client
20
+ .expects(:get)
21
+ .with(credentials, 'v1.0/accounts')
22
+ .yields(200, data)
23
+ .returns(account_list)
24
+
25
+ Esendex::Responses::Accounts
26
+ .expects(:deserialise)
27
+ .with(data)
28
+ .returns(accounts)
29
+
30
+ accounts
31
+ .expects(:accounts)
32
+ .returns(account_list)
33
+ }
34
+
35
+ it 'retrieves all accounts' do
36
+ returned_accounts = []
37
+ subject.each do |account|
38
+ returned_accounts << account
39
+ end
40
+
41
+ returned_accounts.must_equal account_list
42
+ end
43
+ end
44
+
45
+ describe '#get' do
46
+ let(:id) { "heyohid" }
47
+ let(:data) { mock }
48
+ let(:account) { mock }
49
+
50
+ before {
51
+ Esendex::Client
52
+ .expects(:get)
53
+ .with(credentials, "v1.0/accounts/#{id}")
54
+ .yields(200, data)
55
+ .returns(account)
56
+
57
+ Esendex::Responses::Account
58
+ .expects(:deserialise)
59
+ .with(data)
60
+ .returns(account)
61
+ }
62
+
63
+ it 'retrieves the specified accounts' do
64
+ subject.get(id).must_equal account
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,130 @@
1
+ require_relative '../helper'
2
+
3
+ describe Esendex::Client do
4
+ subject { Esendex::Client }
5
+
6
+ describe '.get' do
7
+ let(:credentials) { dummy_credentials }
8
+ let(:path) { "some/url/path" }
9
+ let(:args) { { query: "what", thing: "yep" } }
10
+
11
+ let(:expected_code) { 418 }
12
+ let(:expected_body) { "Hi I'm a body" }
13
+
14
+ let(:uri) { mock }
15
+ let(:form_params) { mock }
16
+ let(:http) { mock }
17
+ let(:get_request) { mock }
18
+
19
+ before {
20
+ URI.expects(:encode_www_form).with(args).returns(form_params)
21
+ uri.expects(:query=).with(form_params)
22
+ subject.expects(:url).with(path).returns(uri)
23
+
24
+ subject
25
+ .expects(:execute)
26
+ .with(credentials, get_request)
27
+ .returns([expected_code, expected_body])
28
+
29
+ Net::HTTP::Get.expects(:new).with(uri).returns(get_request)
30
+ }
31
+
32
+ it 'returns the expected status code' do
33
+ code, _ = subject.get(credentials, path, args)
34
+ code.must_equal expected_code
35
+ end
36
+
37
+ it 'returns the expected body' do
38
+ _, body = subject.get(credentials, path, args)
39
+ body.must_equal expected_body
40
+ end
41
+ end
42
+
43
+ describe '.post' do
44
+ let(:credentials) { dummy_credentials }
45
+
46
+ let(:path) { "some/url/path?query=yah" }
47
+
48
+ let(:expected_code) { 418 }
49
+ let(:expected_body) { "Hi I'm a body" }
50
+
51
+ let(:xml) { "</xml>" }
52
+ let(:serialisable_object) { stub(serialise: xml) }
53
+ let(:post_request) { mock }
54
+
55
+ before {
56
+ subject
57
+ .expects(:execute)
58
+ .with(credentials, post_request)
59
+ .returns([expected_code, expected_body])
60
+
61
+ Net::HTTP::Post
62
+ .expects(:new)
63
+ .with(subject::ROOT + path)
64
+ .returns(post_request)
65
+
66
+ post_request
67
+ .expects(:body=)
68
+ .with(xml)
69
+
70
+ post_request
71
+ .expects(:content_type=)
72
+ .with('application/xml')
73
+ }
74
+
75
+ it 'returns the expected status code' do
76
+ code, _ = subject.post(credentials, path, serialisable_object)
77
+ code.must_equal expected_code
78
+ end
79
+
80
+ it 'returns the expected body' do
81
+ _, body = subject.post(credentials, path, serialisable_object)
82
+ body.must_equal expected_body
83
+ end
84
+ end
85
+
86
+
87
+ describe '.execute' do
88
+ let(:username) { 'myusername' }
89
+ let(:password) { 'mypassword' }
90
+ let(:credentials) { Esendex::Credentials.new(username, password, 'EX00') }
91
+
92
+ let(:expected_code) { 418 }
93
+ let(:expected_body) { "Hi I'm a body" }
94
+
95
+ let(:http) { mock }
96
+ let(:request) { mock }
97
+ let(:response) { stub(body: expected_body, code: expected_code) }
98
+
99
+ before {
100
+ Net::HTTP
101
+ .expects(:start)
102
+ .with(subject::ROOT.host, subject::ROOT.port, use_ssl: true)
103
+ .yields(http)
104
+ .returns(expected_code, expected_body)
105
+
106
+ request
107
+ .expects(:[]=)
108
+ .with("User-Agent", subject::USER_AGENT)
109
+
110
+ request
111
+ .expects(:basic_auth)
112
+ .with(username, password)
113
+
114
+ http
115
+ .expects(:request)
116
+ .with(request)
117
+ .returns(response)
118
+ }
119
+
120
+ it 'returns the expected status code' do
121
+ code, _ = subject.send(:execute, credentials, request)
122
+ code.must_equal expected_code
123
+ end
124
+
125
+ it 'returns the expected body' do
126
+ _, body = subject.send(:execute, credentials, request)
127
+ body.must_equal expected_body
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,41 @@
1
+ require_relative '../helper'
2
+
3
+ describe Esendex::Dispatcher do
4
+ let(:credentials) { dummy_credentials }
5
+ subject { Esendex::Dispatcher.new(credentials) }
6
+
7
+ describe '.send' do
8
+ let(:body) { 'Hey I am message' }
9
+ let(:to) { '44123456789' }
10
+ let(:messages) { mock }
11
+ let(:response_xml) { mock }
12
+ let(:response_message_headers) { mock }
13
+
14
+ before {
15
+ args = {
16
+ account_reference: credentials.account_reference,
17
+ messages: [{ to: to, body: body }]
18
+ }
19
+
20
+ Esendex::Requests::Messages
21
+ .expects(:new)
22
+ .with(args)
23
+ .returns(messages)
24
+
25
+ Esendex::Responses::MessageDispatcherHeaders
26
+ .expects(:deserialise)
27
+ .with(response_xml)
28
+ .returns(response_message_headers)
29
+
30
+ Esendex::Client
31
+ .expects(:post)
32
+ .with(credentials, 'v1.0/messagedispatcher', messages)
33
+ .yields(200, response_xml)
34
+ .returns(response_message_headers)
35
+ }
36
+
37
+ it 'sends a single message' do
38
+ subject.send(body, to).must_equal response_message_headers
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,54 @@
1
+ require_relative '../helper'
2
+
3
+ describe Esendex::Messages do
4
+ subject { dummy_esendex }
5
+ let(:credentials) { subject.instance_variable_get(:@credentials) }
6
+
7
+ describe '#sent' do
8
+ let(:xml) { "Hey I'm xml" }
9
+ let(:first_message) { Object.new }
10
+ let(:parsed_messages) { stub(messageheaders: [first_message]) }
11
+
12
+ before {
13
+ Esendex::Client
14
+ .expects(:get)
15
+ .with(credentials, 'v1.0/messageheaders', startIndex: 0, count: 25)
16
+ .yields(200, xml)
17
+ .returns(parsed_messages.messageheaders)
18
+
19
+ Esendex::Responses::MessageHeaders
20
+ .expects(:deserialise)
21
+ .with(xml)
22
+ .returns(parsed_messages)
23
+ }
24
+
25
+ it 'returns the messages sent by the user on the account' do
26
+ sent = subject.messages.sent
27
+ sent.first.must_equal first_message
28
+ end
29
+ end
30
+
31
+ describe '#get' do
32
+ let(:message_id) { "guid" }
33
+ let(:xml) { "Hey I'm xml" }
34
+ let(:parsed_message) { Object.new }
35
+
36
+ before {
37
+ Esendex::Client
38
+ .expects(:get)
39
+ .with(credentials, "v1.0/messageheaders/#{message_id}")
40
+ .yields(200, xml)
41
+ .returns(parsed_message)
42
+
43
+ Esendex::Responses::MessageHeader
44
+ .expects(:deserialise)
45
+ .with(xml)
46
+ .returns(parsed_message)
47
+ }
48
+
49
+ it 'returns the message sent with the given id' do
50
+ sent = subject.messages.get(message_id)
51
+ sent.must_equal parsed_message
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,33 @@
1
+ require_relative '../../helper'
2
+
3
+ describe Esendex::Requests::Messages do
4
+ subject { Esendex::Requests::Messages }
5
+
6
+ describe '#serialise' do
7
+ let(:reference) { 'EX0000' }
8
+ let(:first) { { to: 'someone', body: 'yo' } }
9
+ let(:second) { { to: 'other', body: 'what?' } }
10
+
11
+ it 'returns an xml representation of the instance' do
12
+ messages = subject.new({
13
+ account_reference: reference,
14
+ messages: [first, second]
15
+ })
16
+
17
+ messages.serialise.must_equal <<EOS
18
+ <?xml version="1.0" encoding="utf-8"?>
19
+ <messages>
20
+ <accountreference>#{reference}</accountreference>
21
+ <message>
22
+ <to>#{first[:to]}</to>
23
+ <body>#{first[:body]}</body>
24
+ </message>
25
+ <message>
26
+ <to>#{second[:to]}</to>
27
+ <body>#{second[:body]}</body>
28
+ </message>
29
+ </messages>
30
+ EOS
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,48 @@
1
+ require_relative '../../helper'
2
+
3
+ describe Esendex::Responses::Account do
4
+ describe '.deserialise' do
5
+
6
+ let(:id) { "A00F0218-510D-423D-A74E-5A65342FE070" }
7
+ let(:uri) { "http://api.esendex.com/v1.0/accounts/A00F0218-510D-423D-A74E-5A65342FE070" }
8
+ let(:reference) { "EX0000000" }
9
+ let(:label) { "label" }
10
+ let(:address) { "447700900654" }
11
+ let(:type) { "Professional" }
12
+ let(:messagesremaining) { 2000 }
13
+ let(:expireson) { "2999-02-25T00:00:00" }
14
+ let(:role) { "PowerUser" }
15
+ let(:settings_uri) { "http://api.esendex.com/v1.0/accounts/A00F0218-510D-423D-A74E-5A65342FE070/settings" }
16
+
17
+ let(:xml) {
18
+ <<EOS
19
+ <?xml version="1.0" encoding="utf-8"?>
20
+ <account id="#{id}" uri="#{uri}" xmlns="http://api.esendex.com/ns/">
21
+ <reference>#{reference}</reference>
22
+ <label>#{label}</label>
23
+ <address>#{address}</address>
24
+ <type>#{type}</type>
25
+ <messagesremaining>#{messagesremaining}</messagesremaining>
26
+ <expireson>#{expireson}</expireson>
27
+ <role>#{role}</role>
28
+ <settings uri="#{settings_uri}" />
29
+ </account>
30
+ EOS
31
+ }
32
+
33
+ it 'deserialises xml into an Account instance' do
34
+ account = Esendex::Responses::Account.deserialise(xml)
35
+
36
+ account.id.must_equal id
37
+ account.uri.must_equal uri
38
+ account.reference.must_equal reference
39
+ account.label.must_equal label
40
+ account.address.must_equal address
41
+ account.type.must_equal type
42
+ account.messages_remaining.must_equal messagesremaining
43
+ account.expires_on.must_equal expireson
44
+ account.role.must_equal role
45
+ account.settings.uri.must_equal settings_uri
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,51 @@
1
+ require_relative '../../helper'
2
+
3
+ describe Esendex::Responses::Accounts do
4
+ describe '.deserialise' do
5
+
6
+ let(:id) { "A00F0218-510D-423D-A74E-5A65342FE070" }
7
+ let(:uri) { "http://api.esendex.com/v1.0/accounts/A00F0218-510D-423D-A74E-5A65342FE070" }
8
+ let(:reference) { "EX0000000" }
9
+ let(:label) { "label" }
10
+ let(:address) { "447700900654" }
11
+ let(:type) { "Professional" }
12
+ let(:messagesremaining) { 2000 }
13
+ let(:expireson) { "2999-02-25T00:00:00" }
14
+ let(:role) { "PowerUser" }
15
+ let(:settings_uri) { "http://api.esendex.com/v1.0/accounts/A00F0218-510D-423D-A74E-5A65342FE070/settings" }
16
+
17
+ let(:xml) {
18
+ <<EOS
19
+ <?xml version="1.0" encoding="utf-8"?>
20
+ <accounts xmlns="http://api.esendex.com/ns/">
21
+ <account id="#{id}" uri="#{uri}">
22
+ <reference>#{reference}</reference>
23
+ <label>#{label}</label>
24
+ <address>#{address}</address>
25
+ <type>#{type}</type>
26
+ <messagesremaining>#{messagesremaining}</messagesremaining>
27
+ <expireson>#{expireson}</expireson>
28
+ <role>#{role}</role>
29
+ <settings uri="#{settings_uri}" />
30
+ </account>
31
+ </accounts>
32
+ EOS
33
+ }
34
+
35
+ it 'deserialises xml into an Accounts instance' do
36
+ accounts = Esendex::Responses::Accounts.deserialise(xml)
37
+ account = accounts.accounts.first
38
+
39
+ account.id.must_equal id
40
+ account.uri.must_equal uri
41
+ account.reference.must_equal reference
42
+ account.label.must_equal label
43
+ account.address.must_equal address
44
+ account.type.must_equal type
45
+ account.messages_remaining.must_equal messagesremaining
46
+ account.expires_on.must_equal expireson
47
+ account.role.must_equal role
48
+ account.settings.uri.must_equal settings_uri
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,29 @@
1
+ require_relative '../../helper'
2
+
3
+ describe Esendex::Responses::MessageDispatcherHeaders do
4
+ subject { Esendex::Responses::MessageDispatcherHeaders }
5
+
6
+ describe '.deserialise' do
7
+ let(:batch_id) { "F8BF9867-FF81-49E4-ACC5-774DE793B776" }
8
+ let(:header_uri) { "https://api.esendex.com/v1.0/MessageHeaders/1183C73D-2E62-4F60-B610-30F160BDFBD5" }
9
+ let(:header_id) { "1183C73D-2E62-4F60-B610-30F160BDFBD5" }
10
+
11
+ let(:xml) {
12
+ <<EOS
13
+ <?xml version="1.0" encoding="utf-8"?>
14
+ <messageheaders batchid="#{batch_id}"
15
+ xmlns="http://api.esendex.com/ns/">
16
+ <messageheader uri="#{header_uri}" id="#{header_id}" />
17
+ </messageheaders>
18
+ EOS
19
+ }
20
+
21
+ it 'deserialises xml into a MessageDispatcherHeaders instance' do
22
+ headers = subject.deserialise(xml)
23
+
24
+ headers.batch_id.must_equal batch_id
25
+ headers.message_headers.first.uri.must_equal header_uri
26
+ headers.message_headers.first.id.must_equal header_id
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,61 @@
1
+ require_relative '../../helper'
2
+
3
+ describe Esendex::Responses::MessageHeader do
4
+ describe '.deserialise' do
5
+
6
+ let(:id) { "CDEB3533-1F76-46D7-A2A9-0DAF8290F7FC" }
7
+ let(:uri) { "http://api.esendex.com/v1.0/messageheaders/CDEB3533-1F76-46D7-A2A9-0DAF8290F7FC/" }
8
+ let(:status) { "Delivered" }
9
+ let(:laststatusat) { "2010-01-01T12:00:05.000" }
10
+ let(:submittedat) { "2010-01-01T12:00:02.000" }
11
+ let(:type) { "SMS" }
12
+ let(:to) { "447700900123" }
13
+ let(:from) { "447700900654" }
14
+ let(:summary) { "Testing REST API" }
15
+ let(:body) { "http://api.esendex.com/v1.0/messageheaders/CDEB3533-1F76-46D7-A2A9-0DAF8290F7FC/body" }
16
+ let(:direction) { "Outbound" }
17
+ let(:parts) { 1 }
18
+ let(:username) { "user@example.com" }
19
+
20
+ let(:xml) {
21
+ <<EOS
22
+ <?xml version="1.0" encoding="utf-8"?>
23
+ <messageheader id="#{id}" uri="#{uri}" xmlns="http://api.esendex.com/ns/">
24
+ <status>#{status}</status>
25
+ <laststatusat>#{laststatusat}</laststatusat>
26
+ <submittedat>#{submittedat}</submittedat>
27
+ <type>#{type}</type>
28
+ <to>
29
+ <phonenumber>#{to}</phonenumber>
30
+ </to>
31
+ <from>
32
+ <phonenumber>#{from}</phonenumber>
33
+ </from>
34
+ <summary>#{summary}</summary>
35
+ <body uri="#{body}"/>
36
+ <direction>#{direction}</direction>
37
+ <parts>#{parts}</parts>
38
+ <username>#{username}</username>
39
+ </messageheader>
40
+ EOS
41
+ }
42
+
43
+ it 'deseralises xml into a MessageHeader instance' do
44
+ message_header = Esendex::Responses::MessageHeader.deserialise(xml)
45
+
46
+ message_header.id.must_equal id
47
+ message_header.uri.must_equal uri
48
+ message_header.status.must_equal status
49
+ message_header.last_status_at.must_equal Time.parse(laststatusat)
50
+ message_header.submitted_at.must_equal Time.parse(submittedat)
51
+ message_header.type.must_equal type
52
+ message_header.to.phonenumber.must_equal to
53
+ message_header.from.phonenumber.must_equal from
54
+ message_header.summary.must_equal summary
55
+ message_header.body.uri.must_equal body
56
+ message_header.direction.must_equal direction
57
+ message_header.parts.must_equal parts
58
+ message_header.username.must_equal username
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,73 @@
1
+ require_relative '../../helper'
2
+
3
+ describe Esendex::Responses::MessageHeaders do
4
+ describe '.deserialise' do
5
+
6
+ let(:startindex) { 5 }
7
+ let(:count) { 15 }
8
+ let(:totalcount) { 200 }
9
+
10
+ let(:id) { "CDEB3533-1F76-46D7-A2A9-0DAF8290F7FC" }
11
+ let(:uri) { "http://api.esendex.com/v1.0/messageheaders/CDEB3533-1F76-46D7-A2A9-0DAF8290F7FC/" }
12
+ let(:status) { "Delivered" }
13
+ let(:laststatusat) { "2010-01-01T12:00:05.000" }
14
+ let(:submittedat) { "2010-01-01T12:00:02.000" }
15
+ let(:type) { "SMS" }
16
+ let(:to) { "447700900123" }
17
+ let(:from) { "447700900654" }
18
+ let(:summary) { "Testing REST API" }
19
+ let(:body) { "http://api.esendex.com/v1.0/messageheaders/CDEB3533-1F76-46D7-A2A9-0DAF8290F7FC/body" }
20
+ let(:direction) { "Outbound" }
21
+ let(:parts) { 1 }
22
+ let(:username) { "user@example.com" }
23
+
24
+ let(:xml) {
25
+ <<EOS
26
+ <?xml version="1.0" encoding="utf-8"?>
27
+ <messageheaders startindex="#{startindex}" count="#{count}" totalcount="#{totalcount}" xmlns="http://api.esendex.com/ns/">
28
+ <messageheader id="#{id}" uri="#{uri}" xmlns="http://api.esendex.com/ns/">
29
+ <status>#{status}</status>
30
+ <laststatusat>#{laststatusat}</laststatusat>
31
+ <submittedat>#{submittedat}</submittedat>
32
+ <type>#{type}</type>
33
+ <to>
34
+ <phonenumber>#{to}</phonenumber>
35
+ </to>
36
+ <from>
37
+ <phonenumber>#{from}</phonenumber>
38
+ </from>
39
+ <summary>#{summary}</summary>
40
+ <body uri="#{body}"/>
41
+ <direction>#{direction}</direction>
42
+ <parts>#{parts}</parts>
43
+ <username>#{username}</username>
44
+ </messageheader>
45
+ </messageheaders>
46
+ EOS
47
+ }
48
+
49
+ it 'deserialises xml into a MessageHeaders instance' do
50
+ message_headers = Esendex::Responses::MessageHeaders.deserialise(xml)
51
+
52
+ message_headers.start_index.must_equal startindex
53
+ message_headers.count.must_equal count
54
+ message_headers.total_count.must_equal totalcount
55
+
56
+ message_header = message_headers.message_headers.first
57
+
58
+ message_header.id.must_equal id
59
+ message_header.uri.must_equal uri
60
+ message_header.status.must_equal status
61
+ message_header.last_status_at.must_equal Time.parse(laststatusat)
62
+ message_header.submitted_at.must_equal Time.parse(submittedat)
63
+ message_header.type.must_equal type
64
+ message_header.to.phonenumber.must_equal to
65
+ message_header.from.phonenumber.must_equal from
66
+ message_header.summary.must_equal summary
67
+ message_header.body.uri.must_equal body
68
+ message_header.direction.must_equal direction
69
+ message_header.parts.must_equal parts
70
+ message_header.username.must_equal username
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,18 @@
1
+ require_relative '../helper'
2
+
3
+ describe Esendex::Users do
4
+ let(:credentials) { Esendex::Credentials.new('user', 'pass', 'ref') }
5
+ subject { Esendex::Users.new(credentials) }
6
+
7
+ describe '#username' do
8
+ it 'returns the username' do
9
+ subject.username.must_equal credentials.username
10
+ end
11
+ end
12
+
13
+ describe '#password' do
14
+ it 'returns the password' do
15
+ subject.password.must_equal credentials.password
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,59 @@
1
+ require_relative 'helper'
2
+
3
+ describe Esendex do
4
+
5
+ subject { dummy_esendex }
6
+ let(:credentials) { subject.instance_variable_get(:@credentials) }
7
+
8
+ describe '#account' do
9
+ let(:account) { Object.new }
10
+
11
+ it 'returns a new Accounts instance' do
12
+ Esendex::Accounts
13
+ .expects(:new)
14
+ .with(credentials)
15
+ .returns(account)
16
+
17
+ subject.account.must_equal account
18
+ end
19
+ end
20
+
21
+ describe '#dispatcher' do
22
+ let(:dispatcher) { Object.new }
23
+
24
+ it 'returns a new Dispatcher instance' do
25
+ Esendex::Dispatcher
26
+ .expects(:new)
27
+ .with(credentials)
28
+ .returns(dispatcher)
29
+
30
+ subject.dispatcher.must_equal dispatcher
31
+ end
32
+ end
33
+
34
+ describe '#messages' do
35
+ let(:messages) { Object.new }
36
+
37
+ it 'returns a new Messages instance' do
38
+ Esendex::Messages
39
+ .expects(:new)
40
+ .with(credentials)
41
+ .returns(messages)
42
+
43
+ subject.messages.must_equal messages
44
+ end
45
+ end
46
+
47
+ describe '#user' do
48
+ let(:user) { Object.new }
49
+
50
+ it 'returns a new Users instance' do
51
+ Esendex::Users
52
+ .expects(:new)
53
+ .with(credentials)
54
+ .returns(user)
55
+
56
+ subject.user.must_equal user
57
+ end
58
+ end
59
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xednese
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Joshua Hawxwell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: seq
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: serialisable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mocha
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ description: |2
98
+ Xednese provides an easy to use client for interacting with the Esendex
99
+ REST API.
100
+ email: m@hawx.me
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - README.md
106
+ - Gemfile
107
+ - Rakefile
108
+ - LICENSE
109
+ - lib/xednese.rb
110
+ - lib/xednese/accounts.rb
111
+ - lib/xednese/client.rb
112
+ - lib/xednese/messages.rb
113
+ - lib/xednese/version.rb
114
+ - lib/xednese/users.rb
115
+ - lib/xednese/responses/accounts.rb
116
+ - lib/xednese/responses/message_headers.rb
117
+ - lib/xednese/responses/parser.rb
118
+ - lib/xednese/responses/message_header.rb
119
+ - lib/xednese/responses/account.rb
120
+ - lib/xednese/responses/message_dispatcher_headers.rb
121
+ - lib/xednese/dispatcher.rb
122
+ - lib/xednese/requests/messages.rb
123
+ - spec/helper.rb
124
+ - spec/xednese_spec.rb
125
+ - spec/xednese/accounts_spec.rb
126
+ - spec/xednese/responses/message_header_spec.rb
127
+ - spec/xednese/responses/message_dispatcher_headers_spec.rb
128
+ - spec/xednese/responses/accounts_spec.rb
129
+ - spec/xednese/responses/account_spec.rb
130
+ - spec/xednese/responses/message_headers_spec.rb
131
+ - spec/xednese/dispatcher_spec.rb
132
+ - spec/xednese/messages_spec.rb
133
+ - spec/xednese/requests/messages_spec.rb
134
+ - spec/xednese/client_spec.rb
135
+ - spec/xednese/users_spec.rb
136
+ homepage: http://github.com/hawx/xednese
137
+ licenses:
138
+ - MIT
139
+ metadata: {}
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.0.14
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: Client library for interacting with the Esendex API
160
+ test_files:
161
+ - spec/helper.rb
162
+ - spec/xednese_spec.rb
163
+ - spec/xednese/accounts_spec.rb
164
+ - spec/xednese/responses/message_header_spec.rb
165
+ - spec/xednese/responses/message_dispatcher_headers_spec.rb
166
+ - spec/xednese/responses/accounts_spec.rb
167
+ - spec/xednese/responses/account_spec.rb
168
+ - spec/xednese/responses/message_headers_spec.rb
169
+ - spec/xednese/dispatcher_spec.rb
170
+ - spec/xednese/messages_spec.rb
171
+ - spec/xednese/requests/messages_spec.rb
172
+ - spec/xednese/client_spec.rb
173
+ - spec/xednese/users_spec.rb