paubox 0.1.1 → 0.1.3

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: 71a4b58946b0869eac1768ba49c208950fc7d6f2
4
- data.tar.gz: 704a4cf54c5ef966e0f060ad3186f7aab314ecca
3
+ metadata.gz: 1f0440a738fccb295099ca9e7851a3af6d5c3e76
4
+ data.tar.gz: 0e62063b19db76bc80286645cd160bc708a9812b
5
5
  SHA512:
6
- metadata.gz: 89fa8a685e2170ee6ebbf87c2845c7eb3eb875576fc9fd002034d6c33c94fd159c04a0cd5f13985311de9b614ceb8d5f1bd589767b60fad5ebf2adb999497c58
7
- data.tar.gz: 44ab568c8b28b5f77c376851865e0892bf17cbb59f1975e8af47a69be6202cd8ea9ac152aa6c79ff37dcf39497ccd4bc8565254e619876c7ed0d5e314d738b51
6
+ metadata.gz: 458522bb6529f2e8a04d3bd1b729bf0a42e0106d93e55e110e0d8b3bf1537fdb49fdd7694b09549debfb7377ab49f2c759076f5fe13fa44d8d80b1af7cba7448
7
+ data.tar.gz: 9804229b214ab1973f1fce4d3019f919be12511bffb8bb8109b250ebb5f419763a2e582c7e653f323b0386006eaf128420a7e41fb57010f522f1f3071b578b7e
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
 
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
+ .gem
data/README.md CHANGED
@@ -25,19 +25,20 @@ Or install it yourself as:
25
25
  You will need to have a Paubox account. Please contact [Paubox Customer Success](https://paubox.zendesk.com/hc/en-us) for details on gaining access to the Transactional Email API alpha testing program.
26
26
 
27
27
  ### Configuring API Credentials
28
- To set your API credentials you'll need to include these in an initializer (config/initializers/paubox.rb in Rails).
28
+ Include your API credentials in an initializer (e.g. config/initializers/paubox.rb in Rails).
29
29
 
30
- Be careful not to commit your API credentials to version control. It's best to store these in environmental variables.
30
+ Keep your API credentials out of version control. Store these in environmental variables.
31
31
 
32
32
  Paubox.configure do |config|
33
33
  config.api_key = ENV['PAUBOX_API_KEY']
34
34
  config.api_user = ENV['PAUBOX_API_USER']
35
35
  end
36
36
 
37
+ ## Usage
37
38
 
38
39
  ### Sending Messages with the Ruby Mail Library
39
40
 
40
- If you're already using the Ruby Mail Library, sending via Paubox is easy. Just build your message as normal and set Mail::Paubox as the delivery method.
41
+ Using the Ruby Mail Library? Sending via Paubox is easy. Just build a message as normal and set Mail::Paubox as the delivery method.
41
42
 
42
43
  message = Mail.new do
43
44
  from 'you@yourdomain.com'
@@ -62,9 +63,9 @@ If you're already using the Ruby Mail Library, sending via Paubox is easy. Just
62
63
  message.source_tracking_id
63
64
  => "2a3c048485aa4cf6"
64
65
 
65
- ### Sending Messages without ensuring TLS
66
+ ### Allowing non-TLS message delivery
66
67
 
67
- If you want to send non-PHI mail that does not need to be HIPAA-compliant, you can allow the message delivery to take place even if a TLS connection is unavailable.
68
+ If you want to send non-PHI mail that does not need to be HIPAA-compliant, you can allow the message delivery to take place even if a TLS connection is unavailable. This means a message will not be converted into a secure portal message when a non-TLS connection is encountered.
68
69
 
69
70
  message = Mail.new do
70
71
  from 'you@yourdomain.com'
@@ -79,22 +80,54 @@ If you want to send non-PHI mail that does not need to be HIPAA-compliant, you c
79
80
  message.deliver!
80
81
 
81
82
  ### Sending Messages using just the Paubox API
83
+ You don't need to use Ruby Mail to build and send messages with Paubox.
82
84
 
83
85
  args = { from: 'you@yourdomain.com',
84
- to: 'someone@domain.com, someone_else@domain.com',
85
- cc: ['another@domain.com', 'yetanother@domain.com'],
86
+ to: 'someone@domain.com, someone-else@domain.com',
87
+ cc: ['another@domain.com', 'yet-another@domain.com'],
86
88
  bcc: 'bcc-recipient@domain.com',
87
89
  reply_to: 'reply-to@yourdomain.com',
88
90
  subject: 'Testing!',
89
91
  text_content: 'Hello World!',
90
92
  html_content: '<h1>Hello World!</h1>' }
91
93
 
92
- message = Message.new(args)
94
+ message = Paubox::Message.new(args)
93
95
 
94
96
  client = Paubox::Client.new
95
97
  client.deliver_mail(message)
96
98
  => {"message"=>"Service OK", "sourceTrackingId"=>"2a3c048485aa4cf6"}
97
99
 
100
+ ### Checking Email Dispositions
101
+
102
+ client = Paubox::Client.new
103
+ email_disposition = client.email_disposition('2a3c048485aa4cf6')
104
+
105
+ # Get array of email_dispositions. One email_disposition is generated for each recipient.
106
+ message_deliveries = email_disposition.message_deliveries
107
+ => [<struct Paubox::EmailDisposition::MessageDelivery recipient="test@domain.com", status=#<struct Paubox::EmailDisposition::MessageDeliveryStatus delivery_status="delivered", delivery_time=Mon, 30 Apr 2018 12:54:19 -0700, opened_status="opened", opened_time=Mon, 30 Apr 2018 12:55:19 -0700>>]
108
+
109
+ # Inspect a message delivery
110
+ delivery = message_deliveries.first
111
+
112
+ delivery.recipient
113
+ => "test@domain.com"
114
+
115
+ # Inspect the message delivery status
116
+ status = delivery.status
117
+
118
+ status.delivery_status
119
+ => "delivered"
120
+
121
+ status.delivery_time
122
+ => Mon, 30 Apr 2018 12:54:19 -0700
123
+
124
+ # opened_status is only available for single-recipient messages
125
+ status.opened_status
126
+ => "opened"
127
+
128
+ # opened_time is only available for single-recipient messages
129
+ status.opened_time
130
+ => Mon, 30 Apr 2018 12:55:19 -0700
98
131
 
99
132
 
100
133
 
@@ -3,6 +3,7 @@ require 'paubox/client'
3
3
  require 'paubox/format_helper'
4
4
  require 'paubox/mail_to_message'
5
5
  require 'paubox/message'
6
+ require 'paubox/email_disposition'
6
7
  require 'mail/paubox'
7
8
 
8
9
  module Paubox
@@ -2,6 +2,7 @@ module Paubox
2
2
  # Client sends API requests to Paubox API
3
3
  class Client
4
4
  require 'rest-client'
5
+ require 'ostruct'
5
6
  attr_reader :api_key, :api_user, :api_host, :api_protocol, :api_version
6
7
 
7
8
  def initialize(args = {})
@@ -41,7 +42,7 @@ module Paubox
41
42
  def email_disposition(source_tracking_id)
42
43
  url = "#{request_endpoint('message_receipt')}?sourceTrackingId=#{source_tracking_id}"
43
44
  response = RestClient.get(url, auth_header)
44
- JSON.parse(response.body)
45
+ email_disposition = Paubox::EmailDisposition.new(JSON.parse(response.body))
45
46
  end
46
47
  alias message_receipt email_disposition
47
48
 
@@ -69,5 +70,12 @@ module Paubox
69
70
  api_version: 'v1',
70
71
  test_mode: false }
71
72
  end
73
+
74
+ # recursively converts a nested Hash into OpenStruct
75
+ def to_open_struct(hash)
76
+ OpenStruct.new(hash.each_with_object({}) do |(key, val), memo|
77
+ memo[key] = val.is_a?(Hash) ? to_open_struct(val) : val
78
+ end)
79
+ end
72
80
  end
73
81
  end
@@ -0,0 +1,57 @@
1
+ module Paubox
2
+ # Parses email dispositions from /v1/message_reciept response to friendly Ruby
3
+ class EmailDisposition
4
+ require 'time'
5
+ attr_reader :response, :raw_json_response, :source_tracking_id, :message_id,
6
+ :message_deliveries, :errors
7
+ MessageDelivery = Struct.new(:recipient, :status)
8
+ MessageDeliveryStatus = Struct.new(:delivery_status, :delivery_time,
9
+ :opened_status, :opened_time)
10
+ MessageMultiDeliveryStatus = Struct.new(:delivery_status, :delivery_time)
11
+ ResponseError = Struct.new(:code, :status, :title, :details)
12
+
13
+ def initialize(response)
14
+ @response = response
15
+ @raw_json_response = response.to_json
16
+ @source_tracking_id = response.dig('sourceTrackingId')
17
+ @message_data = response.dig('data', 'message')
18
+ @message_id = @message_data ? @message_data['id'] : nil
19
+ @message_deliveries ||= build_message_deliveries
20
+ @errors ||= build_errors
21
+ end
22
+
23
+ def errors?
24
+ errors.any?
25
+ end
26
+
27
+ def build_errors
28
+ return [] unless response['errors']
29
+ errors = response['errors']
30
+ errors.map { |e| ResponseError.new(e['code'], e['status'], e['title'], e['details']) }
31
+ end
32
+
33
+ private
34
+
35
+ def build_message_deliveries
36
+ return [] unless @message_data
37
+ deliveries = @message_data.fetch('message_deliveries', [])
38
+ deliveries.map do |delivery|
39
+ status = build_message_delivery_status(delivery['status'])
40
+ MessageDelivery.new(delivery['recipient'], status)
41
+ end
42
+ end
43
+
44
+ def build_message_delivery_status(stat)
45
+ delivery_status = stat['deliveryStatus']
46
+ delivery_time = stat['deliveryTime'].to_s.empty? ? nil : DateTime.parse(stat['deliveryTime'])
47
+ opened_status = stat['openedStatus'].to_s.empty? ? 'unopened' : stat['openedStatus']
48
+ opened_time = stat['openedTime'].to_s.empty? ? nil : DateTime.parse(stat['openedTime'])
49
+ return MessageMultiDeliveryStatus.new(delivery_status, delivery_time) if multi_recipient?
50
+ MessageDeliveryStatus.new(delivery_status, delivery_time, opened_status, opened_time)
51
+ end
52
+
53
+ def multi_recipient?
54
+ @message_data.fetch('message_deliveries', []).length > 1
55
+ end
56
+ end
57
+ end
@@ -1,3 +1,3 @@
1
1
  module Paubox
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -20,13 +20,13 @@ Gem::Specification.new do |spec|
20
20
  spec.bindir = "exe"
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
-
23
+ spec.required_ruby_version = '>= 2.3'
24
24
  spec.add_development_dependency 'bundler', '~> 1.14'
25
25
  spec.add_development_dependency 'rake', '~> 10.0'
26
26
  spec.add_development_dependency 'rspec', '~> 3.2'
27
27
  spec.add_development_dependency 'webmock', '~> 2.1'
28
28
  spec.add_development_dependency 'pry'
29
29
 
30
- spec.add_dependency 'mail', '~> 2.6', '>= 2.6.4'
30
+ spec.add_dependency 'mail', '>= 2.6'
31
31
  spec.add_dependency 'rest-client', '~> 2.0', '>= 2.0.2'
32
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paubox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paubox
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-04-26 00:00:00.000000000 Z
12
+ date: 2018-04-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -85,22 +85,16 @@ dependencies:
85
85
  name: mail
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - "~>"
89
- - !ruby/object:Gem::Version
90
- version: '2.6'
91
88
  - - ">="
92
89
  - !ruby/object:Gem::Version
93
- version: 2.6.4
90
+ version: '2.6'
94
91
  type: :runtime
95
92
  prerelease: false
96
93
  version_requirements: !ruby/object:Gem::Requirement
97
94
  requirements:
98
- - - "~>"
99
- - !ruby/object:Gem::Version
100
- version: '2.6'
101
95
  - - ">="
102
96
  - !ruby/object:Gem::Version
103
- version: 2.6.4
97
+ version: '2.6'
104
98
  - !ruby/object:Gem::Dependency
105
99
  name: rest-client
106
100
  requirement: !ruby/object:Gem::Requirement
@@ -140,12 +134,12 @@ files:
140
134
  - lib/mail/paubox.rb
141
135
  - lib/paubox.rb
142
136
  - lib/paubox/client.rb
137
+ - lib/paubox/email_disposition.rb
143
138
  - lib/paubox/format_helper.rb
144
139
  - lib/paubox/mail_to_message.rb
145
140
  - lib/paubox/message.rb
146
141
  - lib/paubox/version.rb
147
142
  - lib/paubox_ruby.rb
148
- - paubox-0.1.0.gem
149
143
  - paubox_ruby.gemspec
150
144
  homepage: https://www.paubox.com
151
145
  licenses:
@@ -159,7 +153,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
159
153
  requirements:
160
154
  - - ">="
161
155
  - !ruby/object:Gem::Version
162
- version: '0'
156
+ version: '2.3'
163
157
  required_rubygems_version: !ruby/object:Gem::Requirement
164
158
  requirements:
165
159
  - - ">="
Binary file