postmark 1.8.1 → 1.9.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 04bb2d6b28c097935401c0bef37ca1ea75114d12
4
- data.tar.gz: ab9fb06aea0112f5ac0a7ab94902592a0ed7bfab
3
+ metadata.gz: 0db315ab0a2f924dca2620b8fc4d18f8c07445e5
4
+ data.tar.gz: 9a322908b988cd2e61126a16359ec95ad02cd391
5
5
  SHA512:
6
- metadata.gz: 324a336fbf5d24aa554e4d8aba8fd55ed4785cd4bb0b42bc1241bfdb6230e6d59ab8da5165e08343b084c9eed68f11dd2a7d2aa0a7e4ff0761c8a7cf2723215b
7
- data.tar.gz: 96c991acef4077c05af52f7f0bda6084e6777e6d3bc3e4c08ae75c0f421b03d8ff943a13d89b5e8ceab732f83432023ad0f58f4f1f22342fc57b2aa9752e0473
6
+ metadata.gz: 1ae0e033687041435061769f2d9e39cbe3de8cf1d46e5939c808aeaa69f88ad844eb9578d1d3cf8babbeae355d64223b4355edfb17c58fee4778d933c5537c4b
7
+ data.tar.gz: 7adbede1755f986942d4260cc44c4d96e2ac03aeea90804162a352184d17f75a4dbfca7348950ada41df6f468092e004cb82c8980086ad5d626dc6423ed3c4c4
data/.gitignore CHANGED
@@ -6,3 +6,4 @@ pkg/*
6
6
  .rvmrc
7
7
  .idea
8
8
  bin/*
9
+ *.swp
data/.travis.yml CHANGED
@@ -21,6 +21,7 @@ matrix:
21
21
  - rvm: 1.9.3
22
22
  gemfile: gemfiles/Gemfile.legacy
23
23
  - rvm: jruby-19mode
24
+ jdk: oraclejdk8
24
25
  gemfile: gemfiles/Gemfile.legacy
25
26
  script: bundle exec rake spec
26
27
  before_install:
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,9 @@
1
1
  = Changelog
2
2
 
3
+ == 1.9.0
4
+
5
+ * Added methods to access domains API endoints
6
+
3
7
  == 1.8.1
4
8
 
5
9
  * Technical release. Fixed gemspec.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.8.1
1
+ 1.9.0
@@ -61,6 +61,46 @@ module Postmark
61
61
  end
62
62
  alias_method :delete_signature, :delete_sender
63
63
 
64
+ def domains(options = {})
65
+ find_each('domains', 'Domains', options)
66
+ end
67
+
68
+ def get_domains(options = {})
69
+ load_batch('domains', 'Domains', options).last
70
+ end
71
+
72
+ def get_domains_count(options = {})
73
+ get_resource_count('domains', options)
74
+ end
75
+
76
+ def get_domain(id)
77
+ format_response http_client.get("domains/#{id.to_i}")
78
+ end
79
+
80
+ def create_domain(attributes = {})
81
+ data = serialize(HashHelper.to_postmark(attributes))
82
+
83
+ format_response http_client.post('domains', data)
84
+ end
85
+
86
+ def update_domain(id, attributes = {})
87
+ data = serialize(HashHelper.to_postmark(attributes))
88
+
89
+ format_response http_client.put("domains/#{id.to_i}", data)
90
+ end
91
+
92
+ def verified_domain_spf?(id)
93
+ !!http_client.post("domains/#{id.to_i}/verifyspf")['SPFVerified']
94
+ end
95
+
96
+ def rotate_domain_dkim(id)
97
+ format_response http_client.post("domains/#{id.to_i}/rotatedkim")
98
+ end
99
+
100
+ def delete_domain(id)
101
+ format_response http_client.delete("domains/#{id.to_i}")
102
+ end
103
+
64
104
  def servers(options = {})
65
105
  find_each('servers', 'Servers', options)
66
106
  end
@@ -93,4 +133,4 @@ module Postmark
93
133
 
94
134
  end
95
135
 
96
- end
136
+ end
@@ -1,3 +1,3 @@
1
1
  module Postmark
2
- VERSION = '1.8.1'
2
+ VERSION = '1.9.0'
3
3
  end
@@ -31,6 +31,7 @@ describe 'Account API client usage' do
31
31
  expect(updated_sender[:name]).to eq('New Name')
32
32
  expect(updated_sender[:id]).to eq(new_sender[:id])
33
33
 
34
+
34
35
  # spf
35
36
  expect(subject.verified_sender_spf?(new_sender[:id])).to be_true
36
37
 
@@ -46,6 +47,44 @@ describe 'Account API client usage' do
46
47
  expect { subject.delete_sender(new_sender[:id]) }.not_to raise_error
47
48
  end
48
49
 
50
+ it 'can be used to manage domains' do
51
+ new_domain = nil
52
+ domain_name = "#{unique_token}-gem-integration.test"
53
+ return_path = "return.#{domain_name}"
54
+ updated_return_path = "updated-return.#{domain_name}"
55
+
56
+ # create & count
57
+ new_domain = subject.create_domain(:name => domain_name,
58
+ :return_path_domain => return_path)
59
+ expect(subject.get_domains_count).to be > 0
60
+
61
+ # get
62
+ expect(subject.get_domain(new_domain[:id])[:id]).to eq(new_domain[:id])
63
+
64
+ # list
65
+ domains = subject.get_domains(:count => 50)
66
+ expect(domains.map { |d| d[:id] }).to include(new_domain[:id])
67
+
68
+ # collection
69
+ expect(subject.domains.map { |d| d[:id] }).to include(new_domain[:id])
70
+
71
+ # update
72
+ updated_domain = subject.update_domain(new_domain[:id], :return_path_domain => updated_return_path)
73
+ expect(updated_domain[:return_path_domain]).to eq(updated_return_path)
74
+ expect(updated_domain[:id]).to eq(new_domain[:id])
75
+
76
+ # spf
77
+ expect(subject.verified_domain_spf?(new_domain[:id])).to be_false
78
+
79
+ # dkim
80
+ expect { subject.rotate_domain_dkim(new_domain[:id]) }.
81
+ to raise_error(Postmark::InvalidMessageError,
82
+ 'This DKIM is already being renewed.')
83
+
84
+ # delete
85
+ expect { subject.delete_domain(new_domain[:id]) }.not_to raise_error
86
+ end
87
+
49
88
  it 'can be used to manage servers' do
50
89
  new_server = nil
51
90
 
@@ -73,4 +112,4 @@ describe 'Account API client usage' do
73
112
  expect { subject.delete_server(new_server[:id]) }.not_to raise_error
74
113
  end
75
114
 
76
- end
115
+ end
@@ -323,6 +323,221 @@ describe Postmark::AccountApiClient do
323
323
  end
324
324
 
325
325
  end
326
+
327
+ describe '#domains' do
328
+
329
+ let(:response) {
330
+ {
331
+ 'TotalCount' => 10, 'Domains' => [{}, {}]
332
+ }
333
+ }
334
+
335
+ it 'returns an enumerator' do
336
+ expect(subject.domains).to be_kind_of(Enumerable)
337
+ end
338
+
339
+ it 'lazily loads domains' do
340
+ allow(subject.http_client).to receive(:get).
341
+ with('domains', an_instance_of(Hash)).and_return(response)
342
+ subject.domains.take(1000)
343
+ end
344
+
345
+ end
346
+
347
+ describe '#get_domains' do
348
+
349
+ let(:response) {
350
+ {
351
+ "TotalCount" => 1,
352
+ "Domains" => [{
353
+ "Name" => "example.com",
354
+ "ID" => 8139
355
+ }]
356
+ }
357
+ }
358
+
359
+ it 'performs a GET request to /domains endpoint' do
360
+ allow(subject.http_client).to receive(:get).
361
+ with('domains', :offset => 0, :count => 30).
362
+ and_return(response)
363
+ subject.get_domains
364
+ end
365
+
366
+ it 'formats the keys of returned list of domains' do
367
+ allow(subject.http_client).to receive(:get).and_return(response)
368
+ keys = subject.get_domains.map { |s| s.keys }.flatten
369
+ expect(keys.all? { |k| k.is_a?(Symbol) }).to be_true
370
+ end
371
+
372
+ it 'accepts offset and count options' do
373
+ allow(subject.http_client).to receive(:get).
374
+ with('domains', :offset => 10, :count => 42).
375
+ and_return(response)
376
+ subject.get_domains(:offset => 10, :count => 42)
377
+ end
378
+
379
+ end
380
+
381
+ describe '#get_domains_count' do
382
+
383
+ let(:response) { {'TotalCount' => 42} }
384
+
385
+ it 'returns a total number of domains' do
386
+ allow(subject.http_client).to receive(:get).
387
+ with('domains', an_instance_of(Hash)).and_return(response)
388
+ expect(subject.get_domains_count).to eq(42)
389
+ end
390
+
391
+ end
392
+
393
+ describe '#get_domain' do
394
+
395
+ let(:response) {
396
+ {
397
+ "Name" => "example.com",
398
+ "ID" => 8139
399
+ }
400
+ }
401
+
402
+ it 'performs a GET request to /domains/:id endpoint' do
403
+ allow(subject.http_client).to receive(:get).with("domains/42").
404
+ and_return(response)
405
+ subject.get_domain(42)
406
+ end
407
+
408
+ it 'formats the keys of returned response' do
409
+ allow(subject.http_client).to receive(:get).and_return(response)
410
+ keys = subject.get_domain(42).keys
411
+ expect(keys.all? { |k| k.is_a?(Symbol) }).to be_true
412
+ end
413
+ end
414
+
415
+ describe '#create_domain' do
416
+
417
+ let(:response) {
418
+ {
419
+ "Name" => "example.com",
420
+ "ID" => 8139
421
+ }
422
+ }
423
+
424
+ it 'performs a POST request to /domains endpoint' do
425
+ allow(subject.http_client).to receive(:post).
426
+ with("domains", an_instance_of(String)).and_return(response)
427
+ subject.create_domain(:name => 'example.com')
428
+ end
429
+
430
+ it 'converts the domain attributes names to camel case' do
431
+ allow(subject.http_client).to receive(:post).
432
+ with("domains", {'FooBar' => 'bar'}.to_json).and_return(response)
433
+ subject.create_domain(:foo_bar => 'bar')
434
+ end
435
+
436
+ it 'formats the keys of returned response' do
437
+ allow(subject.http_client).to receive(:post).and_return(response)
438
+ keys = subject.create_domain(:foo => 'bar').keys
439
+ expect(keys.all? { |k| k.is_a?(Symbol) }).to be_true
440
+ end
441
+ end
442
+
443
+ describe '#update_domain' do
444
+
445
+ let(:response) {
446
+ {
447
+ "Name" => "example.com",
448
+ "ReturnPathDomain" => "return.example.com",
449
+ "ID" => 8139
450
+ }
451
+ }
452
+
453
+ it 'performs a PUT request to /domains/:id endpoint' do
454
+ allow(subject.http_client).to receive(:put).
455
+ with('domains/42', an_instance_of(String)).and_return(response)
456
+ subject.update_domain(42, :return_path_domain => 'updated-return.example.com')
457
+ end
458
+
459
+ it 'converts the domain attributes names to camel case' do
460
+ allow(subject.http_client).to receive(:put).
461
+ with('domains/42', {'FooBar' => 'bar'}.to_json).and_return(response)
462
+ subject.update_domain(42, :foo_bar => 'bar')
463
+ end
464
+
465
+ it 'formats the keys of returned response' do
466
+ allow(subject.http_client).to receive(:put).and_return(response)
467
+ keys = subject.update_domain(42, :foo => 'bar').keys
468
+ expect(keys.all? { |k| k.is_a?(Symbol) }).to be_true
469
+ end
470
+
471
+ end
472
+
473
+ describe '#verified_domain_spf?' do
474
+
475
+ let(:response) { {"SPFVerified" => true} }
476
+ let(:false_response) { {"SPFVerified" => false} }
477
+
478
+ it 'performs a POST request to /domains/:id/verifyspf endpoint' do
479
+ allow(subject.http_client).to receive(:post).
480
+ with('domains/42/verifyspf').and_return(response)
481
+ subject.verified_domain_spf?(42)
482
+ end
483
+
484
+ it 'returns false when SPFVerified field of the response is false' do
485
+ allow(subject.http_client).to receive(:post).and_return(false_response)
486
+ expect(subject.verified_domain_spf?(42)).to be_false
487
+ end
488
+
489
+ it 'returns true when SPFVerified field of the response is true' do
490
+ allow(subject.http_client).to receive(:post).and_return(response)
491
+ expect(subject.verified_domain_spf?(42)).to be_true
492
+ end
493
+
494
+ end
495
+
496
+ describe '#rotate_domain_dkim' do
497
+
498
+ let(:response) {
499
+ {
500
+ "Name" => "example.com",
501
+ "ID" => 8139
502
+ }
503
+ }
504
+
505
+ it 'performs a POST request to /domains/:id/rotatedkim endpoint' do
506
+ allow(subject.http_client).to receive(:post).
507
+ with('domains/42/rotatedkim').and_return(response)
508
+ subject.rotate_domain_dkim(42)
509
+ end
510
+
511
+ it 'formats the keys of returned response' do
512
+ allow(subject.http_client).to receive(:post).and_return(response)
513
+ keys = subject.rotate_domain_dkim(42).keys
514
+ expect(keys.all? { |k| k.is_a?(Symbol) }).to be_true
515
+ end
516
+
517
+ end
518
+
519
+ describe '#delete_domain' do
520
+
521
+ let(:response) {
522
+ {
523
+ "ErrorCode" => 0,
524
+ "Message" => "Domain example.com removed."
525
+ }
526
+ }
527
+
528
+ it 'performs a DELETE request to /domains/:id endpoint' do
529
+ allow(subject.http_client).to receive(:delete).
530
+ with('domains/42').and_return(response)
531
+ subject.delete_domain(42)
532
+ end
533
+
534
+ it 'formats the keys of returned response' do
535
+ allow(subject.http_client).to receive(:delete).and_return(response)
536
+ keys = subject.delete_sender(42).keys
537
+ expect(keys.all? { |k| k.is_a?(Symbol) }).to be_true
538
+ end
539
+
540
+ end
326
541
 
327
542
  describe '#servers' do
328
543
 
@@ -535,4 +750,4 @@ describe Postmark::AccountApiClient do
535
750
 
536
751
  end
537
752
 
538
- end
753
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postmark
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.1
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Petyo Ivanov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-07-12 00:00:00.000000000 Z
13
+ date: 2016-10-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake