drip-ruby 1.0.0 → 2.0.0

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
- SHA1:
3
- metadata.gz: 5aafc1c74dbc6f3b1394f304f7d1b9ceb3fe829d
4
- data.tar.gz: 9a83f650a30e9c127c1a594fcbbd6964af009966
2
+ SHA256:
3
+ metadata.gz: 0116b3930cb8e30ecf0291777d9acd336661f6c600a594632cd8b831bf042b9b
4
+ data.tar.gz: ecf5f5ea8225363976fb5993aa0a3fd29be1796261508a829027e71f6d458d65
5
5
  SHA512:
6
- metadata.gz: 0a36ee1b8ac89b1fb63663e49d383acc3a3d15ff22e6bccf3afe5a5ab6cf17d4c76b5ae5369fe8a44383317d1db63fbda43432e1ad9c41c37ad3569bd9377a58
7
- data.tar.gz: 64d97aea9e8937326694c91e34abbd8825890dc31476e0efc22403fef440b9569edf4a5b0ddd3b211e32a3e859290aaa4269acd29698c4d8da380cea578c0ffd
6
+ metadata.gz: ce290db0ffdae723d78d12d71e7f71f47c0b632c50d3d63d8f1c544d90e0cf367f43c4c73cab06b8321daf4d20764bc1ad4b5e0fb6e7086c93d6a95d85278880
7
+ data.tar.gz: e2f2f8f62441222da207c808f63b130c8be44ce6808faee5d681d6653481a2620d552f79487bdb8daeb45bcd24092b0ea19386342b9da72427e190b6b304e5ac
data/README.md CHANGED
@@ -120,13 +120,15 @@ as methods on the client object. The following methods are currently available:
120
120
  | List all forms | `#forms` |
121
121
  | Fetch a form | `#form(id)` |
122
122
 
123
- #### Purchases
123
+ #### Orders
124
+
125
+ **Note:** The beta purchases endpoint has been deprecated and its methods have been removed from the gem except `create_purchase`, which now sends requests to the Order creation endpoint [here](https://developer.drip.com/#orders)
124
126
 
125
127
  | Actions | Methods |
126
128
  | :------------------------- | :--------------------------------------------------- |
127
- | List purchases for a subscriber | `#purchases(email)` |
128
- | Create a purchase         | `#create_purchase(email, amount, options = {})` |
129
- | Fetch a purchase | `#purchase(email, id)` |
129
+ | Create or update an order | `#create_or_update_order(email, options = {})` |
130
+ | Create or update a batch of orders | `#create_or_update_orders(orders = {})` |
131
+ | Create or update a refund | `#create_or_update_refund(options = {})` |
130
132
 
131
133
  #### Subscribers
132
134
 
@@ -1,5 +1,3 @@
1
- require "cgi"
2
-
3
1
  module Drip
4
2
  class Client
5
3
  module Events
@@ -0,0 +1,45 @@
1
+ module Drip
2
+ class Client
3
+ module Orders
4
+ # Public: Create or update an order.
5
+ #
6
+ # email - Required. The String email address of the subscriber.
7
+ # options - Required. A Hash of additional order options. Refer to the
8
+ # Drip API docs for the required schema.
9
+ #
10
+ # Returns a Drip::Response.
11
+ # See https://developer.drip.com/#orders
12
+ def create_or_update_order(email, options = {})
13
+ data = options.merge(email: email)
14
+ post "#{account_id}/orders", generate_resource("orders", data)
15
+ end
16
+
17
+ # Public: Create or update a batch of orders.
18
+ #
19
+ # orders - Required. An Array with between 1 and 1000 objects containing order data
20
+ #
21
+ # Returns a Drip::Response.
22
+ # See https://developer.drip.com/#create-or-update-a-batch-of-orders
23
+ def create_or_update_orders(orders)
24
+ post "#{account_id}/orders/batches", generate_resource("batches", { "orders" => orders })
25
+ end
26
+
27
+ # Public: Create or update a refund.
28
+ #
29
+ # options - Required. A Hash of refund properties
30
+ # amount - Required. The amount of the refund.
31
+ # provider - Required. The provider for the Order being refunded.
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
36
+ # ISO-8601 format.
37
+ #
38
+ # Returns a Drip::Response.
39
+ # See https://developer.drip.com/#create-or-update-a-refund
40
+ def create_or_update_refund(options)
41
+ post "#{account_id}/refunds", generate_resource("refunds", options)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,5 +1,3 @@
1
- require "cgi"
2
-
3
1
  module Drip
4
2
  class Client
5
3
  module Purchases
@@ -7,59 +5,18 @@ module Drip
7
5
  #
8
6
  # email - Required. The String email address of the subscriber.
9
7
  # amount - Required. The total amount of the purchase in cents.
10
- # options - A Hash of options.
11
- # - properties - Optional. An Object containing properties about
12
- # the order.
13
- # - items - Optional. An Array of objects containing information
14
- # about specific order items.
15
- # - name - Required. The product name.
16
- # - amount - Required. The line total (in
17
- # cents).
18
- # - quantity - Optional. The quantity of the
19
- # item purchased (if omitted,
20
- # defaults to 1).
21
- # - product_id - Optional. A unique identifier
22
- # for the specific product.
23
- # - sku - Optional. The product SKU number.
24
- # - properties - Optional. An Object containing
25
- # properties about the line item.
26
- # - provider - Optional. The identifier for the provider from
27
- # which the purchase data was received
28
- # - order_id - Optional. A unique identifier for the order
29
- # (generally the primary key generated by the
30
- # order management system).
31
- # - permalink - Optional. A URL for the human-readable
32
- # interface to view the order details.
33
- # - occurred_at - Optional. The String time at which the event
34
- # occurred in ISO-8601 format. Defaults to the
35
- # current time.
36
- #
8
+ # options - Required. A Hash of additional order options. Refer to the
9
+ # Drip API docs for the required schema.
37
10
  # Returns a Drip::Response.
38
- # See https://www.getdrip.com/docs/rest-api#create_purchase
39
- def create_purchase(email, amount, options = {})
40
- data = options.merge(amount: amount)
41
- post "#{account_id}/subscribers/#{CGI.escape email}/purchases", generate_resource("purchases", data)
42
- end
43
-
44
- # Public: Fetch a list of purchases for a subscriber.
45
- #
46
- # email - The String email address of the subscriber.
11
+ # See https://developer.drip.com/#orders
47
12
  #
48
- # Returns a Drip::Response.
49
- # See https://www.getdrip.com/docs/rest-api#list_purchases
50
- def purchases(email)
51
- get "#{account_id}/subscribers/#{CGI.escape email}/purchases"
52
- end
13
+ # DEPRECATED: The beta Purchase endpoint has been deprecated and this method now sends
14
+ # requests to the Order creation endpoint. Please use `create_or_update_order` instead
15
+ def create_purchase(email, amount, options = {})
16
+ warn "[DEPRECATED] `create_purchase` is deprecated. Please use `create_or_update_order` instead."
53
17
 
54
- # Public: Fetch a purchase.
55
- #
56
- # email - The String email address of the subscriber.
57
- # id - The String ID of the purchase
58
- #
59
- # Returns a Drip::Response.
60
- # See https://www.getdrip.com/docs/rest-api#list_purchases
61
- def purchase(email, id)
62
- get "#{account_id}/subscribers/#{CGI.escape email}/purchases/#{id}"
18
+ data = options.merge({ amount: amount, email: email })
19
+ post "#{account_id}/orders", generate_resource("orders", data)
63
20
  end
64
21
  end
65
22
  end
data/lib/drip/client.rb CHANGED
@@ -7,6 +7,7 @@ require "drip/client/conversions"
7
7
  require "drip/client/custom_fields"
8
8
  require "drip/client/events"
9
9
  require "drip/client/forms"
10
+ require "drip/client/orders"
10
11
  require "drip/client/purchases"
11
12
  require "drip/client/subscribers"
12
13
  require "drip/client/tags"
@@ -27,6 +28,7 @@ module Drip
27
28
  include CustomFields
28
29
  include Events
29
30
  include Forms
31
+ include Orders
30
32
  include Purchases
31
33
  include Subscribers
32
34
  include Tags
@@ -0,0 +1,13 @@
1
+ require "drip/collection"
2
+
3
+ module Drip
4
+ class Orders < Collection
5
+ def self.collection_name
6
+ "orders"
7
+ end
8
+
9
+ def self.resource_name
10
+ "order"
11
+ end
12
+ end
13
+ end
@@ -3,6 +3,7 @@ require "drip/collections/broadcasts"
3
3
  require "drip/collections/campaigns"
4
4
  require "drip/collections/campaign_subscriptions"
5
5
  require "drip/collections/errors"
6
+ require "drip/collections/orders"
6
7
  require "drip/collections/purchases"
7
8
  require "drip/collections/subscribers"
8
9
  require "drip/collections/tags"
@@ -19,6 +20,7 @@ module Drip
19
20
  Drip::Campaigns,
20
21
  Drip::CampaignSubscriptions,
21
22
  Drip::Errors,
23
+ Drip::Orders,
22
24
  Drip::Purchases,
23
25
  Drip::Subscribers,
24
26
  Drip::Tags,
@@ -0,0 +1,9 @@
1
+ require "drip/resource"
2
+
3
+ module Drip
4
+ class Order < Resource
5
+ def self.resource_name
6
+ "order"
7
+ end
8
+ end
9
+ end
@@ -3,6 +3,7 @@ require "drip/resources/broadcast"
3
3
  require "drip/resources/campaign"
4
4
  require "drip/resources/campaign_subscription"
5
5
  require "drip/resources/error"
6
+ require "drip/resources/order"
6
7
  require "drip/resources/purchase"
7
8
  require "drip/resources/subscriber"
8
9
  require "drip/resources/tag"
@@ -19,6 +20,7 @@ module Drip
19
20
  Drip::Campaign,
20
21
  Drip::CampaignSubscription,
21
22
  Drip::Error,
23
+ Drip::Order,
22
24
  Drip::Purchase,
23
25
  Drip::Subscriber,
24
26
  Drip::Tag,
data/lib/drip/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Drip
2
- VERSION = "1.0.0".freeze
2
+ VERSION = "2.0.0".freeze
3
3
  end
@@ -0,0 +1,120 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper.rb'
2
+
3
+ class Drip::Client::OrdersTest < Drip::TestCase
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
+ @client = Drip::Client.new { |c| c.account_id = "12345" }
12
+ @client.expects(:connection).at_least_once.returns(@connection)
13
+ end
14
+
15
+ context "#create_or_update_order" do
16
+ setup do
17
+ @email = "drippy@drip.com"
18
+ @options = {
19
+ "email": @email,
20
+ "provider": "shopify",
21
+ "upstream_id": "abcdef",
22
+ "amount": 4900,
23
+ "tax": 100,
24
+ "fees": 0,
25
+ "discount": 0,
26
+ "currency_code": "USD",
27
+ "properties": {
28
+ "size": "medium",
29
+ "color": "red"
30
+ }
31
+ }
32
+ @payload = { "orders" => [@options] }.to_json
33
+ @response_status = 202
34
+ @response_body = stub
35
+
36
+ @stubs.post "12345/orders", @payload do
37
+ [@response_status, {}, @response_body]
38
+ end
39
+ end
40
+
41
+ should "send the correct request" do
42
+ expected = Drip::Response.new(@response_status, @response_body)
43
+ assert_equal expected, @client.create_or_update_order(@email, @options)
44
+ end
45
+ end
46
+
47
+ context "#create_or_update_orders" do
48
+ setup do
49
+ @orders = [
50
+ {
51
+ "email": "drippy@drip.com",
52
+ "provider": "shopify",
53
+ "upstream_id": "abcdef",
54
+ "amount": 4900,
55
+ "tax": 100,
56
+ "fees": 0,
57
+ "discount": 0,
58
+ "currency_code": "USD",
59
+ "properties": {
60
+ "size": "medium",
61
+ "color": "red"
62
+ }
63
+ },
64
+ {
65
+ "email": "dripster@drip.com",
66
+ "provider": "shopify",
67
+ "upstream_id": "abcdef",
68
+ "amount": 1500,
69
+ "tax": 10,
70
+ "fees": 0,
71
+ "discount": 0,
72
+ "currency_code": "SGD",
73
+ "properties": {
74
+ "size": "medium",
75
+ "color": "black"
76
+ }
77
+ }
78
+ ]
79
+
80
+ @payload = { "batches" => [{ "orders" => @orders }] }.to_json
81
+ @response_status = 202
82
+ @response_body = stub
83
+
84
+ @stubs.post "12345/orders/batches", @payload do
85
+ [@response_status, {}, @response_body]
86
+ end
87
+ end
88
+
89
+ should "send the correct request" do
90
+ expected = Drip::Response.new(@response_status, @response_body)
91
+ assert_equal expected, @client.create_or_update_orders(@orders)
92
+ end
93
+ end
94
+
95
+ context "#create_or_update_refund" do
96
+ setup do
97
+ @options = {
98
+ "provider": "shopify",
99
+ "order_upstream_id": "abcdef",
100
+ "amount": 4900,
101
+ "upstream_id": "tuvwx",
102
+ "note": "Incorrect size",
103
+ "processed_at": "2013-06-22T10:41:11Z"
104
+ }
105
+
106
+ @payload = { "refunds" => [@options] }.to_json
107
+ @response_status = 202
108
+ @response_body = stub
109
+
110
+ @stubs.post "12345/refunds", @payload do
111
+ [@response_status, {}, @response_body]
112
+ end
113
+ end
114
+
115
+ should "send the correct request" do
116
+ expected = Drip::Response.new(@response_status, @response_body)
117
+ assert_equal expected, @client.create_or_update_refund(@options)
118
+ end
119
+ end
120
+ end
@@ -15,79 +15,33 @@ class Drip::Client::PurchasesTest < Drip::TestCase
15
15
  context "#create_purchase" do
16
16
  setup do
17
17
  @email = "derrick@getdrip.com"
18
- @amount = 3900
19
- @properties = {
20
- address: '123 Anywhere St'
21
- }
22
-
23
- @items = [
24
- {
25
- name: 'foo',
26
- amount: 100
27
- },
28
- {
29
- name: 'bar',
30
- amount: 200
18
+ @amount = 4900
19
+ @options = {
20
+ "email": @email,
21
+ "provider": "shopify",
22
+ "upstream_id": "abcdef",
23
+ "amount": @amount,
24
+ "tax": 100,
25
+ "fees": 0,
26
+ "discount": 0,
27
+ "currency_code": "USD",
28
+ "properties": {
29
+ "size": "medium",
30
+ "color": "red"
31
31
  }
32
- ]
33
-
34
- @payload = {
35
- purchases: [{
36
- properties: @properties,
37
- items: @items,
38
- amount: @amount
39
- }]
40
- }.to_json
41
-
42
- @response_status = 201
43
- @response_body = stub
44
-
45
- @stubs.post "12345/subscribers/#{CGI.escape @email}/purchases", @payload do
46
- [@response_status, {}, @response_body]
47
- end
48
- end
49
-
50
- should "send the right request" do
51
- expected = Drip::Response.new(@response_status, @response_body)
52
- assert_equal expected, @client.create_purchase(@email, @amount, {
53
- properties: @properties,
54
- items: @items
55
- })
56
- end
57
- end
58
-
59
- context "#purchases" do
60
- setup do
61
- @email = "derrick@getdrip.com"
62
- @response_status = 201
63
- @response_body = stub
64
-
65
- @stubs.get "12345/subscribers/#{CGI.escape @email}/purchases" do
66
- [@response_status, {}, @response_body]
67
- end
68
- end
69
-
70
- should "send the right request" do
71
- expected = Drip::Response.new(@response_status, @response_body)
72
- assert_equal expected, @client.purchases(@email)
73
- end
74
- end
75
-
76
- context "#purchase" do
77
- setup do
78
- @email = "derrick@getdrip.com"
79
- @id = '23456'
80
- @response_status = 201
32
+ }
33
+ @payload = { "orders" => [@options] }.to_json
34
+ @response_status = 202
81
35
  @response_body = stub
82
36
 
83
- @stubs.get "12345/subscribers/#{CGI.escape @email}/purchases/#{@id}" do
37
+ @stubs.post "12345/orders", @payload do
84
38
  [@response_status, {}, @response_body]
85
39
  end
86
40
  end
87
41
 
88
42
  should "send the right request" do
89
43
  expected = Drip::Response.new(@response_status, @response_body)
90
- assert_equal expected, @client.purchase(@email, @id)
44
+ assert_equal expected, @client.create_purchase(@email, @amount, @options)
91
45
  end
92
46
  end
93
47
  end
@@ -7,6 +7,7 @@ class Drip::CollectionsTest < Drip::TestCase
7
7
  assert_equal Drip::Campaigns, Drip::Collections.find_class("campaigns")
8
8
  assert_equal Drip::CampaignSubscriptions, Drip::Collections.find_class("campaign_subscriptions")
9
9
  assert_equal Drip::Errors, Drip::Collections.find_class("errors")
10
+ assert_equal Drip::Orders, Drip::Collections.find_class("orders")
10
11
  assert_equal Drip::Purchases, Drip::Collections.find_class("purchases")
11
12
  assert_equal Drip::Subscribers, Drip::Collections.find_class("subscribers")
12
13
  assert_equal Drip::Tags, Drip::Collections.find_class("tags")
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper.rb'
2
+
3
+ class Drip::OrderTest < Drip::TestCase
4
+ should "have a resource name" do
5
+ assert_equal "order", Drip::Order.resource_name
6
+ end
7
+ end
@@ -6,6 +6,7 @@ class Drip::ResourcesTest < Drip::TestCase
6
6
  assert_equal Drip::Campaign, Drip::Resources.find_class("campaign")
7
7
  assert_equal Drip::CampaignSubscription, Drip::Resources.find_class("campaign_subscription")
8
8
  assert_equal Drip::Error, Drip::Resources.find_class("error")
9
+ assert_equal Drip::Order, Drip::Resources.find_class("order")
9
10
  assert_equal Drip::Purchase, Drip::Resources.find_class("purchase")
10
11
  assert_equal Drip::Subscriber, Drip::Resources.find_class("subscriber")
11
12
  assert_equal Drip::Tag, Drip::Resources.find_class("tag")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drip-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derrick Reimer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-27 00:00:00.000000000 Z
11
+ date: 2018-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -134,6 +134,7 @@ files:
134
134
  - lib/drip/client/custom_fields.rb
135
135
  - lib/drip/client/events.rb
136
136
  - lib/drip/client/forms.rb
137
+ - lib/drip/client/orders.rb
137
138
  - lib/drip/client/purchases.rb
138
139
  - lib/drip/client/subscribers.rb
139
140
  - lib/drip/client/tags.rb
@@ -147,6 +148,7 @@ files:
147
148
  - lib/drip/collections/campaign_subscriptions.rb
148
149
  - lib/drip/collections/campaigns.rb
149
150
  - lib/drip/collections/errors.rb
151
+ - lib/drip/collections/orders.rb
150
152
  - lib/drip/collections/purchases.rb
151
153
  - lib/drip/collections/subscribers.rb
152
154
  - lib/drip/collections/tags.rb
@@ -160,6 +162,7 @@ files:
160
162
  - lib/drip/resources/campaign.rb
161
163
  - lib/drip/resources/campaign_subscription.rb
162
164
  - lib/drip/resources/error.rb
165
+ - lib/drip/resources/order.rb
163
166
  - lib/drip/resources/purchase.rb
164
167
  - lib/drip/resources/subscriber.rb
165
168
  - lib/drip/resources/tag.rb
@@ -176,6 +179,7 @@ files:
176
179
  - test/drip/client/custom_fields_test.rb
177
180
  - test/drip/client/events_test.rb
178
181
  - test/drip/client/forms_test.rb
182
+ - test/drip/client/orders_test.rb
179
183
  - test/drip/client/purchases_test.rb
180
184
  - test/drip/client/subscribers_test.rb
181
185
  - test/drip/client/tags_test.rb
@@ -187,6 +191,7 @@ files:
187
191
  - test/drip/collections_test.rb
188
192
  - test/drip/resource_test.rb
189
193
  - test/drip/resources/account_test.rb
194
+ - test/drip/resources/order_test.rb
190
195
  - test/drip/resources/subscriber_test.rb
191
196
  - test/drip/resources_test.rb
192
197
  - test/drip/response_test.rb
@@ -213,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
218
  version: '0'
214
219
  requirements: []
215
220
  rubyforge_project:
216
- rubygems_version: 2.5.1
221
+ rubygems_version: 2.7.6
217
222
  signing_key:
218
223
  specification_version: 4
219
224
  summary: A Ruby gem for interacting with the Drip API
@@ -226,6 +231,7 @@ test_files:
226
231
  - test/drip/client/custom_fields_test.rb
227
232
  - test/drip/client/events_test.rb
228
233
  - test/drip/client/forms_test.rb
234
+ - test/drip/client/orders_test.rb
229
235
  - test/drip/client/purchases_test.rb
230
236
  - test/drip/client/subscribers_test.rb
231
237
  - test/drip/client/tags_test.rb
@@ -237,6 +243,7 @@ test_files:
237
243
  - test/drip/collections_test.rb
238
244
  - test/drip/resource_test.rb
239
245
  - test/drip/resources/account_test.rb
246
+ - test/drip/resources/order_test.rb
240
247
  - test/drip/resources/subscriber_test.rb
241
248
  - test/drip/resources_test.rb
242
249
  - test/drip/response_test.rb