bronto 0.3.2 → 0.3.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 +4 -4
- data/lib/bronto/base.rb +23 -10
- data/lib/bronto/delivery.rb +3 -2
- data/lib/bronto/list.rb +3 -0
- data/lib/bronto/version.rb +1 -1
- data/test/base_test.rb +26 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3a718a328693429d18167f9175b9aca02526a48
|
4
|
+
data.tar.gz: b40542d8e2d99e15ffaf3b8ed020cf6932d3eda7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dabc2a81c8582050ddbe3a06d2b7df310bf383a57a4de5cceeadc8acb98462021a58c2c5dd35e440a510c1ee4b15dc24f35f2dedb43c6f137174ffb9340baff6
|
7
|
+
data.tar.gz: 04204bdb29158c915fab4ebb16afbb032e67a9b76db1c6b6fe6b18a1149fb6c9330159ed01c6336de5ca8a0f564156f081106f5123342bf16b20613f49ab290d
|
data/lib/bronto/base.rb
CHANGED
@@ -20,6 +20,10 @@ module Bronto
|
|
20
20
|
@@api_key
|
21
21
|
end
|
22
22
|
|
23
|
+
def self.connection_cache
|
24
|
+
@@connection_cache ||= {}
|
25
|
+
end
|
26
|
+
|
23
27
|
# Simple helper method to convert class name to downcased pluralized version (e.g., Field -> fields).
|
24
28
|
def self.plural_class_name
|
25
29
|
self.to_s.split("::").last.downcase.pluralize
|
@@ -37,28 +41,37 @@ module Bronto
|
|
37
41
|
|
38
42
|
resp = api(api_key).call(method.to_sym, message: message)
|
39
43
|
|
40
|
-
|
44
|
+
connection_cache[api_key][:last_used] = Time.now
|
41
45
|
|
42
46
|
resp.body["#{method}_response".to_sym]
|
43
47
|
end
|
44
48
|
|
45
49
|
# Sets up the Savon SOAP client object, including sessionHeaders and returns the client.
|
46
50
|
def self.api(api_key, refresh = false)
|
47
|
-
return
|
51
|
+
return connection_cache[api_key][:client] unless refresh || session_expired(api_key) || connection_cache[api_key].nil?
|
48
52
|
|
49
|
-
client = Savon.client(wsdl: 'https://api.bronto.com/v4?wsdl', ssl_version: :
|
53
|
+
client = Savon.client(wsdl: 'https://api.bronto.com/v4?wsdl', ssl_version: :TLSv1_2)
|
50
54
|
resp = client.call(:login, message: { api_token: api_key })
|
51
55
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
+
connection_cache[api_key] = {
|
57
|
+
client: Savon.client(
|
58
|
+
wsdl: 'https://api.bronto.com/v4?wsdl',
|
59
|
+
soap_header: {
|
60
|
+
"tns:sessionHeader" => { session_id: resp.body[:login_response][:return] }
|
61
|
+
},
|
62
|
+
read_timeout: 600 # Give Bronto up to 10 minutes to reply
|
63
|
+
),
|
64
|
+
last_used: nil
|
65
|
+
}
|
66
|
+
connection_cache[api_key][:client]
|
56
67
|
end
|
57
68
|
|
58
69
|
# returns true if a cached session identifier is missing or is too old
|
59
|
-
def self.session_expired
|
60
|
-
return true if (
|
61
|
-
|
70
|
+
def self.session_expired(api_key)
|
71
|
+
return true if (connection_cache[api_key].nil?)
|
72
|
+
last_used = connection_cache[api_key][:last_used]
|
73
|
+
return true if (last_used == nil)
|
74
|
+
return true if (Time.now.tv_sec - last_used.tv_sec > SESSION_REUSE_SECONDS)
|
62
75
|
|
63
76
|
false
|
64
77
|
end
|
data/lib/bronto/delivery.rb
CHANGED
@@ -33,9 +33,10 @@ module Bronto
|
|
33
33
|
end
|
34
34
|
|
35
35
|
hash = {
|
36
|
-
id: id, start: start_val, message_id: message_id, from_email: from_email, from_name: from_name,
|
36
|
+
id: id, start: start_val, message_id: message_id, type: type, from_email: from_email, from_name: from_name,
|
37
37
|
reply_email: reply_email, recipients: recipients, fields: fields, authentication: authentication,
|
38
|
-
reply_tracking: reply_tracking
|
38
|
+
reply_tracking: reply_tracking,
|
39
|
+
type: type,
|
39
40
|
}
|
40
41
|
hash.each { |k,v| hash.delete(k) if v.blank? }
|
41
42
|
hash
|
data/lib/bronto/list.rb
CHANGED
data/lib/bronto/version.rb
CHANGED
data/test/base_test.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class BaseTest < Test::Unit::TestCase
|
4
|
+
context "" do
|
5
|
+
teardown do
|
6
|
+
reset_all
|
7
|
+
end
|
8
|
+
|
9
|
+
should "reuse clients when the api key is the same" do
|
10
|
+
client1 = Bronto::Base.api('api-key-1')
|
11
|
+
client2 = Bronto::Base.api('api-key-1')
|
12
|
+
|
13
|
+
assert client1.is_a?(Savon::Client)
|
14
|
+
assert_equal client1, client2
|
15
|
+
end
|
16
|
+
|
17
|
+
should "not reuse clients when the api key is different" do
|
18
|
+
client1 = Bronto::Base.api('api-key-1')
|
19
|
+
client2 = Bronto::Base.api('api-key-2')
|
20
|
+
|
21
|
+
assert client1.is_a?(Savon::Client)
|
22
|
+
assert client2.is_a?(Savon::Client)
|
23
|
+
assert_not_equal client1, client2
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bronto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Gordon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: savon
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- lib/core_ext/array.rb
|
93
93
|
- lib/core_ext/object.rb
|
94
94
|
- lib/core_ext/string.rb
|
95
|
+
- test/base_test.rb
|
95
96
|
- test/contact_test.rb
|
96
97
|
- test/delivery_test.rb
|
97
98
|
- test/field_test.rb
|
@@ -118,15 +119,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
119
|
version: '0'
|
119
120
|
requirements: []
|
120
121
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.
|
122
|
+
rubygems_version: 2.6.11
|
122
123
|
signing_key:
|
123
124
|
specification_version: 4
|
124
125
|
summary: A Ruby wrapper for the Bronto SOAP API
|
125
126
|
test_files:
|
127
|
+
- test/base_test.rb
|
126
128
|
- test/contact_test.rb
|
127
129
|
- test/delivery_test.rb
|
128
130
|
- test/field_test.rb
|
129
131
|
- test/list_test.rb
|
130
132
|
- test/message_test.rb
|
131
133
|
- test/test_helper.rb
|
132
|
-
has_rdoc:
|