bronto 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ecef6f6a33b18193065318d61c2c05ad66eb6bc
4
- data.tar.gz: 5bc7a98913ab5d3adc1c35cb149065c2a8715606
3
+ metadata.gz: b3a718a328693429d18167f9175b9aca02526a48
4
+ data.tar.gz: b40542d8e2d99e15ffaf3b8ed020cf6932d3eda7
5
5
  SHA512:
6
- metadata.gz: 9414d10e373c8483bea255a4f465d2593edf20b3413cb83ab365185ffc83f40d553da3d44284f05916cd8a896ee44ec9caf211f3427ede18f30383a19ed42ebd
7
- data.tar.gz: 562a6880bbe7f0b4d2693a1725ef105e412d799f9e9678c3834fb2bbe5ff634810e3d41e68aeff730cf24e8b13bdd92e79582ebefdb68963030fa5b1dea2d530
6
+ metadata.gz: dabc2a81c8582050ddbe3a06d2b7df310bf383a57a4de5cceeadc8acb98462021a58c2c5dd35e440a510c1ee4b15dc24f35f2dedb43c6f137174ffb9340baff6
7
+ data.tar.gz: 04204bdb29158c915fab4ebb16afbb032e67a9b76db1c6b6fe6b18a1149fb6c9330159ed01c6336de5ca8a0f564156f081106f5123342bf16b20613f49ab290d
@@ -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
- @last_used = Time.now
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 @api unless refresh || session_expired || @api.nil?
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: :TLSv1)
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
- @api = Savon.client(wsdl: 'https://api.bronto.com/v4?wsdl', soap_header: {
53
- "tns:sessionHeader" => { session_id: resp.body[:login_response][:return] }
54
- },
55
- read_timeout: 600) # Give Bronto up to 10 minutes to reply
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 (@last_used == nil)
61
- return true if (Time.now.tv_sec - @last_used.tv_sec > SESSION_REUSE_SECONDS)
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
@@ -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
@@ -17,6 +17,9 @@ module Bronto
17
17
  def initialize(options = {})
18
18
  super(options)
19
19
  self.active_count ||= 0
20
+ if !self.label.present?
21
+ self.label = self.name
22
+ end
20
23
  end
21
24
 
22
25
  def add_to_list(*contacts)
@@ -1,3 +1,3 @@
1
1
  module Bronto
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
@@ -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.2
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: 2015-06-11 00:00:00.000000000 Z
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.4.6
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: