govdelivery-tms 0.9.4 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.version +1 -0
- data/Gemfile +1 -2
- data/README.md +92 -12
- data/govdelivery-tms.gemspec +5 -2
- data/lib/govdelivery-tms.rb +2 -0
- data/lib/govdelivery/tms/client.rb +2 -2
- data/lib/govdelivery/tms/collection_resource.rb +2 -2
- data/lib/govdelivery/tms/connection.rb +2 -2
- data/lib/govdelivery/tms/instance_resource.rb +2 -2
- data/lib/govdelivery/tms/resource/from_address.rb +16 -4
- data/lib/govdelivery/tms/resource/reports_messages_email_statistics.rb +8 -0
- data/lib/govdelivery/tms/resource/reports_messages_sms_statistics.rb +8 -0
- data/lib/govdelivery/tms/util/core_ext.rb +4 -2
- data/lib/govdelivery/tms/util/hal_link_parser.rb +1 -1
- data/lib/govdelivery/tms/version.rb +1 -1
- data/spec/client_spec.rb +5 -0
- data/spec/core_ext_spec.rb +27 -0
- data/spec/email_message_spec.rb +1 -1
- data/spec/email_messages_spec.rb +34 -0
- data/spec/email_template_spec.rb +1 -1
- data/spec/from_address_spec.rb +3 -33
- data/spec/keyword_spec.rb +1 -1
- data/spec/reports_messages_email_statistics_spec.rb +23 -0
- data/spec/reports_messages_sms_statistics_spec.rb +22 -0
- data/spec/sms_message_spec.rb +1 -1
- data/spec/sms_messages_spec.rb +20 -8
- data/spec/spec_helper.rb +7 -0
- metadata +68 -23
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
Y2EzNjAyZDA5MWRiZmYyYzBmMzkyZWYyYzc5NDQ1MjMwZjY1NmM5NA==
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fecf72f8c754802f0f002fee9576334b534e29ca4cc0e7f5280821565912db85
|
4
|
+
data.tar.gz: d6e4087bcde8f26b587c4bc9a9616dae17b748a6548508adbdf1aeaa48e87136
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
Yzg5ZDI4Y2I5ZDZlZGE1OTQyYWZkNjAxNmJkOWFmYTU1NWNjMzIxYTM1ZmUx
|
11
|
-
ZmI0MTA2MTMwNGIxZWI2YzlkYjQ2YzBlYWI0YjFhMGQ0MDk5NmU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MmJmNzk5ZjRiNWI1OTJiNjIyYTFmMDY0MTgyZmFhZmQ1ZWQxNzA4YmZmMmU5
|
14
|
-
ZjZmMWUzMDUwZTJhMGY3NGQzNjE3ZTAzZjVhNmNlMGRkNGU0NDU5MTBlODUw
|
15
|
-
NTM0ZDE0ZDU4ZDFkODZhNWE0MzEyYmVmMWY3NTA3NzEwMzQ2ZWE=
|
6
|
+
metadata.gz: e0fcda1aa09326cb1761e9746032052b4d50ac5f0a08e550e64982929a63204cf1dda6c255202877384c56afafb07ed45280a3e6b159ebb8eaee0ab950588c83
|
7
|
+
data.tar.gz: be9073dd5b9e540c61283777ed5814d3fe6ecbb3064990decbc7f9c00b19aeb97a37bc3ae2f07f633c86890f05a48f4e99aa760afc21d534438237c67d2e83b9
|
data/.version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.0
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[![Build Status](https://travis-ci.org/
|
1
|
+
[![Build Status](https://travis-ci.org/granicus/govdelivery-tms-ruby.svg?branch=master)](https://travis-ci.org/granicus/govdelivery-tms-ruby)
|
2
2
|
|
3
3
|
TMS Client
|
4
4
|
===========
|
@@ -39,6 +39,27 @@ client.sms_messages.get # get the first page of sms messages
|
|
39
39
|
client.sms_messages.next.get # get the next page of sms messages
|
40
40
|
```
|
41
41
|
|
42
|
+
#### Optional parameters
|
43
|
+
When loading messages, the following parameters can be passed with requests to change the sort order and number of results returned:
|
44
|
+
|
45
|
+
**page_size**: Must be an integer between 1 and 100
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
client.sms_messages.get({page_size: 2}) # get the first two sms messages
|
49
|
+
```
|
50
|
+
|
51
|
+
**sort_by**: Field by which to sort results. Default: created_at.
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
client.sms_messages.get({sort_by: 'created_at'}) # get the first page of sms messages, sorted by created_at
|
55
|
+
```
|
56
|
+
|
57
|
+
**sort_order**: Order by which to sort results. Must be ASC or DESC. Default: DESC.
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
client.sms_messages.get({sort_order: 'ASC'}) # get the first page of sms messages, sorted by created_at DESC
|
61
|
+
client.sms_messages.get({sort_by: 'body', sort_order: 'ASC'}) # get the first page of sms messages, sorted by body ASC
|
62
|
+
```
|
42
63
|
|
43
64
|
### Sending an SMS Message
|
44
65
|
|
@@ -68,8 +89,7 @@ inbound_sms.attributes # {:from=>"+15005550
|
|
68
89
|
|
69
90
|
```ruby
|
70
91
|
message = client.email_messages.build(:body=>'<p><a href="http://example.com">Visit here</a></p>',
|
71
|
-
:subject => 'Hey'
|
72
|
-
:from_email => 'foo@example.com')
|
92
|
+
:subject => 'Hey')
|
73
93
|
message.recipients.build(:email=>'example1@example.com')
|
74
94
|
message.recipients.build(:email=>'')
|
75
95
|
message.post # true
|
@@ -91,6 +111,45 @@ message.recipients.build(:email=>'bill@example.com')
|
|
91
111
|
message.post
|
92
112
|
```
|
93
113
|
|
114
|
+
#### From Addresses
|
115
|
+
|
116
|
+
From Addresses are read only resources that define which email addresses you
|
117
|
+
can send an email from and have replies and bounces sent to. From Addresses
|
118
|
+
also have an associated default display name. If you wish to send a message
|
119
|
+
from an address that is not your account's default, you will need to specify a
|
120
|
+
From Address on your Message.
|
121
|
+
|
122
|
+
To add or edit From Addresses, you will need to contact your CSC.
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
# Fetch the from_addresses on your account
|
126
|
+
client.from_addresses.get
|
127
|
+
|
128
|
+
# Get the first from address on your account
|
129
|
+
from_address = client.from_addresses.collection.first
|
130
|
+
|
131
|
+
# Lets see what the emails and display name are
|
132
|
+
puts from_address.from_email
|
133
|
+
puts from_address.reply_to_email
|
134
|
+
puts from_address.bound_email
|
135
|
+
puts from_address.from_name
|
136
|
+
|
137
|
+
# Is this from address the account's default?
|
138
|
+
puts from_address.is_default
|
139
|
+
|
140
|
+
# New messages default to using the default from_address of your account
|
141
|
+
message = client.email_messages.build(:body=>'<p><a href="http://example.com">Visit here</a></p>',
|
142
|
+
:subject => 'Hey')
|
143
|
+
|
144
|
+
# Specifiy a different from_address using the links hash
|
145
|
+
message.links[:from_address] = from_address.id
|
146
|
+
|
147
|
+
# If you want, you can override the form_name on a message
|
148
|
+
message.from_name = 'Better Name'
|
149
|
+
message.post
|
150
|
+
```
|
151
|
+
|
152
|
+
|
94
153
|
### Creating an Email Template
|
95
154
|
|
96
155
|
```ruby
|
@@ -181,6 +240,7 @@ completed_at | (sent or failed recipients only)
|
|
181
240
|
|
182
241
|
Metrics
|
183
242
|
-------
|
243
|
+
|
184
244
|
### Viewing recipients that clicked on a link in an email
|
185
245
|
|
186
246
|
```ruby
|
@@ -205,6 +265,29 @@ email_recipient.clicks.get.collection #=> [<#EmailRecipientClick>,...]
|
|
205
265
|
email_recipient.opens.get.collection #=> [<#EmailRecipientOpen>,...]
|
206
266
|
```
|
207
267
|
|
268
|
+
Reports
|
269
|
+
-------
|
270
|
+
|
271
|
+
### Message recipient counts
|
272
|
+
Recipient counts are aggregated across all messages and grouped by message status.
|
273
|
+
|
274
|
+
`start` and `end` are required datetime parameters. They must be truncated to the hour and be in ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ).
|
275
|
+
|
276
|
+
End dates are exclusive and all results are based on utc time.
|
277
|
+
|
278
|
+
#### Email
|
279
|
+
|
280
|
+
```ruby
|
281
|
+
stats = client.reports_messages_email_statistics.get({start: '2017-06-01T10:00:00Z', end: '2017:06:30T18:00:00Z'}) # get email recipient counts for messages sent between 6/1/17 and 6/30/17
|
282
|
+
stats.recipients
|
283
|
+
```
|
284
|
+
|
285
|
+
#### SMS
|
286
|
+
```ruby
|
287
|
+
stats = client.reports_messages_sms_statistics.get({start: '2017-06-01T10:00:00Z', end: '2017:06:30T18:00:00Z'}) # get sms recipient counts for messages sent between 6/1/17 and 6/30/17
|
288
|
+
stats.recipients
|
289
|
+
```
|
290
|
+
|
208
291
|
Configuring 2-way SMS
|
209
292
|
---------------------
|
210
293
|
|
@@ -321,25 +404,22 @@ Generating Documentation
|
|
321
404
|
------------------------
|
322
405
|
This project uses [yard](https://github.com/lsegal/yard) to generate documentation. To generate API documentation yourself, use the following series of commands from the project root:
|
323
406
|
|
324
|
-
```
|
407
|
+
```
|
325
408
|
# install development gems
|
326
409
|
bundle install
|
327
410
|
# generate documentation
|
328
|
-
rake yard
|
411
|
+
bundle exec rake yard
|
329
412
|
```
|
330
413
|
The generated documentation will be placed in the `doc` folder.
|
331
414
|
|
332
415
|
|
333
416
|
Running Tests
|
334
417
|
-------------
|
335
|
-
```ruby
|
336
|
-
appraisal install
|
337
|
-
# optionally specify an activesupport version to test against (3/4), e.g.
|
338
|
-
# appraisal 4 rake ## for ruby 2.1.2
|
339
|
-
appraisal rake
|
340
418
|
```
|
341
|
-
|
419
|
+
bundle install
|
420
|
+
bundle exec rake
|
421
|
+
```
|
342
422
|
|
343
423
|
Compatibility
|
344
424
|
-------------
|
345
|
-
This project is tested and compatible with
|
425
|
+
This project is tested and compatible with Ruby >=2.5.8, and <= 2.7.1.
|
data/govdelivery-tms.gemspec
CHANGED
@@ -12,18 +12,21 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.summary = 'A ruby client to interact with the GovDelivery TMS REST API.'
|
13
13
|
s.description = "A reference implementation, written in Ruby,
|
14
14
|
to interact with GovDelivery's TMS API. The client is
|
15
|
-
compatible with Ruby
|
15
|
+
compatible with Ruby >=2.5.8, and <= 2.7.1"
|
16
16
|
|
17
|
-
s.add_runtime_dependency 'activesupport'
|
17
|
+
s.add_runtime_dependency 'activesupport', '>=5.2.4.3', '<6.0.0'
|
18
18
|
s.add_runtime_dependency 'faraday'
|
19
19
|
s.add_runtime_dependency 'faraday_middleware'
|
20
20
|
s.add_runtime_dependency 'mime-types'
|
21
|
+
s.add_development_dependency 'simplecov'
|
22
|
+
s.add_development_dependency 'simplecov-cobertura'
|
21
23
|
|
22
24
|
s.files = %w(
|
23
25
|
Gemfile
|
24
26
|
README.md
|
25
27
|
Rakefile
|
26
28
|
govdelivery-tms.gemspec
|
29
|
+
.version
|
27
30
|
) + Dir['lib/**/*']
|
28
31
|
|
29
32
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/lib/govdelivery-tms.rb
CHANGED
@@ -36,3 +36,5 @@ require 'govdelivery/tms/resource/command_action'
|
|
36
36
|
require 'govdelivery/tms/resource/command'
|
37
37
|
require 'govdelivery/tms/resource/keyword'
|
38
38
|
require 'govdelivery/tms/resource/webhook'
|
39
|
+
require 'govdelivery/tms/resource/reports_messages_email_statistics'
|
40
|
+
require 'govdelivery/tms/resource/reports_messages_sms_statistics'
|
@@ -39,8 +39,8 @@ class GovDelivery::TMS::Client
|
|
39
39
|
parse_links(services['_links'])
|
40
40
|
end
|
41
41
|
|
42
|
-
def get(href)
|
43
|
-
response = raw_connection.get(href)
|
42
|
+
def get(href, params = {})
|
43
|
+
response = raw_connection.get(href, params)
|
44
44
|
case response.status
|
45
45
|
when 500..599
|
46
46
|
fail GovDelivery::TMS::Request::Error.new(response.status)
|
@@ -16,8 +16,8 @@ module GovDelivery::TMS::CollectionResource
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def get
|
20
|
-
response = client.get(href)
|
19
|
+
def get(params = {})
|
20
|
+
response = client.get(href, params)
|
21
21
|
initialize_collection_from_items(response.body)
|
22
22
|
# setup page links from header
|
23
23
|
links = LinkHeader.parse(response.headers['link']).to_a.collect do |a|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class GovDelivery::TMS::Connection
|
2
2
|
attr_accessor :auth_token, :api_root, :connection, :logger
|
3
3
|
|
4
|
-
def get(href)
|
5
|
-
resp = connection.get("#{href}.json")
|
4
|
+
def get(href, params = {})
|
5
|
+
resp = connection.get("#{href}.json", params)
|
6
6
|
if resp.status != 200
|
7
7
|
fail RecordNotFound.new("Could not find resource at #{href} (status #{resp.status})")
|
8
8
|
else
|
@@ -130,9 +130,9 @@ module GovDelivery::TMS::InstanceResource
|
|
130
130
|
|
131
131
|
attr_reader :attributes
|
132
132
|
|
133
|
-
def get
|
133
|
+
def get(params={})
|
134
134
|
fail GovDelivery::TMS::Errors::InvalidGet if self.new_record?
|
135
|
-
process_response(client.get(href), :get) && self
|
135
|
+
process_response(client.get(href, params), :get) && self
|
136
136
|
end
|
137
137
|
alias_method :get!, :get
|
138
138
|
|
@@ -1,11 +1,23 @@
|
|
1
1
|
module GovDelivery::TMS #:nodoc:
|
2
|
+
# FromAddress is an email address, associated response addresses (reply to,
|
3
|
+
# error to), and a display name that is used when sending an email via TMS.
|
4
|
+
# All messages sent via TMS must have a FromAddress, which can be set via or
|
5
|
+
# via a template. If neither is set with a message is sent, then the account's
|
6
|
+
# default FromAddress will be used.
|
7
|
+
#
|
8
|
+
# This resource is read-only.
|
9
|
+
#
|
10
|
+
# To add more FromAddresses to your account, please contact your CSC.
|
11
|
+
#
|
12
|
+
# @attr from_email [String] Email address that a message will be sent from
|
13
|
+
# @attr from_name [String] Display name of the sender of a message
|
14
|
+
# @attr reploy_to_email [Stirng] Email address that will be used for the Reply-To header
|
15
|
+
# @attr bounce_email [String] Email address that will be used for the Errors-To header
|
16
|
+
# @attr is_default [Boolean] Indicates if the FromAddress is the account's default FromAddress
|
2
17
|
class FromAddress
|
3
18
|
include InstanceResource
|
4
19
|
|
5
|
-
# @!parse attr_accessor :from_email, :reply_to_email, :bounce_email, :is_default
|
6
|
-
writeable_attributes :from_email, :reply_to_email, :bounce_email, :is_default
|
7
|
-
|
8
20
|
# @!parse attr_reader :id, :created_at
|
9
|
-
readonly_attributes :id, :created_at
|
21
|
+
readonly_attributes :id, :created_at, :from_email, :from_name, :reply_to_email, :bounce_email, :is_default
|
10
22
|
end
|
11
23
|
end
|
@@ -5,8 +5,10 @@ module GovDelivery::TMS::CoreExt
|
|
5
5
|
ActiveSupport::Inflector.demodulize(path)
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
9
|
-
ActiveSupport::Inflector.camelize
|
8
|
+
def camelize(str)
|
9
|
+
# Do not use ActiveSupport::Inflector.camelize because it uses global
|
10
|
+
# ActiveSupport::Inflector.acronum data.
|
11
|
+
str.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
10
12
|
end
|
11
13
|
|
12
14
|
def singularize(str)
|
@@ -38,7 +38,7 @@ module GovDelivery::TMS::Util
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def relation_class(rel)
|
41
|
-
::GovDelivery::TMS.const_get(
|
41
|
+
::GovDelivery::TMS.const_get(camelize(rel)).tap do |klass|
|
42
42
|
return nil unless klass.name =~ /GovDelivery::TMS/
|
43
43
|
end
|
44
44
|
rescue NameError
|
data/spec/client_spec.rb
CHANGED
@@ -52,6 +52,11 @@ describe GovDelivery::TMS::Client do
|
|
52
52
|
allow(@raw_connection).to receive(:get).and_return(double('response', status: 202, body: { 'message' => 'hi' }))
|
53
53
|
expect { @client.get('/blargh') }.to raise_error(GovDelivery::TMS::Request::InProgress)
|
54
54
|
end
|
55
|
+
it 'should handle all other responses' do
|
56
|
+
response = double('response', status: 200, body: { 'message' => 'hi' })
|
57
|
+
allow(@raw_connection).to receive(:get).with('/blargh', {params: 'foobar'}).and_return(response)
|
58
|
+
expect(@client.get('/blargh', {params: 'foobar'})).to eq(response)
|
59
|
+
end
|
55
60
|
|
56
61
|
context 'creating a new client without output' do
|
57
62
|
subject { GovDelivery::TMS::Client.new('auth_token', api_root: 'null_url', logger: false) }
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
def inflector
|
4
|
+
m = ActiveSupport::Inflector.method('inflections')
|
5
|
+
return ActiveSupport::Inflector.inflections(:en) if m.arity == 1
|
6
|
+
ActiveSupport::Inflector.inflections
|
7
|
+
end
|
8
|
+
|
9
|
+
describe GovDelivery::TMS::CoreExt do
|
10
|
+
|
11
|
+
subject do
|
12
|
+
Object.new.extend(described_class)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#camelize' do
|
16
|
+
before do
|
17
|
+
inflector do |inflect|
|
18
|
+
inflect.acronym 'SMS'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should return camilized string not using inflector acronyms' do
|
23
|
+
expect(subject.camelize('sms_message')).to eq 'SmsMessage'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/spec/email_message_spec.rb
CHANGED
@@ -91,7 +91,7 @@ describe GovDelivery::TMS::EmailMessage do
|
|
91
91
|
'message_type' => '/message_type/abc',
|
92
92
|
'email_template' => '/templates/email/new-template' }
|
93
93
|
}
|
94
|
-
expect(@message.client).to receive('get').with(@message.href).and_return(double('response', status: 200, body: response))
|
94
|
+
expect(@message.client).to receive('get').with(@message.href, {}).and_return(double('response', status: 200, body: response))
|
95
95
|
@message.get
|
96
96
|
expect(@message.body).to eq('processed')
|
97
97
|
expect(@message.subject).to eq('hey')
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GovDelivery::TMS::EmailMessages do
|
4
|
+
let(:href) {'/messages/email'}
|
5
|
+
context 'loading messages' do
|
6
|
+
let(:client) {double('client')}
|
7
|
+
let(:messages) {[
|
8
|
+
{ subject: 'hello', body: 'greetings from places', created_at: 'a while ago' },
|
9
|
+
{ subject: 'hi!', body: 'feel me flow', created_at: 'longer ago' },
|
10
|
+
{ subject: 'yo', body: 'I am not a robot', created_at: 'even longer ago' }
|
11
|
+
]}
|
12
|
+
|
13
|
+
before do
|
14
|
+
@messages = GovDelivery::TMS::EmailMessages.new(client, href)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should GET ok' do
|
18
|
+
expect(@messages.client).to receive(:get).and_return(double('response', body: messages, status: 200, headers: { 'link' => "</messages/email/page/2>; rel=\"next\",</messages/email/page/11>; rel=\"last\"" }))
|
19
|
+
|
20
|
+
@messages.get
|
21
|
+
expect(@messages.collection.length).to eq(3)
|
22
|
+
expect(@messages.next.href).to eq('/messages/email/page/2')
|
23
|
+
expect(@messages.last.href).to eq('/messages/email/page/11')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should GET ok with parameters' do
|
27
|
+
params = {page_size: 2, sort_by: 'created_by', sort_order: 'foobar'}
|
28
|
+
expect(@messages.client).to receive(:get).with(href, params).and_return(double('response', body: messages[1..-1], status: 200, headers: { 'link' => "</messages/email/page/2>; rel=\"next\",</messages/email/page/11>; rel=\"last\"" }))
|
29
|
+
|
30
|
+
@messages.get(params)
|
31
|
+
expect(@messages.collection.length).to eq(2)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/spec/email_template_spec.rb
CHANGED
@@ -25,7 +25,7 @@ describe GovDelivery::TMS::EmailTemplate do
|
|
25
25
|
}
|
26
26
|
]
|
27
27
|
|
28
|
-
expect(@templates.client).to receive('get').with('/templates/email').and_return(double('response', status: 200, body: response, headers: {}))
|
28
|
+
expect(@templates.client).to receive('get').with('/templates/email', {}).and_return(double('response', status: 200, body: response, headers: {}))
|
29
29
|
@templates.get
|
30
30
|
expect(@templates.collection.length).to eq(1)
|
31
31
|
end
|
data/spec/from_address_spec.rb
CHANGED
@@ -12,6 +12,7 @@ describe GovDelivery::TMS::FromAddress do
|
|
12
12
|
it 'should be able to get a list of email templates' do
|
13
13
|
response = [{
|
14
14
|
'from_email' => 'something@evotest.govdelivery.com',
|
15
|
+
'from_name' => 'Something',
|
15
16
|
'reply_to_email' => 'something@evotest.govdelivery.com',
|
16
17
|
'bounce_email' => 'something@evotest.govdelivery.com',
|
17
18
|
'is_default' => true,
|
@@ -20,43 +21,12 @@ describe GovDelivery::TMS::FromAddress do
|
|
20
21
|
'_links' => { 'self' => '/from_addresses/1' }
|
21
22
|
}]
|
22
23
|
|
23
|
-
expect(@fromaddresses.client).to receive('get').with('/from_addresses').and_return(double('/from_addresses', status: 200, body: response, headers: {}))
|
24
|
+
expect(@fromaddresses.client).to receive('get').with('/from_addresses',{}).and_return(double('/from_addresses', status: 200, body: response, headers: {}))
|
24
25
|
addresses = @fromaddresses.get
|
25
26
|
expect(addresses.collection.length).to eq(1)
|
26
27
|
expect(addresses.collection.first.class).to eq(GovDelivery::TMS::FromAddress)
|
27
28
|
expect(addresses.collection.first.from_email).to eq('something@evotest.govdelivery.com')
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'creating a from address' do
|
32
|
-
let(:client) do
|
33
|
-
double('client')
|
34
|
-
end
|
35
|
-
|
36
|
-
before do
|
37
|
-
@fromaddress = GovDelivery::TMS::FromAddress.new(client, '/from_addresses', from_email: 'something@evotest.govdelivery.com',
|
38
|
-
reply_to_email: 'something@evotest.govdelivery.com',
|
39
|
-
bounce_email: 'something@evotest.govdelivery.com',
|
40
|
-
is_default: true)
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should post successfully' do
|
44
|
-
response = {
|
45
|
-
'from_email' => 'something@evotest.govdelivery.com',
|
46
|
-
'reply_to_email' => 'something@evotest.govdelivery.com',
|
47
|
-
'bounce_email' => 'something@evotest.govdelivery.com',
|
48
|
-
'is_default' => true,
|
49
|
-
'created_at' => 'sometime',
|
50
|
-
'_links' => { 'self' => '/from_addresses/1' }
|
51
|
-
}
|
52
|
-
expect(@fromaddress.client).to receive('post').with(@fromaddress).and_return(double('response', status: 201, body: response))
|
53
|
-
@fromaddress.post
|
54
|
-
expect(@fromaddress.from_email).to eq('something@evotest.govdelivery.com')
|
55
|
-
expect(@fromaddress.reply_to_email).to eq('something@evotest.govdelivery.com')
|
56
|
-
expect(@fromaddress.bounce_email).to eq('something@evotest.govdelivery.com')
|
57
|
-
expect(@fromaddress.is_default).to eq(true)
|
58
|
-
expect(@fromaddress.created_at).to eq('sometime')
|
59
|
-
expect(@fromaddress.href).to eq('/from_addresses/1')
|
29
|
+
expect(addresses.collection.first.from_name).to eq('Something')
|
60
30
|
end
|
61
31
|
end
|
62
32
|
|
data/spec/keyword_spec.rb
CHANGED
@@ -39,7 +39,7 @@ describe GovDelivery::TMS::Keyword do
|
|
39
39
|
end
|
40
40
|
it 'should GET cleanly' do
|
41
41
|
response = { name: 'FOO', response_text: 'hello' }
|
42
|
-
expect(@keyword.client).to receive('get').with(@keyword.href).and_return(double('response', status: 200, body: response))
|
42
|
+
expect(@keyword.client).to receive('get').with(@keyword.href, {}).and_return(double('response', status: 200, body: response))
|
43
43
|
@keyword.get
|
44
44
|
expect(@keyword.name).to eq('FOO')
|
45
45
|
expect(@keyword.response_text).to eq('hello')
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GovDelivery::TMS::ReportsMessagesEmailStatistics do
|
4
|
+
context 'loading email message statistics' do
|
5
|
+
let(:client) { double('client') }
|
6
|
+
let(:href) { '/reports/messages/email/statistics' }
|
7
|
+
|
8
|
+
before do
|
9
|
+
@statistics = GovDelivery::TMS::ReportsMessagesEmailStatistics.new(client, href, {})
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'gets OK with params' do
|
13
|
+
params = {start: Time.now.beginning_of_hour - 7.days, end: Time.now.beginning_of_hour}
|
14
|
+
stats = {:recipients => {:new => 5, :sending => 3, :inconclusive => 2, :blacklisted => 1, :canceled => 7, :sent => 80, :failed => 2} }
|
15
|
+
|
16
|
+
|
17
|
+
expect(@statistics.client).to receive('get').with(href, params).and_return(double('response', status: 200, body: stats))
|
18
|
+
@statistics.get(params)
|
19
|
+
expect(@statistics.recipients).to eq(stats[:recipients])
|
20
|
+
expect(@statistics.recipients[:sent]).to eq(80)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GovDelivery::TMS::ReportsMessagesSmsStatistics do
|
4
|
+
context 'loading sms message statistics' do
|
5
|
+
let(:client) { double('client') }
|
6
|
+
let(:href) { '/reports/messages/sms/statistics' }
|
7
|
+
|
8
|
+
before do
|
9
|
+
@statistics = GovDelivery::TMS::ReportsMessagesSmsStatistics.new(client, href, {})
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'gets OK with params' do
|
13
|
+
params = {start: Time.now.beginning_of_hour - 7.days, end: Time.now.beginning_of_hour}
|
14
|
+
stats = {:recipients => {:new => 5, :sending => 3, :inconclusive => 2, :blacklisted => 1, :canceled => 7, :sent => 80, :failed => 2} }
|
15
|
+
|
16
|
+
expect(@statistics.client).to receive('get').with(href, params).and_return(double('response', status: 200, body: stats))
|
17
|
+
@statistics.get(params)
|
18
|
+
expect(@statistics.recipients).to eq(stats[:recipients])
|
19
|
+
expect(@statistics.recipients[:sent]).to eq(80)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/spec/sms_message_spec.rb
CHANGED
@@ -52,7 +52,7 @@ describe GovDelivery::TMS::SmsMessage do
|
|
52
52
|
end
|
53
53
|
it 'should GET cleanly' do
|
54
54
|
response = { body: 'processed', recipients: [{ phone: '22345678' }], created_at: 'time' }
|
55
|
-
expect(@message.client).to receive('get').with(@message.href).and_return(double('response', status: 200, body: response))
|
55
|
+
expect(@message.client).to receive('get').with(@message.href, {}).and_return(double('response', status: 200, body: response))
|
56
56
|
@message.get
|
57
57
|
expect(@message.body).to eq('processed')
|
58
58
|
expect(@message.created_at).to eq('time')
|
data/spec/sms_messages_spec.rb
CHANGED
@@ -1,21 +1,33 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GovDelivery::TMS::SmsMessages do
|
4
|
+
let(:href) {'/messages/sms'}
|
4
5
|
context 'creating a new messages list' do
|
5
|
-
let(:client)
|
6
|
-
|
7
|
-
|
6
|
+
let(:client) {double('client')}
|
7
|
+
let(:messages) {[
|
8
|
+
{ short_body: 'hi ho', created_at: 'a while ago' },
|
9
|
+
{ short_body: 'hello', created_at: 'longer ago' },
|
10
|
+
{ short_body: 'yo', created_at: 'even longer ago' }
|
11
|
+
]}
|
12
|
+
|
8
13
|
before do
|
9
|
-
@messages = GovDelivery::TMS::SmsMessages.new(client,
|
14
|
+
@messages = GovDelivery::TMS::SmsMessages.new(client, href)
|
10
15
|
end
|
11
16
|
it 'should GET itself' do
|
12
|
-
|
13
|
-
expect(@messages.client).to receive(:get).and_return(double('response', body: body, status: 200, headers: { 'link' => "</messages/page/2>; rel=\"next\",</messages/page/11>; rel=\"last\"" }))
|
17
|
+
expect(@messages.client).to receive(:get).and_return(double('response', body: messages, status: 200, headers: { 'link' => "</messages/sms/page/2>; rel=\"next\",</messages/sms/page/11>; rel=\"last\"" }))
|
14
18
|
|
15
19
|
@messages.get
|
20
|
+
expect(@messages.collection.length).to eq(3)
|
21
|
+
expect(@messages.next.href).to eq('/messages/sms/page/2')
|
22
|
+
expect(@messages.last.href).to eq('/messages/sms/page/11')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should GET ok with parameters' do
|
26
|
+
params = {page_size: 2, sort_by: 'created_by', sort_order: 'foobar'}
|
27
|
+
expect(@messages.client).to receive(:get).with(href, params).and_return(double('response', body: messages[1..-1], status: 200, headers: { 'link' => "</messages/sms/page/2>; rel=\"next\",</messages/sms/page/11>; rel=\"last\"" }))
|
28
|
+
|
29
|
+
@messages.get(params)
|
16
30
|
expect(@messages.collection.length).to eq(2)
|
17
|
-
expect(@messages.next.href).to eq('/messages/page/2')
|
18
|
-
expect(@messages.last.href).to eq('/messages/page/11')
|
19
31
|
end
|
20
32
|
end
|
21
33
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
$LOAD_PATH << File.expand_path('../lib', __FILE__)
|
2
|
+
|
3
|
+
require 'simplecov'
|
4
|
+
require 'simplecov-cobertura'
|
5
|
+
|
6
|
+
SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
|
7
|
+
SimpleCov.start { add_filter "/spec/" }
|
8
|
+
|
2
9
|
require 'govdelivery-tms'
|
3
10
|
|
4
11
|
class GovDelivery::TMS::Horse
|
metadata
CHANGED
@@ -1,80 +1,116 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govdelivery-tms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GovDelivery
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 5.2.4.3
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 6.0.0
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
29
|
+
version: 5.2.4.3
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 6.0.0
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: faraday
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
|
-
- -
|
37
|
+
- - ">="
|
32
38
|
- !ruby/object:Gem::Version
|
33
39
|
version: '0'
|
34
40
|
type: :runtime
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
|
-
- -
|
44
|
+
- - ">="
|
39
45
|
- !ruby/object:Gem::Version
|
40
46
|
version: '0'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: faraday_middleware
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
|
-
- -
|
51
|
+
- - ">="
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: '0'
|
48
54
|
type: :runtime
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
|
-
- -
|
58
|
+
- - ">="
|
53
59
|
- !ruby/object:Gem::Version
|
54
60
|
version: '0'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: mime-types
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
|
-
- -
|
65
|
+
- - ">="
|
60
66
|
- !ruby/object:Gem::Version
|
61
67
|
version: '0'
|
62
68
|
type: :runtime
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
|
-
- -
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: simplecov
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: simplecov-cobertura
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
67
101
|
- !ruby/object:Gem::Version
|
68
102
|
version: '0'
|
69
|
-
description:
|
70
|
-
|
71
|
-
|
103
|
+
description: |-
|
104
|
+
A reference implementation, written in Ruby,
|
105
|
+
to interact with GovDelivery's TMS API. The client is
|
106
|
+
compatible with Ruby >=2.5.8, and <= 2.7.1
|
72
107
|
email:
|
73
108
|
- support@govdelivery.com
|
74
109
|
executables: []
|
75
110
|
extensions: []
|
76
111
|
extra_rdoc_files: []
|
77
112
|
files:
|
113
|
+
- ".version"
|
78
114
|
- Gemfile
|
79
115
|
- README.md
|
80
116
|
- Rakefile
|
@@ -103,6 +139,8 @@ files:
|
|
103
139
|
- lib/govdelivery/tms/resource/keyword.rb
|
104
140
|
- lib/govdelivery/tms/resource/message_type.rb
|
105
141
|
- lib/govdelivery/tms/resource/recipient.rb
|
142
|
+
- lib/govdelivery/tms/resource/reports_messages_email_statistics.rb
|
143
|
+
- lib/govdelivery/tms/resource/reports_messages_sms_statistics.rb
|
106
144
|
- lib/govdelivery/tms/resource/sms_message.rb
|
107
145
|
- lib/govdelivery/tms/resource/sms_template.rb
|
108
146
|
- lib/govdelivery/tms/resource/webhook.rb
|
@@ -111,7 +149,9 @@ files:
|
|
111
149
|
- lib/govdelivery/tms/version.rb
|
112
150
|
- spec/client_spec.rb
|
113
151
|
- spec/command_types_spec.rb
|
152
|
+
- spec/core_ext_spec.rb
|
114
153
|
- spec/email_message_spec.rb
|
154
|
+
- spec/email_messages_spec.rb
|
115
155
|
- spec/email_template_spec.rb
|
116
156
|
- spec/errors_spec.rb
|
117
157
|
- spec/from_address_spec.rb
|
@@ -121,6 +161,8 @@ files:
|
|
121
161
|
- spec/keywords_spec.rb
|
122
162
|
- spec/mail/delivery_method_spec.rb
|
123
163
|
- spec/message_types_spec.rb
|
164
|
+
- spec/reports_messages_email_statistics_spec.rb
|
165
|
+
- spec/reports_messages_sms_statistics_spec.rb
|
124
166
|
- spec/sms_message_spec.rb
|
125
167
|
- spec/sms_messages_spec.rb
|
126
168
|
- spec/spec_helper.rb
|
@@ -128,30 +170,32 @@ files:
|
|
128
170
|
homepage: http://govdelivery.com
|
129
171
|
licenses: []
|
130
172
|
metadata: {}
|
131
|
-
post_install_message:
|
173
|
+
post_install_message:
|
132
174
|
rdoc_options: []
|
133
175
|
require_paths:
|
134
176
|
- lib
|
135
177
|
required_ruby_version: !ruby/object:Gem::Requirement
|
136
178
|
requirements:
|
137
|
-
- -
|
179
|
+
- - ">="
|
138
180
|
- !ruby/object:Gem::Version
|
139
181
|
version: '0'
|
140
182
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
183
|
requirements:
|
142
|
-
- -
|
184
|
+
- - ">="
|
143
185
|
- !ruby/object:Gem::Version
|
144
186
|
version: '0'
|
145
187
|
requirements: []
|
146
|
-
rubyforge_project:
|
147
|
-
rubygems_version: 2.
|
148
|
-
signing_key:
|
188
|
+
rubyforge_project:
|
189
|
+
rubygems_version: 2.7.6.2
|
190
|
+
signing_key:
|
149
191
|
specification_version: 4
|
150
192
|
summary: A ruby client to interact with the GovDelivery TMS REST API.
|
151
193
|
test_files:
|
152
194
|
- spec/client_spec.rb
|
153
195
|
- spec/command_types_spec.rb
|
196
|
+
- spec/core_ext_spec.rb
|
154
197
|
- spec/email_message_spec.rb
|
198
|
+
- spec/email_messages_spec.rb
|
155
199
|
- spec/email_template_spec.rb
|
156
200
|
- spec/errors_spec.rb
|
157
201
|
- spec/from_address_spec.rb
|
@@ -161,8 +205,9 @@ test_files:
|
|
161
205
|
- spec/keywords_spec.rb
|
162
206
|
- spec/mail/delivery_method_spec.rb
|
163
207
|
- spec/message_types_spec.rb
|
208
|
+
- spec/reports_messages_email_statistics_spec.rb
|
209
|
+
- spec/reports_messages_sms_statistics_spec.rb
|
164
210
|
- spec/sms_message_spec.rb
|
165
211
|
- spec/sms_messages_spec.rb
|
166
212
|
- spec/spec_helper.rb
|
167
213
|
- spec/tms_spec.rb
|
168
|
-
has_rdoc:
|