drip-ruby 3.2.0 → 3.4.2

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.
Files changed (104) hide show
  1. checksums.yaml +5 -5
  2. data/.github/pull_request_template.md +39 -0
  3. data/.rubocop.yml +5 -1
  4. data/.rubocop_todo.yml +17 -9
  5. data/.travis.yml +2 -4
  6. data/CHANGELOG.md +51 -1
  7. data/Gemfile +12 -0
  8. data/README.md +6 -0
  9. data/Rakefile +2 -0
  10. data/drip-ruby.gemspec +4 -11
  11. data/lib/drip.rb +2 -0
  12. data/lib/drip/client.rb +48 -66
  13. data/lib/drip/client/accounts.rb +4 -2
  14. data/lib/drip/client/broadcasts.rb +4 -2
  15. data/lib/drip/client/campaign_subscriptions.rb +3 -1
  16. data/lib/drip/client/campaigns.rb +7 -5
  17. data/lib/drip/client/configuration.rb +30 -0
  18. data/lib/drip/client/conversions.rb +4 -2
  19. data/lib/drip/client/custom_fields.rb +3 -1
  20. data/lib/drip/client/events.rb +6 -4
  21. data/lib/drip/client/forms.rb +4 -2
  22. data/lib/drip/client/http_client.rb +66 -0
  23. data/lib/drip/client/orders.rb +5 -3
  24. data/lib/drip/client/shopper_activity.rb +80 -0
  25. data/lib/drip/client/subscribers.rb +30 -16
  26. data/lib/drip/client/tags.rb +5 -3
  27. data/lib/drip/client/users.rb +17 -0
  28. data/lib/drip/client/webhooks.rb +7 -5
  29. data/lib/drip/client/workflow_triggers.rb +5 -3
  30. data/lib/drip/client/workflows.rb +8 -6
  31. data/lib/drip/collection.rb +2 -0
  32. data/lib/drip/collections.rb +2 -0
  33. data/lib/drip/collections/accounts.rb +2 -0
  34. data/lib/drip/collections/broadcasts.rb +2 -0
  35. data/lib/drip/collections/campaign_subscriptions.rb +2 -0
  36. data/lib/drip/collections/campaigns.rb +2 -0
  37. data/lib/drip/collections/errors.rb +2 -0
  38. data/lib/drip/collections/orders.rb +2 -0
  39. data/lib/drip/collections/purchases.rb +2 -0
  40. data/lib/drip/collections/subscribers.rb +2 -0
  41. data/lib/drip/collections/tags.rb +2 -0
  42. data/lib/drip/collections/webhooks.rb +2 -0
  43. data/lib/drip/collections/workflow_triggers.rb +2 -0
  44. data/lib/drip/collections/workflows.rb +2 -0
  45. data/lib/drip/errors.rb +2 -0
  46. data/lib/drip/request.rb +33 -0
  47. data/lib/drip/resource.rb +2 -0
  48. data/lib/drip/resources.rb +2 -0
  49. data/lib/drip/resources/account.rb +2 -0
  50. data/lib/drip/resources/broadcast.rb +2 -0
  51. data/lib/drip/resources/campaign.rb +2 -0
  52. data/lib/drip/resources/campaign_subscription.rb +2 -0
  53. data/lib/drip/resources/error.rb +2 -0
  54. data/lib/drip/resources/order.rb +2 -0
  55. data/lib/drip/resources/purchase.rb +2 -0
  56. data/lib/drip/resources/subscriber.rb +2 -0
  57. data/lib/drip/resources/tag.rb +2 -0
  58. data/lib/drip/resources/webhook.rb +2 -0
  59. data/lib/drip/resources/workflow.rb +2 -0
  60. data/lib/drip/resources/workflow_trigger.rb +2 -0
  61. data/lib/drip/response.rb +15 -13
  62. data/lib/drip/version.rb +3 -1
  63. data/test/drip/client/accounts_test.rb +2 -0
  64. data/test/drip/client/broadcasts_test.rb +2 -0
  65. data/test/drip/client/campaign_subscriptions_test.rb +2 -0
  66. data/test/drip/client/campaigns_test.rb +2 -0
  67. data/test/drip/client/configuration_test.rb +112 -0
  68. data/test/drip/client/conversions_test.rb +2 -0
  69. data/test/drip/client/custom_fields_test.rb +2 -0
  70. data/test/drip/client/events_test.rb +2 -0
  71. data/test/drip/client/forms_test.rb +2 -0
  72. data/test/drip/client/http_client_test.rb +98 -0
  73. data/test/drip/client/orders_test.rb +2 -0
  74. data/test/drip/client/shopper_activity_test.rb +189 -0
  75. data/test/drip/client/subscribers_test.rb +8 -0
  76. data/test/drip/client/tags_test.rb +2 -0
  77. data/test/drip/client/users_test.rb +24 -0
  78. data/test/drip/client/webhooks_test.rb +2 -0
  79. data/test/drip/client/workflow_triggers_test.rb +2 -0
  80. data/test/drip/client/workflows_test.rb +2 -0
  81. data/test/drip/client_test.rb +34 -97
  82. data/test/drip/collection_test.rb +16 -0
  83. data/test/drip/collections/account_test.rb +10 -0
  84. data/test/drip/collections/broadcasts_test.rb +10 -0
  85. data/test/drip/collections/campaign_subscriptions_test.rb +10 -0
  86. data/test/drip/collections/campaigns_test.rb +10 -0
  87. data/test/drip/collections/errors_test.rb +10 -0
  88. data/test/drip/collections/orders_test.rb +10 -0
  89. data/test/drip/collections/purchases_test.rb +10 -0
  90. data/test/drip/collections/tags_test.rb +10 -0
  91. data/test/drip/collections/webhooks_test.rb +10 -0
  92. data/test/drip/collections/workflow_triggers_test.rb +10 -0
  93. data/test/drip/collections/workflows_test.rb +10 -0
  94. data/test/drip/collections_test.rb +2 -0
  95. data/test/drip/request_test.rb +60 -0
  96. data/test/drip/resource_test.rb +14 -0
  97. data/test/drip/resources/account_test.rb +2 -0
  98. data/test/drip/resources/order_test.rb +2 -0
  99. data/test/drip/resources/subscriber_test.rb +2 -0
  100. data/test/drip/resources/tag_test.rb +15 -0
  101. data/test/drip/resources_test.rb +2 -0
  102. data/test/drip/response_test.rb +35 -0
  103. data/test/test_helper.rb +5 -0
  104. metadata +50 -109
data/lib/drip/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Drip
2
- VERSION = "3.2.0".freeze
4
+ VERSION = "3.4.2"
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require File.dirname(__FILE__) + '/../../test_helper.rb'
2
4
 
3
5
  class Drip::Client::AccountsTest < Drip::TestCase
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require File.dirname(__FILE__) + '/../../test_helper.rb'
2
4
 
3
5
  class Drip::Client::BroadcastsTest < Drip::TestCase
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require File.dirname(__FILE__) + '/../../test_helper.rb'
2
4
 
3
5
  class Drip::Client::CampaignSubscriptionsTest < Drip::TestCase
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require File.dirname(__FILE__) + '/../../test_helper.rb'
2
4
 
3
5
  class Drip::Client::CampaignsTest < Drip::TestCase
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.dirname(__FILE__) + '/../../test_helper.rb'
4
+ require "drip/client/configuration"
5
+
6
+ class Drip::Client::ConfigurationTest < Drip::TestCase
7
+ context "#initializer" do
8
+ context "with reasonable parameters" do
9
+ should "accept parameters" do
10
+ config = Drip::Client::Configuration.new(access_token: "123")
11
+ assert_equal "123", config.access_token
12
+ end
13
+ end
14
+
15
+ context "with one additional parameter" do
16
+ should "raise singular error" do
17
+ err = assert_raises(ArgumentError) { Drip::Client::Configuration.new(blahdeblah: "123") }
18
+ assert_equal "unknown keyword: blahdeblah", err.message
19
+ end
20
+ end
21
+
22
+ context "with multiple additional parameters" do
23
+ should "raise plural error" do
24
+ err = assert_raises(ArgumentError) { Drip::Client::Configuration.new(blahdeblah: "123", blahdeblah1: "123") }
25
+ assert_equal "unknown keywords: blahdeblah, blahdeblah1", err.message
26
+ end
27
+ end
28
+ end
29
+
30
+ context "#url_prefix" do
31
+ should "have default url prefix" do
32
+ config = Drip::Client::Configuration.new
33
+ assert_equal "https://api.getdrip.com/", config.url_prefix
34
+ end
35
+
36
+ should "accept passed parameter" do
37
+ config = Drip::Client::Configuration.new(url_prefix: "https://www.example.com/")
38
+ assert_equal "https://www.example.com/", config.url_prefix
39
+ end
40
+
41
+ should "allow setter" do
42
+ config = Drip::Client::Configuration.new
43
+ config.url_prefix = "https://www.example.com/"
44
+ assert_equal "https://www.example.com/", config.url_prefix
45
+ end
46
+ end
47
+
48
+ context "#access_token" do
49
+ should "accept passed parameter" do
50
+ config = Drip::Client::Configuration.new(access_token: "blah")
51
+ assert_equal "blah", config.access_token
52
+ end
53
+
54
+ should "allow setter" do
55
+ config = Drip::Client::Configuration.new
56
+ config.access_token = "blah"
57
+ assert_equal "blah", config.access_token
58
+ end
59
+ end
60
+
61
+ context "#api_key" do
62
+ should "accept passed parameter" do
63
+ config = Drip::Client::Configuration.new(api_key: "blah")
64
+ assert_equal "blah", config.api_key
65
+ end
66
+
67
+ should "allow setter" do
68
+ config = Drip::Client::Configuration.new
69
+ config.api_key = "blah"
70
+ assert_equal "blah", config.api_key
71
+ end
72
+ end
73
+
74
+ context "#account_id" do
75
+ should "accept passed parameter" do
76
+ config = Drip::Client::Configuration.new(account_id: "1234567")
77
+ assert_equal "1234567", config.account_id
78
+ end
79
+
80
+ should "allow setter" do
81
+ config = Drip::Client::Configuration.new
82
+ config.account_id = "1234567"
83
+ assert_equal "1234567", config.account_id
84
+ end
85
+ end
86
+
87
+ context "#http_open_timeout" do
88
+ should "accept passed parameter" do
89
+ config = Drip::Client::Configuration.new(http_open_timeout: 12)
90
+ assert_equal 12, config.http_open_timeout
91
+ end
92
+
93
+ should "allow setter" do
94
+ config = Drip::Client::Configuration.new
95
+ config.http_open_timeout = 12
96
+ assert_equal 12, config.http_open_timeout
97
+ end
98
+ end
99
+
100
+ context "#http_timeout" do
101
+ should "accept passed parameter" do
102
+ config = Drip::Client::Configuration.new(http_timeout: 42)
103
+ assert_equal 42, config.http_timeout
104
+ end
105
+
106
+ should "allow setter" do
107
+ config = Drip::Client::Configuration.new
108
+ config.http_timeout = 42
109
+ assert_equal 42, config.http_timeout
110
+ end
111
+ end
112
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require File.dirname(__FILE__) + '/../../test_helper.rb'
2
4
 
3
5
  class Drip::Client::ConversionsTest < Drip::TestCase
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require File.dirname(__FILE__) + '/../../test_helper.rb'
2
4
 
3
5
  class Drip::Client::CustomFieldsTest < Drip::TestCase
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require File.dirname(__FILE__) + '/../../test_helper.rb'
2
4
 
3
5
  class Drip::Client::EventsTest < Drip::TestCase
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require File.dirname(__FILE__) + '/../../test_helper.rb'
2
4
 
3
5
  class Drip::Client::FormsTest < Drip::TestCase
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.dirname(__FILE__) + '/../../test_helper.rb'
4
+ require "drip/client/configuration"
5
+ require "drip/client/http_client"
6
+ require "drip/request"
7
+
8
+ class Drip::Client::HTTPClientTest < Drip::TestCase
9
+ context "given a personal api key" do
10
+ setup do
11
+ @key = "aaaa"
12
+ @config = Drip::Client::Configuration.new(api_key: @key)
13
+ @client = Drip::Client::HTTPClient.new(@config)
14
+ end
15
+
16
+ should "use Basic authentication" do
17
+ stub_request(:get, "https://api.getdrip.com/v2/testpath").
18
+ to_return(status: 200, body: "", headers: {})
19
+
20
+ @client.make_request(Drip::Request.new(:get, URI("https://api.getdrip.com/v2/testpath")))
21
+
22
+ header = "Basic #{Base64.encode64(@key + ':')}".strip
23
+ assert_requested :get, "https://api.getdrip.com/v2/testpath", headers: { 'Authorization' => header }
24
+ end
25
+ end
26
+
27
+ context "given a OAuth access token" do
28
+ setup do
29
+ @key = "aaaa"
30
+ @config = Drip::Client::Configuration.new(access_token: @key)
31
+ @client = Drip::Client::HTTPClient.new(@config)
32
+ end
33
+
34
+ should "use Bearer token authentication" do
35
+ stub_request(:get, "https://api.getdrip.com/v2/testpath").
36
+ to_return(status: 200, body: "", headers: {})
37
+ @client.make_request(Drip::Request.new(:get, URI("https://api.getdrip.com/v2/testpath")))
38
+ header = "Bearer #{@key}"
39
+ assert_requested :get, "https://api.getdrip.com/v2/testpath", headers: { 'Authorization' => header }
40
+ end
41
+ end
42
+
43
+ context "given a redirecting url" do
44
+ setup do
45
+ @config = Drip::Client::Configuration.new
46
+ @client = Drip::Client::HTTPClient.new(@config)
47
+ end
48
+
49
+ should "follow redirect" do
50
+ stub_request(:get, "https://api.getdrip.com/v2/testpath").
51
+ to_return(status: 301, body: "", headers: { "Location" => "https://api.example.com/mytestpath" })
52
+ stub_request(:get, "https://api.example.com/mytestpath").
53
+ to_return(status: 200, body: "{}")
54
+ response = @client.make_request(Drip::Request.new(:get, URI("https://api.getdrip.com/v2/testpath")))
55
+ assert_requested :get, "https://api.getdrip.com/v2/testpath"
56
+ assert_requested :get, "https://api.example.com/mytestpath"
57
+ assert_equal("{}", response.body)
58
+ end
59
+
60
+ should "not follow too many redirects" do
61
+ stub_request(:get, "https://api.getdrip.com/v2/accounts").
62
+ to_return(status: 301, body: "", headers: { "Location" => "https://api.example.com/mytestpath" })
63
+ stub_request(:get, "https://api.example.com/mytestpath").
64
+ to_return(status: 302, body: "", headers: { "Location" => "https://api.getdrip.com/v2/accounts" })
65
+ assert_raises(Drip::TooManyRedirectsError) { @client.make_request(Drip::Request.new(:get, URI("https://api.getdrip.com/v2/accounts"))) }
66
+ assert_requested :get, "https://api.getdrip.com/v2/accounts", times: 5
67
+ assert_requested :get, "https://api.example.com/mytestpath", times: 5
68
+ end
69
+ end
70
+
71
+ context "given a get request" do
72
+ setup do
73
+ @config = Drip::Client::Configuration.new(http_open_timeout: 20)
74
+ @client = Drip::Client::HTTPClient.new(@config)
75
+ @response = mock
76
+ @response.stubs(:code).returns('200')
77
+ @response.stubs(:body).returns('{}')
78
+
79
+ @http = mock
80
+ @http.expects(:request).returns(@response)
81
+
82
+ @request = mock
83
+ @request.stubs(:[]=)
84
+ @request.stubs(:basic_auth)
85
+ end
86
+
87
+ should "encode query and not set body" do
88
+ Net::HTTP::Get.expects(:new).returns(@request)
89
+ Net::HTTP.expects(:start).yields(@http).returns(@response)
90
+
91
+ @request.expects(:body=).with(nil)
92
+ URI.expects(:encode_www_form).once
93
+
94
+ response = @client.make_request(Drip::Request.new(:get, URI("https://api.getdrip.com/v2/testpath")))
95
+ assert_equal("{}", response.body)
96
+ end
97
+ end
98
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require File.dirname(__FILE__) + '/../../test_helper.rb'
2
4
 
3
5
  class Drip::Client::OrdersTest < Drip::TestCase
@@ -0,0 +1,189 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.dirname(__FILE__) + '/../../test_helper.rb'
4
+
5
+ class Drip::Client::ShopperActivityTest < Drip::TestCase
6
+ def setup
7
+ @client = Drip::Client.new { |c| c.account_id = "12345" }
8
+ end
9
+
10
+ context "#create_cart_activity_event" do
11
+ setup do
12
+ @email = "drippy@drip.com"
13
+ @options = {
14
+ email: @email,
15
+ action: "created",
16
+ provider: "shopify",
17
+ cart_id: "abcdef",
18
+ cart_url: "https://www.example.com/mythingy",
19
+ amount: 4900,
20
+ tax: 100,
21
+ fees: 0,
22
+ discount: 0,
23
+ currency_code: "USD",
24
+ properties: {
25
+ "size" => "medium",
26
+ "color" => "red"
27
+ }
28
+ }
29
+ @response_status = 202
30
+ @response_body = "{}"
31
+
32
+ stub_request(:post, "https://api.getdrip.com/v3/12345/shopper_activity/cart").
33
+ with(headers: { "Content-Type" => "application/json" }).
34
+ to_return(status: @response_status, body: @response_body, headers: {})
35
+ end
36
+
37
+ should "send the right request" do
38
+ expected = Drip::Response.new(@response_status, JSON.parse(@response_body))
39
+ assert_equal expected, @client.create_cart_activity_event(@options)
40
+ end
41
+
42
+ should "return error when missing fields" do
43
+ @options.delete(:cart_id)
44
+ assert_raises(ArgumentError) { @client.create_cart_activity_event(@options) }
45
+ end
46
+
47
+ should "return error when missing person identifier" do
48
+ @options.delete(:email)
49
+ assert_raises(ArgumentError) { @client.create_cart_activity_event(@options) }
50
+
51
+ @options[:person_id] = "acd123"
52
+ @client.create_cart_activity_event(@options)
53
+
54
+ @options.delete(:person_id)
55
+ @options[:visitor_uuid] = "v1234"
56
+ @client.create_cart_activity_event(@options)
57
+ end
58
+ end
59
+
60
+ context "#create_order_activity_event" do
61
+ setup do
62
+ @email = "drippy@drip.com"
63
+ @options = {
64
+ email: @email,
65
+ action: "created",
66
+ provider: "shopify",
67
+ order_id: "abcdef",
68
+ amount: 4900,
69
+ tax: 100,
70
+ fees: 0,
71
+ discount: 0,
72
+ currency_code: "USD",
73
+ properties: {
74
+ "size" => "medium",
75
+ "color" => "red"
76
+ }
77
+ }
78
+ @response_status = 202
79
+ @response_body = "{}"
80
+
81
+ stub_request(:post, "https://api.getdrip.com/v3/12345/shopper_activity/order").
82
+ with(headers: { "Content-Type" => "application/json" }).
83
+ to_return(status: @response_status, body: @response_body, headers: {})
84
+ end
85
+
86
+ should "send the right request" do
87
+ expected = Drip::Response.new(@response_status, JSON.parse(@response_body))
88
+ assert_equal expected, @client.create_order_activity_event(@options)
89
+ end
90
+
91
+ should "return error when missing fields" do
92
+ @options.delete(:order_id)
93
+ assert_raises(ArgumentError) { @client.create_order_activity_event(@options) }
94
+ end
95
+ end
96
+
97
+ context "#create_order_activity_events" do
98
+ setup do
99
+ @records = [
100
+ {
101
+ email: "drippy@example.com",
102
+ action: "created",
103
+ provider: "shopify",
104
+ order_id: "abcdef",
105
+ amount: 4900,
106
+ tax: 100,
107
+ fees: 0,
108
+ discount: 0,
109
+ currency_code: "USD",
110
+ properties: {
111
+ "size" => "medium",
112
+ "color" => "red"
113
+ }
114
+ },
115
+ {
116
+ email: "drippy1@example.com",
117
+ action: "created",
118
+ provider: "shopify",
119
+ order_id: "fdsgs",
120
+ amount: 4900,
121
+ tax: 100,
122
+ fees: 0,
123
+ discount: 0,
124
+ currency_code: "USD",
125
+ properties: {
126
+ "size" => "medium",
127
+ "color" => "red"
128
+ }
129
+ }
130
+ ]
131
+ @response_status = 202
132
+ @response_body = "{}"
133
+
134
+ stub_request(:post, "https://api.getdrip.com/v3/12345/shopper_activity/order/batch").
135
+ with(headers: { "Content-Type" => "application/json" }).
136
+ to_return(status: @response_status, body: @response_body, headers: {})
137
+ end
138
+
139
+ should "send the right request" do
140
+ expected = Drip::Response.new(@response_status, JSON.parse(@response_body))
141
+ assert_equal expected, @client.create_order_activity_events(@records)
142
+ end
143
+
144
+ should "return error when missing fields" do
145
+ @records[1].delete(:order_id)
146
+ err = assert_raises(ArgumentError) { @client.create_order_activity_events(@records) }
147
+ assert_equal "order_id: parameter required in record 1", err.message
148
+ end
149
+ end
150
+
151
+ context "#create_product_activity_event" do
152
+ setup do
153
+ @email = "drippy@drip.com"
154
+ @options = {
155
+ provider: "my_custom_platform",
156
+ action: "created",
157
+ occurred_at: "2019-01-28T12:15:23Z",
158
+ product_id: "B01J4SWO1G",
159
+ product_variant_id: "B01J4SWO1G-CW-BOTT",
160
+ sku: "XHB-1234",
161
+ name: "The Coolest Water Bottle",
162
+ brand: "Drip",
163
+ categories: [
164
+ "Accessories"
165
+ ],
166
+ price: 11.16,
167
+ inventory: 42,
168
+ product_url: "https://mysuperstore.example.com/dp/B01J4SWO1G",
169
+ image_url: "https://www.getdrip.com/images/example_products/water_bottle.png"
170
+ }
171
+ @response_status = 202
172
+ @response_body = "{}"
173
+
174
+ stub_request(:post, "https://api.getdrip.com/v3/12345/shopper_activity/product").
175
+ with(headers: { "Content-Type" => "application/json" }).
176
+ to_return(status: @response_status, body: @response_body, headers: {})
177
+ end
178
+
179
+ should "send the right request" do
180
+ expected = Drip::Response.new(@response_status, JSON.parse(@response_body))
181
+ assert_equal expected, @client.create_product_activity_event(@options)
182
+ end
183
+
184
+ should "return error when missing fields" do
185
+ @options.delete(:product_id)
186
+ assert_raises(ArgumentError) { @client.create_product_activity_event(@options) }
187
+ end
188
+ end
189
+ end