-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from DripEmail/orders
Orders API
- Loading branch information
Showing
15 changed files
with
236 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
require "cgi" | ||
|
||
module Drip | ||
class Client | ||
module Events | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Drip | ||
class Client | ||
module Orders | ||
# Public: Create or update an order. | ||
# | ||
# email - Required. The String email address of the subscriber. | ||
# options - Required. A Hash of additional order options. Refer to the | ||
# Drip API docs for the required schema. | ||
# | ||
# Returns a Drip::Response. | ||
# See https://developer.drip.com/#orders | ||
def create_or_update_order(email, options = {}) | ||
data = options.merge(email: email) | ||
post "#{account_id}/orders", generate_resource("orders", data) | ||
end | ||
|
||
# Public: Create or update a batch of orders. | ||
# | ||
# orders - Required. An Array with between 1 and 1000 objects containing order data | ||
# | ||
# Returns a Drip::Response. | ||
# See https://developer.drip.com/#create-or-update-a-batch-of-orders | ||
def create_or_update_orders(orders) | ||
post "#{account_id}/orders/batches", generate_resource("batches", { "orders" => orders }) | ||
end | ||
|
||
# Public: Create or update a refund. | ||
# | ||
# options - Required. A Hash of refund properties | ||
# amount - Required. The amount of the refund. | ||
# provider - Required. The provider for the Order being refunded. | ||
# order_upstream_id - Required. The upstream_id for the Order being refunded. | ||
# upstream_id - The unique id of refund in the order management system. | ||
# note - A note about the refund. | ||
# processed_at - The String time at which the refund was processed in | ||
# ISO-8601 format. | ||
# | ||
# Returns a Drip::Response. | ||
# See https://developer.drip.com/#create-or-update-a-refund | ||
def create_or_update_refund(options) | ||
post "#{account_id}/refunds", generate_resource("refunds", options) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require "drip/collection" | ||
|
||
module Drip | ||
class Orders < Collection | ||
def self.collection_name | ||
"orders" | ||
end | ||
|
||
def self.resource_name | ||
"order" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "drip/resource" | ||
|
||
module Drip | ||
class Order < Resource | ||
def self.resource_name | ||
"order" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Drip | ||
VERSION = "1.0.0".freeze | ||
VERSION = "2.0.0".freeze | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
require File.dirname(__FILE__) + '/../../test_helper.rb' | ||
|
||
class Drip::Client::OrdersTest < Drip::TestCase | ||
def setup | ||
@stubs = Faraday::Adapter::Test::Stubs.new | ||
|
||
@connection = Faraday.new do |builder| | ||
builder.adapter :test, @stubs | ||
end | ||
|
||
@client = Drip::Client.new { |c| c.account_id = "12345" } | ||
@client.expects(:connection).at_least_once.returns(@connection) | ||
end | ||
|
||
context "#create_or_update_order" do | ||
setup do | ||
@email = "drippy@drip.com" | ||
@options = { | ||
"email": @email, | ||
"provider": "shopify", | ||
"upstream_id": "abcdef", | ||
"amount": 4900, | ||
"tax": 100, | ||
"fees": 0, | ||
"discount": 0, | ||
"currency_code": "USD", | ||
"properties": { | ||
"size": "medium", | ||
"color": "red" | ||
} | ||
} | ||
@payload = { "orders" => [@options] }.to_json | ||
@response_status = 202 | ||
@response_body = stub | ||
|
||
@stubs.post "12345/orders", @payload do | ||
[@response_status, {}, @response_body] | ||
end | ||
end | ||
|
||
should "send the correct request" do | ||
expected = Drip::Response.new(@response_status, @response_body) | ||
assert_equal expected, @client.create_or_update_order(@email, @options) | ||
end | ||
end | ||
|
||
context "#create_or_update_orders" do | ||
setup do | ||
@orders = [ | ||
{ | ||
"email": "drippy@drip.com", | ||
"provider": "shopify", | ||
"upstream_id": "abcdef", | ||
"amount": 4900, | ||
"tax": 100, | ||
"fees": 0, | ||
"discount": 0, | ||
"currency_code": "USD", | ||
"properties": { | ||
"size": "medium", | ||
"color": "red" | ||
} | ||
}, | ||
{ | ||
"email": "dripster@drip.com", | ||
"provider": "shopify", | ||
"upstream_id": "abcdef", | ||
"amount": 1500, | ||
"tax": 10, | ||
"fees": 0, | ||
"discount": 0, | ||
"currency_code": "SGD", | ||
"properties": { | ||
"size": "medium", | ||
"color": "black" | ||
} | ||
} | ||
] | ||
|
||
@payload = { "batches" => [{ "orders" => @orders }] }.to_json | ||
@response_status = 202 | ||
@response_body = stub | ||
|
||
@stubs.post "12345/orders/batches", @payload do | ||
[@response_status, {}, @response_body] | ||
end | ||
end | ||
|
||
should "send the correct request" do | ||
expected = Drip::Response.new(@response_status, @response_body) | ||
assert_equal expected, @client.create_or_update_orders(@orders) | ||
end | ||
end | ||
|
||
context "#create_or_update_refund" do | ||
setup do | ||
@options = { | ||
"provider": "shopify", | ||
"order_upstream_id": "abcdef", | ||
"amount": 4900, | ||
"upstream_id": "tuvwx", | ||
"note": "Incorrect size", | ||
"processed_at": "2013-06-22T10:41:11Z" | ||
} | ||
|
||
@payload = { "refunds" => [@options] }.to_json | ||
@response_status = 202 | ||
@response_body = stub | ||
|
||
@stubs.post "12345/refunds", @payload do | ||
[@response_status, {}, @response_body] | ||
end | ||
end | ||
|
||
should "send the correct request" do | ||
expected = Drip::Response.new(@response_status, @response_body) | ||
assert_equal expected, @client.create_or_update_refund(@options) | ||
end | ||
end | ||
end |
Oops, something went wrong.