drip-ruby 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,12 +27,12 @@ module Drip
27
27
  # Public: Create or update a refund.
28
28
  #
29
29
  # options - Required. A Hash of refund properties
30
- # amount - Required. The amount of the refund.
30
+ # amount - Required. The amount of the refund.
31
31
  # provider - Required. The provider for the Order being refunded.
32
32
  # order_upstream_id - Required. The upstream_id for the Order being refunded.
33
- # upstream_id - The unique id of refund in the order management system.
34
- # note - A note about the refund.
35
- # processed_at - The String time at which the refund was processed in
33
+ # upstream_id - The unique id of refund in the order management system.
34
+ # note - A note about the refund.
35
+ # processed_at - The String time at which the refund was processed in
36
36
  # ISO-8601 format.
37
37
  #
38
38
  # Returns a Drip::Response.
@@ -0,0 +1,3 @@
1
+ module Drip
2
+ class TooManyRedirectsError < StandardError; end
3
+ end
data/lib/drip/response.rb CHANGED
@@ -51,10 +51,10 @@ module Drip
51
51
  if body.is_a?(Hash)
52
52
  body.each do |key, value|
53
53
  klass = if value.is_a?(Array)
54
- Drip::Collections.find_class(key)
55
- else
56
- Drip::Resources.find_class(key)
57
- end
54
+ Drip::Collections.find_class(key)
55
+ else
56
+ Drip::Resources.find_class(key)
57
+ end
58
58
 
59
59
  members[key] = klass.new(value)
60
60
  end
@@ -65,7 +65,7 @@ module Drip
65
65
 
66
66
  def member_map
67
67
  @member_map ||= {}.tap do |map|
68
- members.each { |key, value| map[key.to_sym] = key }
68
+ members.each { |key, _value| map[key.to_sym] = key }
69
69
  end
70
70
  end
71
71
  end
data/lib/drip/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Drip
2
- VERSION = "2.0.0".freeze
2
+ VERSION = "3.0.0".freeze
3
3
  end
@@ -2,24 +2,16 @@ require File.dirname(__FILE__) + '/../../test_helper.rb'
2
2
 
3
3
  class Drip::Client::AccountsTest < Drip::TestCase
4
4
  def setup
5
- @stubs = Faraday::Adapter::Test::Stubs.new
6
-
7
- @connection = Faraday.new do |builder|
8
- builder.adapter :test, @stubs
9
- end
10
-
11
5
  @client = Drip::Client.new
12
- @client.expects(:connection).at_least_once.returns(@connection)
13
6
  end
14
7
 
15
8
  context "#accounts" do
16
9
  setup do
17
10
  @response_status = 200
18
- @response_body = stub
11
+ @response_body = "stub"
19
12
 
20
- @stubs.get "accounts" do
21
- [@response_status, {}, @response_body]
22
- end
13
+ stub_request(:get, "https://api.getdrip.com/v2/accounts").
14
+ to_return(status: @response_status, body: @response_body, headers: {})
23
15
  end
24
16
 
25
17
  should "send the right request" do
@@ -31,12 +23,11 @@ class Drip::Client::AccountsTest < Drip::TestCase
31
23
  context "#account" do
32
24
  setup do
33
25
  @response_status = 200
34
- @response_body = stub
26
+ @response_body = "stub"
35
27
  @id = 9999999
36
28
 
37
- @stubs.get "accounts/#{@id}" do
38
- [@response_status, {}, @response_body]
39
- end
29
+ stub_request(:get, "https://api.getdrip.com/v2/accounts/#{@id}").
30
+ to_return(status: @response_status, body: @response_body, headers: {})
40
31
  end
41
32
 
42
33
  should "send the right request" do
@@ -2,24 +2,16 @@ require File.dirname(__FILE__) + '/../../test_helper.rb'
2
2
 
3
3
  class Drip::Client::BroadcastsTest < Drip::TestCase
4
4
  def setup
5
- @stubs = Faraday::Adapter::Test::Stubs.new
6
-
7
- @connection = Faraday.new do |builder|
8
- builder.adapter :test, @stubs
9
- end
10
-
11
5
  @client = Drip::Client.new { |c| c.account_id = "12345" }
12
- @client.expects(:connection).at_least_once.returns(@connection)
13
6
  end
14
7
 
15
8
  context "#broadcasts" do
16
9
  setup do
17
10
  @response_status = 200
18
- @response_body = stub
11
+ @response_body = "stub"
19
12
 
20
- @stubs.get "12345/broadcasts" do
21
- [@response_status, {}, @response_body]
22
- end
13
+ stub_request(:get, "https://api.getdrip.com/v2/12345/broadcasts").
14
+ to_return(status: @response_status, body: @response_body, headers: {})
23
15
  end
24
16
 
25
17
  should "send the correct request" do
@@ -31,12 +23,11 @@ class Drip::Client::BroadcastsTest < Drip::TestCase
31
23
  context "#broadcast" do
32
24
  setup do
33
25
  @response_status = 200
34
- @response_body = stub
26
+ @response_body = "stub"
35
27
  @id = 99999
36
28
 
37
- @stubs.get "12345/broadcasts/#{@id}" do
38
- [@response_status, {}, @response_body]
39
- end
29
+ stub_request(:get, "https://api.getdrip.com/v2/12345/broadcasts/#{@id}").
30
+ to_return(status: @response_status, body: @response_body, headers: {})
40
31
  end
41
32
 
42
33
  should "send the correct request" do
@@ -2,25 +2,17 @@ require File.dirname(__FILE__) + '/../../test_helper.rb'
2
2
 
3
3
  class Drip::Client::CampaignSubscriptionsTest < Drip::TestCase
4
4
  def setup
5
- @stubs = Faraday::Adapter::Test::Stubs.new
6
-
7
- @connection = Faraday.new do |builder|
8
- builder.adapter :test, @stubs
9
- end
10
-
11
5
  @client = Drip::Client.new { |c| c.account_id = "12345" }
12
- @client.expects(:connection).at_least_once.returns(@connection)
13
6
  end
14
7
 
15
8
  context "#campaign_subscriptions" do
16
9
  setup do
17
10
  @response_status = 200
18
- @response_body = stub
11
+ @response_body = "stub"
19
12
  @subscriber_id = "abc123"
20
13
 
21
- @stubs.get "12345/subscribers/#{@subscriber_id}/campaign_subscriptions" do
22
- [@response_status, {}, @response_body]
23
- end
14
+ stub_request(:get, "https://api.getdrip.com/v2/12345/subscribers/#{@subscriber_id}/campaign_subscriptions").
15
+ to_return(status: @response_status, body: @response_body, headers: {})
24
16
  end
25
17
 
26
18
  should "send the right request" do
@@ -2,24 +2,16 @@ require File.dirname(__FILE__) + '/../../test_helper.rb'
2
2
 
3
3
  class Drip::Client::CampaignsTest < Drip::TestCase
4
4
  def setup
5
- @stubs = Faraday::Adapter::Test::Stubs.new
6
-
7
- @connection = Faraday.new do |builder|
8
- builder.adapter :test, @stubs
9
- end
10
-
11
5
  @client = Drip::Client.new { |c| c.account_id = "12345" }
12
- @client.expects(:connection).at_least_once.returns(@connection)
13
6
  end
14
7
 
15
8
  context "#campaigns" do
16
9
  setup do
17
10
  @response_status = 200
18
- @response_body = stub
11
+ @response_body = "stub"
19
12
 
20
- @stubs.get "12345/campaigns" do
21
- [@response_status, {}, @response_body]
22
- end
13
+ stub_request(:get, "https://api.getdrip.com/v2/12345/campaigns").
14
+ to_return(status: @response_status, body: @response_body, headers: {})
23
15
  end
24
16
 
25
17
  should "send the right request" do
@@ -31,12 +23,11 @@ class Drip::Client::CampaignsTest < Drip::TestCase
31
23
  context "#campaign" do
32
24
  setup do
33
25
  @response_status = 200
34
- @response_body = stub
26
+ @response_body = "stub"
35
27
  @id = 9999999
36
28
 
37
- @stubs.get "12345/campaigns/#{@id}" do
38
- [@response_status, {}, @response_body]
39
- end
29
+ stub_request(:get, "https://api.getdrip.com/v2/12345/campaigns/#{@id}").
30
+ to_return(status: @response_status, body: @response_body, headers: {})
40
31
  end
41
32
 
42
33
  should "send the right request" do
@@ -48,12 +39,11 @@ class Drip::Client::CampaignsTest < Drip::TestCase
48
39
  context "#activate_campaign" do
49
40
  setup do
50
41
  @response_status = 204
51
- @response_body = stub
42
+ @response_body = nil
52
43
  @id = 9999999
53
44
 
54
- @stubs.post "12345/campaigns/#{@id}/activate" do
55
- [@response_status, {}, @response_body]
56
- end
45
+ stub_request(:post, "https://api.getdrip.com/v2/12345/campaigns/#{@id}/activate").
46
+ to_return(status: @response_status, body: @response_body, headers: {})
57
47
  end
58
48
 
59
49
  should "send the right request" do
@@ -65,12 +55,11 @@ class Drip::Client::CampaignsTest < Drip::TestCase
65
55
  context "#pause_campaign" do
66
56
  setup do
67
57
  @response_status = 204
68
- @response_body = stub
58
+ @response_body = nil
69
59
  @id = 9999999
70
60
 
71
- @stubs.post "12345/campaigns/#{@id}/pause" do
72
- [@response_status, {}, @response_body]
73
- end
61
+ stub_request(:post, "https://api.getdrip.com/v2/12345/campaigns/#{@id}/pause").
62
+ to_return(status: @response_status, body: @response_body, headers: {})
74
63
  end
75
64
 
76
65
  should "send the right request" do
@@ -82,12 +71,11 @@ class Drip::Client::CampaignsTest < Drip::TestCase
82
71
  context "#campaign_subscribers" do
83
72
  setup do
84
73
  @response_status = 200
85
- @response_body = stub
74
+ @response_body = "stub"
86
75
  @id = 9999999
87
76
 
88
- @stubs.get "12345/campaigns/#{@id}/subscribers" do
89
- [@response_status, {}, @response_body]
90
- end
77
+ stub_request(:get, "https://api.getdrip.com/v2/12345/campaigns/#{@id}/subscribers").
78
+ to_return(status: @response_status, body: @response_body, headers: {})
91
79
  end
92
80
 
93
81
  should "send the right request" do
@@ -2,24 +2,16 @@ require File.dirname(__FILE__) + '/../../test_helper.rb'
2
2
 
3
3
  class Drip::Client::ConversionsTest < Drip::TestCase
4
4
  def setup
5
- @stubs = Faraday::Adapter::Test::Stubs.new
6
-
7
- @connection = Faraday.new do |builder|
8
- builder.adapter :test, @stubs
9
- end
10
-
11
5
  @client = Drip::Client.new { |c| c.account_id = "12345" }
12
- @client.expects(:connection).at_least_once.returns(@connection)
13
6
  end
14
7
 
15
8
  context "#conversions" do
16
9
  setup do
17
10
  @response_status = 200
18
- @response_body = stub
11
+ @response_body = "stub"
19
12
 
20
- @stubs.get "12345/goals" do
21
- [@response_status, {}, @response_body]
22
- end
13
+ stub_request(:get, "https://api.getdrip.com/v2/12345/goals").
14
+ to_return(status: @response_status, body: @response_body, headers: {})
23
15
  end
24
16
 
25
17
  should "send the right request" do
@@ -31,12 +23,11 @@ class Drip::Client::ConversionsTest < Drip::TestCase
31
23
  context "#conversion" do
32
24
  setup do
33
25
  @response_status = 200
34
- @response_body = stub
26
+ @response_body = "stub"
35
27
  @id = 9999999
36
28
 
37
- @stubs.get "12345/goals/#{@id}" do
38
- [@response_status, {}, @response_body]
39
- end
29
+ stub_request(:get, "https://api.getdrip.com/v2/12345/goals/#{@id}").
30
+ to_return(status: @response_status, body: @response_body, headers: {})
40
31
  end
41
32
 
42
33
  should "send the right request" do
@@ -2,24 +2,16 @@ require File.dirname(__FILE__) + '/../../test_helper.rb'
2
2
 
3
3
  class Drip::Client::CustomFieldsTest < Drip::TestCase
4
4
  def setup
5
- @stubs = Faraday::Adapter::Test::Stubs.new
6
-
7
- @connection = Faraday.new do |builder|
8
- builder.adapter :test, @stubs
9
- end
10
-
11
5
  @client = Drip::Client.new { |c| c.account_id = "12345" }
12
- @client.expects(:connection).at_least_once.returns(@connection)
13
6
  end
14
7
 
15
8
  context "#custom_fields" do
16
9
  setup do
17
10
  @response_status = 200
18
- @response_body = stub
11
+ @response_body = "stub"
19
12
 
20
- @stubs.get "12345/custom_field_identifiers" do
21
- [@response_status, {}, @response_body]
22
- end
13
+ stub_request(:get, "https://api.getdrip.com/v2/12345/custom_field_identifiers").
14
+ to_return(status: @response_status, body: @response_body, headers: {})
23
15
  end
24
16
 
25
17
  should "send the right request" do
@@ -2,14 +2,7 @@ require File.dirname(__FILE__) + '/../../test_helper.rb'
2
2
 
3
3
  class Drip::Client::EventsTest < Drip::TestCase
4
4
  def setup
5
- @stubs = Faraday::Adapter::Test::Stubs.new
6
-
7
- @connection = Faraday.new do |builder|
8
- builder.adapter :test, @stubs
9
- end
10
-
11
5
  @client = Drip::Client.new { |c| c.account_id = "12345" }
12
- @client.expects(:connection).at_least_once.returns(@connection)
13
6
  end
14
7
 
15
8
  context "#track_event" do
@@ -30,11 +23,10 @@ class Drip::Client::EventsTest < Drip::TestCase
30
23
  }.to_json
31
24
 
32
25
  @response_status = 201
33
- @response_body = stub
26
+ @response_body = "stub"
34
27
 
35
- @stubs.post "12345/events", @payload do
36
- [@response_status, {}, @response_body]
37
- end
28
+ stub_request(:post, "https://api.getdrip.com/v2/12345/events").
29
+ to_return(status: @response_status, body: @response_body, headers: {})
38
30
  end
39
31
 
40
32
  should "send the right request" do
@@ -58,11 +50,10 @@ class Drip::Client::EventsTest < Drip::TestCase
58
50
  }.to_json
59
51
 
60
52
  @response_status = 201
61
- @response_body = stub
53
+ @response_body = "stub"
62
54
 
63
- @stubs.post "12345/events", @payload do
64
- [@response_status, {}, @response_body]
65
- end
55
+ stub_request(:post, "https://api.getdrip.com/v2/12345/events").
56
+ to_return(status: @response_status, body: @response_body, headers: {})
66
57
  end
67
58
 
68
59
  should "send the right request" do
@@ -87,11 +78,10 @@ class Drip::Client::EventsTest < Drip::TestCase
87
78
 
88
79
  @payload = { "batches" => [{ "events" => @events }] }.to_json
89
80
  @response_status = 201
90
- @response_body = stub
81
+ @response_body = "stub"
91
82
 
92
- @stubs.post "12345/events/batches", @payload do
93
- [@response_status, {}, @response_body]
94
- end
83
+ stub_request(:post, "https://api.getdrip.com/v2/12345/events/batches").
84
+ to_return(status: @response_status, body: @response_body, headers: {})
95
85
  end
96
86
 
97
87
  should "send the right request" do
@@ -103,11 +93,10 @@ class Drip::Client::EventsTest < Drip::TestCase
103
93
  context "#event_actions" do
104
94
  setup do
105
95
  @response_status = 200
106
- @response_body = stub
96
+ @response_body = "stub"
107
97
 
108
- @stubs.get "12345/event_actions" do
109
- [@response_status, {}, @response_body]
110
- end
98
+ stub_request(:get, "https://api.getdrip.com/v2/12345/event_actions").
99
+ to_return(status: @response_status, body: @response_body, headers: {})
111
100
  end
112
101
 
113
102
  should "send the right request" do
@@ -2,24 +2,16 @@ require File.dirname(__FILE__) + '/../../test_helper.rb'
2
2
 
3
3
  class Drip::Client::FormsTest < Drip::TestCase
4
4
  def setup
5
- @stubs = Faraday::Adapter::Test::Stubs.new
6
-
7
- @connection = Faraday.new do |builder|
8
- builder.adapter :test, @stubs
9
- end
10
-
11
5
  @client = Drip::Client.new { |c| c.account_id = "12345" }
12
- @client.expects(:connection).at_least_once.returns(@connection)
13
6
  end
14
7
 
15
8
  context "#forms" do
16
9
  setup do
17
10
  @response_status = 200
18
- @response_body = stub
11
+ @response_body = "stub"
19
12
 
20
- @stubs.get "12345/forms" do
21
- [@response_status, {}, @response_body]
22
- end
13
+ stub_request(:get, "https://api.getdrip.com/v2/12345/forms").
14
+ to_return(status: @response_status, body: @response_body, headers: {})
23
15
  end
24
16
 
25
17
  should "send the right request" do
@@ -31,12 +23,11 @@ class Drip::Client::FormsTest < Drip::TestCase
31
23
  context "#form" do
32
24
  setup do
33
25
  @response_status = 200
34
- @response_body = stub
26
+ @response_body = "stub"
35
27
  @id = 9999999
36
28
 
37
- @stubs.get "12345/forms/#{@id}" do
38
- [@response_status, {}, @response_body]
39
- end
29
+ stub_request(:get, "https://api.getdrip.com/v2/12345/forms/#{@id}").
30
+ to_return(status: @response_status, body: @response_body, headers: {})
40
31
  end
41
32
 
42
33
  should "send the right request" do