File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,3 +32,7 @@ Layout/MultilineMethodCallIndentation:
3232Metrics/ClassLength :
3333 Exclude :
3434 - ' test/**/*'
35+
36+ Metrics/BlockLength :
37+ Exclude :
38+ - ' test/**/*'
Original file line number Diff line number Diff line change @@ -37,6 +37,27 @@ def create_order_activity_event(data = {})
3737 make_json_request :post , "v3/#{ account_id } /shopper_activity/order" , data
3838 end
3939
40+ # Public: Create a batch of order activity events.
41+ #
42+ # records - Required. An array of hashes containing orders attributes.
43+ # Refer to the Drip API docs for the required schema.
44+ #
45+ # Returns a Drip::Response.
46+ # See https://developer.drip.com/#create-or-update-a-batch-of-orders
47+ def create_order_activity_events ( records = [ ] )
48+ records . each_with_index do |record , i |
49+ raise ArgumentError , "email: or person_id: parameter required in record #{ i } " if !record . key? ( :email ) && !record . key? ( :person_id )
50+
51+ %i[ provider action order_id ] . each do |key |
52+ raise ArgumentError , "#{ key } : parameter required in record #{ i } " unless record . key? ( key )
53+ end
54+
55+ record [ :occurred_at ] = Time . now . iso8601 unless record . key? ( :occurred_at )
56+ end
57+
58+ make_json_request :post , "v3/#{ account_id } /shopper_activity/order/batch" , records
59+ end
60+
4061 # Public: Create a product activity event.
4162 #
4263 # options - Required. A Hash of additional product options. Refer to the
Original file line number Diff line number Diff line change @@ -80,6 +80,60 @@ def setup
8080 end
8181 end
8282
83+ context "#create_order_activity_events" do
84+ setup do
85+ @records = [
86+ {
87+ email : "drippy@example.com" ,
88+ action : "created" ,
89+ provider : "shopify" ,
90+ order_id : "abcdef" ,
91+ amount : 4900 ,
92+ tax : 100 ,
93+ fees : 0 ,
94+ discount : 0 ,
95+ currency_code : "USD" ,
96+ properties : {
97+ "size" => "medium" ,
98+ "color" => "red"
99+ }
100+ } ,
101+ {
102+ email : "drippy1@example.com" ,
103+ action : "created" ,
104+ provider : "shopify" ,
105+ order_id : "fdsgs" ,
106+ amount : 4900 ,
107+ tax : 100 ,
108+ fees : 0 ,
109+ discount : 0 ,
110+ currency_code : "USD" ,
111+ properties : {
112+ "size" => "medium" ,
113+ "color" => "red"
114+ }
115+ }
116+ ]
117+ @response_status = 202
118+ @response_body = "{}"
119+
120+ stub_request ( :post , "https://api.getdrip.com/v3/12345/shopper_activity/order/batch" ) .
121+ with ( headers : { "Content-Type" => "application/json" } ) .
122+ to_return ( status : @response_status , body : @response_body , headers : { } )
123+ end
124+
125+ should "send the right request" do
126+ expected = Drip ::Response . new ( @response_status , JSON . parse ( @response_body ) )
127+ assert_equal expected , @client . create_order_activity_events ( @records )
128+ end
129+
130+ should "return error when missing fields" do
131+ @records [ 1 ] . delete ( :order_id )
132+ err = assert_raises ( ArgumentError ) { @client . create_order_activity_events ( @records ) }
133+ assert_equal "order_id: parameter required in record 1" , err . message
134+ end
135+ end
136+
83137 context "#create_product_activity_event" do
84138 setup do
85139 @email = "drippy@drip.com"
You can’t perform that action at this time.
0 commit comments