braze_ruby 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/braze_ruby/api.rb +5 -4
  3. data/lib/braze_ruby/endpoints/campaigns.rb +1 -1
  4. data/lib/braze_ruby/endpoints/canvas.rb +2 -2
  5. data/lib/braze_ruby/endpoints/delete_users.rb +1 -1
  6. data/lib/braze_ruby/endpoints/email_status.rb +1 -1
  7. data/lib/braze_ruby/endpoints/email_sync.rb +2 -2
  8. data/lib/braze_ruby/endpoints/identify_users.rb +1 -1
  9. data/lib/braze_ruby/endpoints/schedule_messages.rb +1 -1
  10. data/lib/braze_ruby/endpoints/send_messages.rb +1 -1
  11. data/lib/braze_ruby/endpoints/subscription.rb +3 -3
  12. data/lib/braze_ruby/endpoints/track_users.rb +1 -1
  13. data/lib/braze_ruby/http.rb +12 -1
  14. data/lib/braze_ruby/rest/base.rb +3 -2
  15. data/lib/braze_ruby/rest/canvas_details.rb +2 -2
  16. data/lib/braze_ruby/rest/email_hard_bounces.rb +2 -2
  17. data/lib/braze_ruby/rest/email_status.rb +2 -2
  18. data/lib/braze_ruby/rest/email_unsubscribes.rb +2 -2
  19. data/lib/braze_ruby/rest/schedule_messages.rb +2 -2
  20. data/lib/braze_ruby/rest/send_messages.rb +2 -2
  21. data/lib/braze_ruby/rest/subscription_status_get.rb +2 -2
  22. data/lib/braze_ruby/rest/subscription_status_set.rb +2 -2
  23. data/lib/braze_ruby/rest/subscription_user_status.rb +2 -2
  24. data/lib/braze_ruby/rest/trigger_campaign_send.rb +2 -2
  25. data/lib/braze_ruby/rest/trigger_canvas_send.rb +2 -2
  26. data/lib/braze_ruby/version.rb +1 -1
  27. data/spec/braze_ruby/http_spec.rb +45 -0
  28. data/spec/braze_ruby/rest/delete_users_spec.rb +1 -1
  29. data/spec/braze_ruby/rest/email_status_spec.rb +1 -1
  30. data/spec/braze_ruby/rest/export_users_spec.rb +1 -1
  31. data/spec/braze_ruby/rest/identify_users_spec.rb +1 -1
  32. data/spec/braze_ruby/rest/schedule_messages_spec.rb +1 -1
  33. data/spec/braze_ruby/rest/send_messages_spec.rb +3 -1
  34. data/spec/braze_ruby/rest/track_users_spec.rb +1 -1
  35. data/spec/support/integrations.rb +5 -1
  36. metadata +4 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69312ed5aded0835cc1a47be5d8192b0055edef0c64acf05aca8eef6333e8ba1
4
- data.tar.gz: aa86ae45bb15cce4fd1c4ac56f36cc9fe5fcc935e4015c07cd9f611e76b22bf5
3
+ metadata.gz: 00f98a5e5a27d4b6fee439d6a9e94d4cba07a289d19156676cb40ca461f49ebe
4
+ data.tar.gz: f1d8d93b6fc59235283f56d97a70e5865648f0112ed96d4e236ee026b71e4afb
5
5
  SHA512:
6
- metadata.gz: ae746b58c45e1b24a8b5eae483cc9ec5d42a4669aa70803803a9fe49575ee1b17d58e644f3d95c37b7668e1fa967baa850d76423687689f68b7bf56b3c53ac2d
7
- data.tar.gz: 57a527541dc22889bd4ffd015e52ca2d04c45c6e251539de5e6830a9a76ff4b9a01041b6dbbc3f836e98b23689565b652d263986e8200628a51d08c08de28b7e
6
+ metadata.gz: 5054700908a8a4082656351cf8be6a1e1f2733f1ca9b82a1fb1d3bc6b66332dc1c08c46cb739dd13f3083ee09dde3cf3ecce21afee61aca4d1be46c386a7066f
7
+ data.tar.gz: a2a388bb6cdef1683ccd31b6a185d2343d6190c4c4d32479158c830fe94ba79bc30599e7c7bc8a882faa11a7bf4fe4267166f0476ec4198e48cf076ab4014240
@@ -27,18 +27,19 @@ module BrazeRuby
27
27
  include BrazeRuby::Endpoints::IdentifyUsers
28
28
 
29
29
  def export_users(**payload)
30
- BrazeRuby::REST::ExportUsers.new(braze_url).perform(api_key, payload)
30
+ BrazeRuby::REST::ExportUsers.new(braze_url, options).perform(api_key, payload)
31
31
  end
32
32
 
33
33
  def list_segments
34
- BrazeRuby::REST::ListSegments.new(braze_url).perform(api_key)
34
+ BrazeRuby::REST::ListSegments.new(braze_url, options).perform(api_key)
35
35
  end
36
36
 
37
- attr_reader :api_key, :braze_url
37
+ attr_reader :api_key, :braze_url, :options
38
38
 
39
- def initialize(api_key, braze_url)
39
+ def initialize(api_key, braze_url, options = {})
40
40
  @api_key = api_key
41
41
  @braze_url = braze_url
42
+ @options = options
42
43
  end
43
44
  end
44
45
  end
@@ -4,7 +4,7 @@ module BrazeRuby
4
4
  module Endpoints
5
5
  module Campaigns
6
6
  def trigger_campaign_send(**payload)
7
- BrazeRuby::REST::TriggerCampaignSend.new(api_key, braze_url, payload).perform
7
+ BrazeRuby::REST::TriggerCampaignSend.new(api_key, braze_url, options, payload).perform
8
8
  end
9
9
  end
10
10
  end
@@ -4,11 +4,11 @@ module BrazeRuby
4
4
  module Endpoints
5
5
  module Canvas
6
6
  def trigger_canvas_send(**payload)
7
- BrazeRuby::REST::TriggerCanvasSend.new(api_key, braze_url, payload).perform
7
+ BrazeRuby::REST::TriggerCanvasSend.new(api_key, braze_url, options, payload).perform
8
8
  end
9
9
 
10
10
  def canvas_details(**payload)
11
- BrazeRuby::REST::CanvasDetails.new(api_key, braze_url, payload).perform
11
+ BrazeRuby::REST::CanvasDetails.new(api_key, braze_url, options, payload).perform
12
12
  end
13
13
  end
14
14
  end
@@ -16,7 +16,7 @@ module BrazeRuby
16
16
  private
17
17
 
18
18
  def delete_users_service
19
- @delete_users_service ||= BrazeRuby::REST::DeleteUsers.new(braze_url)
19
+ @delete_users_service ||= BrazeRuby::REST::DeleteUsers.new(braze_url, options)
20
20
  end
21
21
  end
22
22
  end
@@ -4,7 +4,7 @@ module BrazeRuby
4
4
  module Endpoints
5
5
  module EmailStatus
6
6
  def email_status(**payload)
7
- email_status_service.new(api_key, braze_url, payload).perform
7
+ email_status_service.new(api_key, braze_url, options, payload).perform
8
8
  end
9
9
 
10
10
  def email_status_service
@@ -4,11 +4,11 @@ module BrazeRuby
4
4
  module Endpoints
5
5
  module EmailSync
6
6
  def email_unsubscribes(**payload)
7
- BrazeRuby::REST::EmailUnsubscribes.new(api_key, braze_url, payload).perform
7
+ BrazeRuby::REST::EmailUnsubscribes.new(api_key, braze_url, options, payload).perform
8
8
  end
9
9
 
10
10
  def email_hard_bounces(**payload)
11
- BrazeRuby::REST::EmailHardBounces.new(api_key, braze_url, payload).perform
11
+ BrazeRuby::REST::EmailHardBounces.new(api_key, braze_url, options, payload).perform
12
12
  end
13
13
  end
14
14
  end
@@ -12,7 +12,7 @@ module BrazeRuby
12
12
  private
13
13
 
14
14
  def identify_users_service
15
- @identify_users_service ||= BrazeRuby::REST::IdentifyUsers.new(braze_url)
15
+ @identify_users_service ||= BrazeRuby::REST::IdentifyUsers.new(braze_url, options)
16
16
  end
17
17
  end
18
18
  end
@@ -4,7 +4,7 @@ module BrazeRuby
4
4
  module Endpoints
5
5
  module ScheduleMessages
6
6
  def schedule_messages(**payload)
7
- schedule_messages_service.new(api_key, braze_url, payload).perform
7
+ schedule_messages_service.new(api_key, braze_url, options, payload).perform
8
8
  end
9
9
 
10
10
  private
@@ -4,7 +4,7 @@ module BrazeRuby
4
4
  module Endpoints
5
5
  module SendMessages
6
6
  def send_messages(**payload)
7
- send_messages_service.new(api_key, braze_url, payload).perform
7
+ send_messages_service.new(api_key, braze_url, options, payload).perform
8
8
  end
9
9
 
10
10
  private
@@ -4,16 +4,16 @@ module BrazeRuby
4
4
  module Endpoints
5
5
  module Subscription
6
6
  def subscription_status_set(**payload)
7
- BrazeRuby::REST::SubscriptionStatusSet.new(api_key, braze_url, payload).perform
7
+ BrazeRuby::REST::SubscriptionStatusSet.new(api_key, braze_url, options, payload).perform
8
8
  end
9
9
 
10
10
  def subscription_status_get(**payload)
11
- BrazeRuby::REST::SubscriptionStatusGet.new(api_key, braze_url, payload).perform
11
+ BrazeRuby::REST::SubscriptionStatusGet.new(api_key, braze_url, options, payload).perform
12
12
  end
13
13
 
14
14
 
15
15
  def subscription_user_status(**payload)
16
- BrazeRuby::REST::SubscriptionUserStatus.new(api_key, braze_url, payload).perform
16
+ BrazeRuby::REST::SubscriptionUserStatus.new(api_key, braze_url, options, payload).perform
17
17
  end
18
18
  end
19
19
  end
@@ -24,7 +24,7 @@ module BrazeRuby
24
24
  private
25
25
 
26
26
  def track_users_service
27
- @track_users_service ||= BrazeRuby::REST::TrackUsers.new(braze_url)
27
+ @track_users_service ||= BrazeRuby::REST::TrackUsers.new(braze_url, options)
28
28
  end
29
29
  end
30
30
  end
@@ -5,8 +5,11 @@ require 'faraday'
5
5
 
6
6
  module BrazeRuby
7
7
  class HTTP
8
- def initialize(braze_url)
8
+ DEFAULT_TIMEOUT = 30
9
+
10
+ def initialize(braze_url, options = {})
9
11
  @braze_url = braze_url
12
+ @options = default_options.merge(options)
10
13
  end
11
14
 
12
15
  def post(path, payload)
@@ -28,7 +31,15 @@ module BrazeRuby
28
31
  connection.response :logger if ENV['BRAZE_RUBY_DEBUG']
29
32
 
30
33
  connection.adapter Faraday.default_adapter
34
+
35
+ connection.options[:timeout] = @options[:timeout]
31
36
  end
32
37
  end
38
+
39
+ private
40
+
41
+ def default_options
42
+ {timeout: DEFAULT_TIMEOUT}
43
+ end
33
44
  end
34
45
  end
@@ -7,14 +7,15 @@ module BrazeRuby
7
7
  class Base
8
8
  attr_writer :http
9
9
 
10
- def initialize(braze_url)
10
+ def initialize(braze_url, options)
11
11
  @braze_url = braze_url
12
+ @options = options
12
13
  end
13
14
 
14
15
  private
15
16
 
16
17
  def http
17
- @http ||= BrazeRuby::HTTP.new(@braze_url)
18
+ @http ||= BrazeRuby::HTTP.new(@braze_url, @options)
18
19
  end
19
20
  end
20
21
  end
@@ -5,10 +5,10 @@ module BrazeRuby
5
5
  class CanvasDetails < Base
6
6
  attr_reader :api_key, :params
7
7
 
8
- def initialize(api_key, braze_url, **params)
8
+ def initialize(api_key, braze_url, options, **params)
9
9
  @api_key = api_key
10
10
  @params = params
11
- super braze_url
11
+ super braze_url, options
12
12
  end
13
13
 
14
14
  def perform
@@ -5,10 +5,10 @@ module BrazeRuby
5
5
  class EmailHardBounces < Base
6
6
  attr_reader :api_key, :params
7
7
 
8
- def initialize(api_key, braze_url, **params)
8
+ def initialize(api_key, braze_url, options, **params)
9
9
  @api_key = api_key
10
10
  @params = params
11
- super braze_url
11
+ super braze_url, options
12
12
  end
13
13
 
14
14
  def perform
@@ -5,11 +5,11 @@ module BrazeRuby
5
5
  class EmailStatus < Base
6
6
  attr_reader :api_key, :email, :status
7
7
 
8
- def initialize(api_key, braze_url, email: nil, status: nil)
8
+ def initialize(api_key, braze_url, options, email: nil, status: nil)
9
9
  @api_key = api_key
10
10
  @email = email
11
11
  @status = status
12
- super braze_url
12
+ super braze_url, options
13
13
  end
14
14
 
15
15
  def perform
@@ -5,10 +5,10 @@ module BrazeRuby
5
5
  class EmailUnsubscribes < Base
6
6
  attr_reader :api_key, :params
7
7
 
8
- def initialize(api_key, braze_url, **params)
8
+ def initialize(api_key, braze_url, options, **params)
9
9
  @api_key = api_key
10
10
  @params = params
11
- super braze_url
11
+ super braze_url, options
12
12
  end
13
13
 
14
14
  def perform
@@ -5,13 +5,13 @@ module BrazeRuby
5
5
  class ScheduleMessages < Base
6
6
  attr_reader :api_key, :time, :messages, :in_local_time, :external_user_ids
7
7
 
8
- def initialize(api_key, braze_url, time: nil, messages: [], external_user_ids: [], in_local_time: false)
8
+ def initialize(api_key, braze_url, options, time: nil, messages: [], external_user_ids: [], in_local_time: false)
9
9
  @api_key = api_key
10
10
  @messages = messages
11
11
  @time = time
12
12
  @external_user_ids = external_user_ids
13
13
  @in_local_time = in_local_time
14
- super braze_url
14
+ super braze_url, options
15
15
  end
16
16
 
17
17
  def perform
@@ -5,11 +5,11 @@ module BrazeRuby
5
5
  class SendMessages < Base
6
6
  attr_reader :api_key, :messages, :external_user_ids
7
7
 
8
- def initialize(api_key, braze_url, messages: [], external_user_ids: [])
8
+ def initialize(api_key, braze_url, options, messages: [], external_user_ids: [])
9
9
  @api_key = api_key
10
10
  @messages = messages
11
11
  @external_user_ids = external_user_ids
12
- super braze_url
12
+ super braze_url, options
13
13
  end
14
14
 
15
15
  def perform
@@ -5,10 +5,10 @@ module BrazeRuby
5
5
  class SubscriptionStatusGet < Base
6
6
  attr_reader :api_key, :params
7
7
 
8
- def initialize(api_key, braze_url, **params)
8
+ def initialize(api_key, braze_url, options, **params)
9
9
  @api_key = api_key
10
10
  @params = params
11
- super braze_url
11
+ super braze_url, options
12
12
  end
13
13
 
14
14
  def perform
@@ -5,10 +5,10 @@ module BrazeRuby
5
5
  class SubscriptionStatusSet < Base
6
6
  attr_reader :api_key, :params
7
7
 
8
- def initialize(api_key, braze_url, **params)
8
+ def initialize(api_key, braze_url, options, **params)
9
9
  @api_key = api_key
10
10
  @params = params
11
- super braze_url
11
+ super braze_url, options
12
12
  end
13
13
 
14
14
  def perform
@@ -5,10 +5,10 @@ module BrazeRuby
5
5
  class SubscriptionUserStatus < Base
6
6
  attr_reader :api_key, :params
7
7
 
8
- def initialize(api_key, braze_url, **params)
8
+ def initialize(api_key, braze_url, options, **params)
9
9
  @api_key = api_key
10
10
  @params = params
11
- super braze_url
11
+ super braze_url, options
12
12
  end
13
13
 
14
14
  def perform
@@ -5,10 +5,10 @@ module BrazeRuby
5
5
  class TriggerCampaignSend < Base
6
6
  attr_reader :api_key, :params
7
7
 
8
- def initialize(api_key, braze_url, **params)
8
+ def initialize(api_key, braze_url, options, **params)
9
9
  @api_key = api_key
10
10
  @params = params
11
- super braze_url
11
+ super braze_url, options
12
12
  end
13
13
 
14
14
  def perform
@@ -5,10 +5,10 @@ module BrazeRuby
5
5
  class TriggerCanvasSend < Base
6
6
  attr_reader :api_key, :params
7
7
 
8
- def initialize(api_key, braze_url, **params)
8
+ def initialize(api_key, braze_url, options, **params)
9
9
  @api_key = api_key
10
10
  @params = params
11
- super braze_url
11
+ super braze_url, options
12
12
  end
13
13
 
14
14
  def perform
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BrazeRuby
4
- VERSION = '0.3.2'.freeze
4
+ VERSION = '0.3.3'.freeze
5
5
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'braze_ruby/http'
5
+
6
+ describe BrazeRuby::HTTP do
7
+ describe "#connection" do
8
+ let(:options) { double("options", :"[]=" => nil) }
9
+ let(:headers) { double("headers", :"[]=" => nil) }
10
+ let(:conn) { double("conn", adapter: nil, options: options, headers: headers) }
11
+
12
+ before :each do
13
+ allow(Faraday).to receive(:new).and_yield(conn)
14
+ allow(Faraday).to receive(:default_adapter).and_return(:default_adapter)
15
+ end
16
+
17
+ it "it defaults to the timeout option" do
18
+ described_class.new("http://example.com").connection
19
+
20
+ expect(options).to have_received(:"[]=").with(:timeout, described_class::DEFAULT_TIMEOUT)
21
+ end
22
+
23
+ it "it sets the default timeout option when given" do
24
+ timeout = 5
25
+ described_class.new("http://example.com", {timeout: timeout}).connection
26
+
27
+ expect(options).to have_received(:"[]=").with(:timeout, timeout)
28
+ end
29
+
30
+ it "sets the headers" do
31
+ described_class.new("http://example.com").connection
32
+
33
+
34
+ expect(headers).to have_received(:"[]=").with("Content-Type", "application/json")
35
+ expect(headers).to have_received(:"[]=").with("Accept", "application/json")
36
+ expect(headers).to have_received(:"[]=").with("User-Agent", "Braze Ruby gem v#{BrazeRuby::VERSION}")
37
+ end
38
+
39
+ it "it sets the default adapter" do
40
+ described_class.new("http://example.com").connection
41
+
42
+ expect(conn).to have_received(:adapter).with(:default_adapter)
43
+ end
44
+ end
45
+ end
@@ -9,7 +9,7 @@ describe BrazeRuby::REST::DeleteUsers do
9
9
 
10
10
  let(:api_key) { :api_key }
11
11
 
12
- subject { described_class.new :rest_url}
12
+ subject { described_class.new :rest_url, {}}
13
13
 
14
14
  before { subject.http = http }
15
15
 
@@ -7,7 +7,7 @@ describe BrazeRuby::REST::EmailStatus do
7
7
 
8
8
  before { subject.http = http }
9
9
 
10
- subject { described_class.new(:api_key, :rest_url, email: :email, status: :status) }
10
+ subject { described_class.new(:api_key, :rest_url, {}, email: :email, status: :status) }
11
11
 
12
12
  it 'makes an http call to the email status endpoint' do
13
13
  expect(http).to receive(:post).with '/email/status', {
@@ -8,7 +8,7 @@ describe BrazeRuby::REST::ExportUsers do
8
8
  let(:payload) {{ external_ids: external_ids }}
9
9
  let(:external_ids) { [1] }
10
10
 
11
- subject { described_class.new :rest_url }
11
+ subject { described_class.new :rest_url, {} }
12
12
 
13
13
  before { subject.http = http }
14
14
 
@@ -10,7 +10,7 @@ describe BrazeRuby::REST::IdentifyUsers do
10
10
 
11
11
  let(:api_key) { :api_key }
12
12
 
13
- subject { described_class.new :rest_url}
13
+ subject { described_class.new :rest_url, {}}
14
14
 
15
15
  before { subject.http = http }
16
16
 
@@ -14,7 +14,7 @@ describe BrazeRuby::REST::ScheduleMessages do
14
14
 
15
15
  let(:api_key) { :api_key }
16
16
 
17
- subject { described_class.new(api_key, :rest_url, payload) }
17
+ subject { described_class.new(api_key, :rest_url, {}, payload) }
18
18
 
19
19
  before { subject.http = http }
20
20
 
@@ -12,7 +12,9 @@ describe BrazeRuby::REST::SendMessages do
12
12
 
13
13
  let(:api_key) { :api_key }
14
14
 
15
- subject { described_class.new(api_key,
15
+ subject { described_class.new(
16
+ api_key,
17
+ {},
16
18
  messages: :messages,
17
19
  external_user_ids: :external_user_ids
18
20
  ) }
@@ -13,7 +13,7 @@ describe BrazeRuby::REST::TrackUsers do
13
13
 
14
14
  let(:api_key) { :api_key }
15
15
 
16
- subject { described_class.new :rest_url}
16
+ subject { described_class.new :rest_url, {}}
17
17
 
18
18
  before { subject.http = http }
19
19
 
@@ -13,8 +13,12 @@ module Integrations
13
13
  braze_test_segment
14
14
  end
15
15
 
16
+ def options
17
+ {}
18
+ end
19
+
16
20
  def api
17
- BrazeRuby::API.new(api_key, rest_url)
21
+ BrazeRuby::API.new(api_key, rest_url, options)
18
22
  end
19
23
 
20
24
  RSpec.configure do |config|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: braze_ruby
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
  - Josh Nussbaum
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-12-27 00:00:00.000000000 Z
13
+ date: 2020-02-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
@@ -193,6 +193,7 @@ files:
193
193
  - spec/braze_ruby/api_spec.rb
194
194
  - spec/braze_ruby/endpoints/delete_users_spec.rb
195
195
  - spec/braze_ruby/endpoints/track_users_spec.rb
196
+ - spec/braze_ruby/http_spec.rb
196
197
  - spec/braze_ruby/rest/delete_users_spec.rb
197
198
  - spec/braze_ruby/rest/email_status_spec.rb
198
199
  - spec/braze_ruby/rest/export_users_spec.rb
@@ -282,6 +283,7 @@ test_files:
282
283
  - spec/braze_ruby/api_spec.rb
283
284
  - spec/braze_ruby/endpoints/delete_users_spec.rb
284
285
  - spec/braze_ruby/endpoints/track_users_spec.rb
286
+ - spec/braze_ruby/http_spec.rb
285
287
  - spec/braze_ruby/rest/delete_users_spec.rb
286
288
  - spec/braze_ruby/rest/email_status_spec.rb
287
289
  - spec/braze_ruby/rest/export_users_spec.rb