basecrm 1.2.3 → 1.3.0
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.
- checksums.yaml +4 -4
- data/README.md +70 -1
- data/lib/basecrm.rb +57 -1
- data/lib/basecrm/models/deal.rb +15 -3
- data/lib/basecrm/models/deal_source.rb +25 -0
- data/lib/basecrm/models/lead_source.rb +25 -0
- data/lib/basecrm/models/line_item.rb +43 -0
- data/lib/basecrm/models/order.rb +22 -0
- data/lib/basecrm/models/price.rb +13 -0
- data/lib/basecrm/models/product.rb +43 -0
- data/lib/basecrm/services/deal_sources_service.rb +133 -0
- data/lib/basecrm/services/deals_service.rb +21 -20
- data/lib/basecrm/services/lead_sources_service.rb +133 -0
- data/lib/basecrm/services/line_items_service.rb +111 -0
- data/lib/basecrm/services/orders_service.rb +129 -0
- data/lib/basecrm/services/products_service.rb +136 -0
- data/lib/basecrm/version.rb +1 -1
- data/spec/factories/deal_source.rb +11 -0
- data/spec/factories/lead_source.rb +11 -0
- data/spec/factories/line_item.rb +18 -0
- data/spec/factories/order.rb +12 -0
- data/spec/factories/product.rb +19 -0
- data/spec/services/deal_sources_service_spec.rb +58 -0
- data/spec/services/deals_service_spec.rb +2 -2
- data/spec/services/lead_sources_service_spec.rb +58 -0
- data/spec/services/line_items_service_spec.rb +62 -0
- data/spec/services/orders_service_spec.rb +64 -0
- data/spec/services/products_service_spec.rb +58 -0
- data/spec/support/client_helpers.rb +2 -2
- metadata +57 -26
@@ -2,24 +2,24 @@
|
|
2
2
|
|
3
3
|
module BaseCRM
|
4
4
|
class DealsService
|
5
|
-
OPTS_KEYS_TO_PERSIST = Set[:contact_id, :currency, :custom_fields, :hot, :loss_reason_id, :name, :owner_id, :source_id, :stage_id, :tags, :value, :last_stage_change_at]
|
5
|
+
OPTS_KEYS_TO_PERSIST = Set[:contact_id, :currency, :custom_fields, :hot, :loss_reason_id, :name, :owner_id, :source_id, :stage_id, :tags, :value, :last_stage_change_at, :estimated_close_date, :customized_win_likelihood]
|
6
6
|
|
7
7
|
def initialize(client)
|
8
8
|
@client = client
|
9
9
|
end
|
10
10
|
|
11
11
|
# Retrieve all deals
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# get '/deals'
|
14
14
|
#
|
15
15
|
# If you want to use filtering or sorting (see #where).
|
16
|
-
# @return [Enumerable] Paginated resource you can use to iterate over all the resources.
|
16
|
+
# @return [Enumerable] Paginated resource you can use to iterate over all the resources.
|
17
17
|
def all
|
18
18
|
PaginatedResource.new(self)
|
19
19
|
end
|
20
20
|
|
21
21
|
# Retrieve all deals
|
22
|
-
#
|
22
|
+
#
|
23
23
|
# get '/deals'
|
24
24
|
#
|
25
25
|
# Returns all deals available to the user according to the parameters provided
|
@@ -36,22 +36,23 @@ module BaseCRM
|
|
36
36
|
# @option options [String] :sort_by (id:asc) A field to sort by. **Default** ordering is **ascending**. If you want to change the sort ordering to descending, append `:desc` to the field e.g. `sort_by=value:desc`.
|
37
37
|
# @option options [Integer] :source_id Id of the Source.
|
38
38
|
# @option options [Integer] :stage_id Id of the Stage.
|
39
|
-
# @
|
39
|
+
# @option options [String] :estimated_close_date of the deal.
|
40
|
+
# @return [Array<Deal>] The list of Deals for the first page, unless otherwise specified.
|
40
41
|
def where(options = {})
|
41
42
|
_, _, root = @client.get("/deals", options)
|
42
43
|
|
43
44
|
root[:items].map{ |item| Deal.new(item[:data]) }
|
44
45
|
end
|
45
|
-
|
46
|
+
|
46
47
|
|
47
48
|
# Create a deal
|
48
|
-
#
|
49
|
+
#
|
49
50
|
# post '/deals'
|
50
51
|
#
|
51
52
|
# Create a new deal
|
52
53
|
#
|
53
|
-
# @param deal [Deal, Hash] Either object of the Deal type or Hash. This object's attributes describe the object to be created.
|
54
|
-
# @return [Deal] The resulting object represting created resource.
|
54
|
+
# @param deal [Deal, Hash] Either object of the Deal type or Hash. This object's attributes describe the object to be created.
|
55
|
+
# @return [Deal] The resulting object represting created resource.
|
55
56
|
def create(deal)
|
56
57
|
validate_type!(deal)
|
57
58
|
|
@@ -60,26 +61,26 @@ module BaseCRM
|
|
60
61
|
|
61
62
|
Deal.new(root[:data])
|
62
63
|
end
|
63
|
-
|
64
|
+
|
64
65
|
|
65
66
|
# Retrieve a single deal
|
66
|
-
#
|
67
|
+
#
|
67
68
|
# get '/deals/{id}'
|
68
69
|
#
|
69
70
|
# Returns a single deal available to the user, according to the unique deal ID provided
|
70
71
|
# If the specified deal does not exist, the request will return an error
|
71
72
|
#
|
72
73
|
# @param id [Integer] Unique identifier of a Deal
|
73
|
-
# @return [Deal] Searched resource object.
|
74
|
+
# @return [Deal] Searched resource object.
|
74
75
|
def find(id)
|
75
76
|
_, _, root = @client.get("/deals/#{id}")
|
76
77
|
|
77
78
|
Deal.new(root[:data])
|
78
79
|
end
|
79
|
-
|
80
|
+
|
80
81
|
|
81
82
|
# Update a deal
|
82
|
-
#
|
83
|
+
#
|
83
84
|
# put '/deals/{id}'
|
84
85
|
#
|
85
86
|
# Updates deal information
|
@@ -89,8 +90,8 @@ module BaseCRM
|
|
89
90
|
# `tags` are replaced every time they are used in a request
|
90
91
|
# </figure>
|
91
92
|
#
|
92
|
-
# @param deal [Deal, Hash] Either object of the Deal type or Hash. This object's attributes describe the object to be updated.
|
93
|
-
# @return [Deal] The resulting object represting updated resource.
|
93
|
+
# @param deal [Deal, Hash] Either object of the Deal type or Hash. This object's attributes describe the object to be updated.
|
94
|
+
# @return [Deal] The resulting object represting updated resource.
|
94
95
|
def update(deal)
|
95
96
|
validate_type!(deal)
|
96
97
|
params = extract_params!(deal, :id)
|
@@ -101,10 +102,10 @@ module BaseCRM
|
|
101
102
|
|
102
103
|
Deal.new(root[:data])
|
103
104
|
end
|
104
|
-
|
105
|
+
|
105
106
|
|
106
107
|
# Delete a deal
|
107
|
-
#
|
108
|
+
#
|
108
109
|
# delete '/deals/{id}'
|
109
110
|
#
|
110
111
|
# Delete an existing deal and remove all of the associated contacts from the deal in a single call
|
@@ -117,7 +118,7 @@ module BaseCRM
|
|
117
118
|
status, _, _ = @client.delete("/deals/#{id}")
|
118
119
|
status == 204
|
119
120
|
end
|
120
|
-
|
121
|
+
|
121
122
|
|
122
123
|
private
|
123
124
|
def validate_type!(deal)
|
@@ -129,7 +130,7 @@ module BaseCRM
|
|
129
130
|
raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length
|
130
131
|
params
|
131
132
|
end
|
132
|
-
|
133
|
+
|
133
134
|
def sanitize(deal)
|
134
135
|
deal_hash = deal.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) }
|
135
136
|
deal_hash[:value] = Coercion.to_string(deal_hash[:value])
|
@@ -0,0 +1,133 @@
|
|
1
|
+
# WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema
|
2
|
+
|
3
|
+
module BaseCRM
|
4
|
+
class LeadSourcesService
|
5
|
+
OPTS_KEYS_TO_PERSIST = Set[:name, :resource_type]
|
6
|
+
|
7
|
+
def initialize(client)
|
8
|
+
@client = client
|
9
|
+
end
|
10
|
+
|
11
|
+
# Retrieve all sources
|
12
|
+
#
|
13
|
+
# get '/lead_sources'
|
14
|
+
#
|
15
|
+
# If you want to use filtering or sorting (see #where).
|
16
|
+
# @return [Enumerable] Paginated resource you can use to iterate over all the resources.
|
17
|
+
def all
|
18
|
+
PaginatedResource.new(self)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Retrieve all sources
|
22
|
+
#
|
23
|
+
# get '/lead_sources'
|
24
|
+
#
|
25
|
+
# Returns all lead sources available to the user according to the parameters provided
|
26
|
+
#
|
27
|
+
# @param options [Hash] Search options
|
28
|
+
# @option options [String] :ids Comma-separated list of lead source IDs to be returned in a request.
|
29
|
+
# @option options [String] :name Name of the source to search for. This parameter is used in a strict sense.
|
30
|
+
# @option options [Integer] :page (1) Page number to start from. Page numbering starts at 1, and omitting the `page` parameter will return the first page.
|
31
|
+
# @option options [Integer] :per_page (25) Number of records to return per page. The default limit is *25* and the maximum number that can be returned is *100*.
|
32
|
+
# @option options [String] :sort_by (id:asc) A field to sort by. The **default** ordering is **ascending**. If you want to change the sort order to descending, append `:desc` to the field e.g. `sort_by=name:desc`.
|
33
|
+
# @return [Array<LeadSource>] The list of LeadSources for the first page, unless otherwise specified.
|
34
|
+
def where(options = {})
|
35
|
+
_, _, root = @client.get("/lead_sources", options)
|
36
|
+
|
37
|
+
root[:items].map{ |item| LeadSource.new(item[:data]) }
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
# Create a new source
|
42
|
+
#
|
43
|
+
# post '/lead_sources'
|
44
|
+
#
|
45
|
+
# Creates a new source
|
46
|
+
# <figure class="notice">
|
47
|
+
# Source's name **must** be unique
|
48
|
+
# </figure>
|
49
|
+
#
|
50
|
+
# @param lead_source [LeadSource, Hash] Either object of the LeadSource type or Hash. This object's attributes describe the object to be created.
|
51
|
+
# @return [LeadSource] The resulting object represting created resource.
|
52
|
+
def create(lead_source)
|
53
|
+
validate_type!(lead_source)
|
54
|
+
|
55
|
+
attributes = sanitize(lead_source)
|
56
|
+
_, _, root = @client.post("/lead_sources", attributes)
|
57
|
+
|
58
|
+
LeadSource.new(root[:data])
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
# Retrieve a single source
|
63
|
+
#
|
64
|
+
# get '/lead_sources/{id}'
|
65
|
+
#
|
66
|
+
# Returns a single source available to the user by the provided id
|
67
|
+
# If a source with the supplied unique identifier does not exist it returns an error
|
68
|
+
#
|
69
|
+
# @param id [Integer] Unique identifier of a LeadSource
|
70
|
+
# @return [LeadSource] Searched resource object.
|
71
|
+
def find(id)
|
72
|
+
_, _, root = @client.get("/lead_sources/#{id}")
|
73
|
+
|
74
|
+
LeadSource.new(root[:data])
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
# Update a source
|
79
|
+
#
|
80
|
+
# put '/lead_sources/{id}'
|
81
|
+
#
|
82
|
+
# Updates source information
|
83
|
+
# If the specified source does not exist, the request will return an error
|
84
|
+
# <figure class="notice">
|
85
|
+
# If you want to update a source, you **must** make sure source's name is unique
|
86
|
+
# </figure>
|
87
|
+
#
|
88
|
+
# @param lead_source [LeadSource, Hash] Either object of the LeadSource type or Hash. This object's attributes describe the object to be updated.
|
89
|
+
# @return [LeadSource] The resulting object represting updated resource.
|
90
|
+
def update(lead_source)
|
91
|
+
validate_type!(lead_source)
|
92
|
+
params = extract_params!(lead_source, :id)
|
93
|
+
id = params[:id]
|
94
|
+
|
95
|
+
attributes = sanitize(lead_source)
|
96
|
+
_, _, root = @client.put("/lead_sources/#{id}", attributes)
|
97
|
+
|
98
|
+
LeadSource.new(root[:data])
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
# Delete a source
|
103
|
+
#
|
104
|
+
# delete '/lead_sources/{id}'
|
105
|
+
#
|
106
|
+
# Delete an existing source
|
107
|
+
# If the specified source does not exist, the request will return an error
|
108
|
+
# This operation cannot be undone
|
109
|
+
#
|
110
|
+
# @param id [Integer] Unique identifier of a LeadSource
|
111
|
+
# @return [Boolean] Status of the operation.
|
112
|
+
def destroy(id)
|
113
|
+
status, _, _ = @client.delete("/lead_sources/#{id}")
|
114
|
+
status == 204
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
private
|
119
|
+
def validate_type!(lead_source)
|
120
|
+
raise TypeError unless lead_source.is_a?(LeadSource) || lead_source.is_a?(Hash)
|
121
|
+
end
|
122
|
+
|
123
|
+
def extract_params!(lead_source, *args)
|
124
|
+
params = lead_source.to_h.select{ |k, _| args.include?(k) }
|
125
|
+
raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length
|
126
|
+
params
|
127
|
+
end
|
128
|
+
|
129
|
+
def sanitize(lead_source)
|
130
|
+
lead_source.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) }
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema
|
2
|
+
|
3
|
+
module BaseCRM
|
4
|
+
class LineItemsService
|
5
|
+
OPTS_KEYS_TO_PERSIST = Set[:product_id, :value, :variation, :currency, :quantity]
|
6
|
+
|
7
|
+
def initialize(client)
|
8
|
+
@client = client
|
9
|
+
end
|
10
|
+
|
11
|
+
# Retrieve order's line items
|
12
|
+
#
|
13
|
+
# get '/orders/{order_id}/line_items'
|
14
|
+
#
|
15
|
+
# If you want to use filtering or sorting (see #where).
|
16
|
+
# @return [Enumerable] Paginated resource you can use to iterate over all the resources.
|
17
|
+
def all(order_id)
|
18
|
+
PaginatedResource.new(self, order_id)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Retrieve order's line items
|
22
|
+
#
|
23
|
+
# get '/orders/{order_id}/line_items'
|
24
|
+
#
|
25
|
+
# Returns all line items associated to order
|
26
|
+
#
|
27
|
+
# @param order_id [Integer] Unique identifier of a Order
|
28
|
+
# @param options [Hash] Search options
|
29
|
+
# @option options [String] :ids Comma-separated list of line item IDs to be returned in a request.
|
30
|
+
# @option options [Integer] :quantity Quantity of line item.
|
31
|
+
# @option options [Integer] :value Value of line item.
|
32
|
+
# @option options [Integer] :page (1) Page number to start from. Page numbering starts at 1, and omitting the `page` parameter will return the first page.
|
33
|
+
# @option options [Integer] :per_page (25) Number of records to return per page. Default limit is *25* and the maximum number that can be returned is *100*.
|
34
|
+
# @option options [String] :sort_by (id:asc) A field to sort by. **Default** ordering is **ascending**. If you want to change the sort ordering to descending, append `:desc` to the field e.g. `sort_by=value:desc`.
|
35
|
+
# @return [Array<LineItem>] The list of LineItems for the first page, unless otherwise specified.
|
36
|
+
def where(order_id, options = {})
|
37
|
+
_, _, root = @client.get("/orders/#{order_id}/line_items", options)
|
38
|
+
|
39
|
+
root[:items].map{ |item| LineItem.new(item[:data]) }
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
# Create a line item
|
44
|
+
#
|
45
|
+
# post '/orders/{order_id}/line_items'
|
46
|
+
#
|
47
|
+
# Adds a new line item to an existing order
|
48
|
+
# Line items correspond to products in the catalog, so first you must create products
|
49
|
+
# Because products allow defining different prices in different currencies, when creating a line item, the parameter currency is required
|
50
|
+
#
|
51
|
+
# @param order_id [Integer] Unique identifier of a Order
|
52
|
+
# @param line_item [LineItem, Hash] Either object of the LineItem type or Hash. This object's attributes describe the object to be created.
|
53
|
+
# @return [LineItem] The resulting object represting created resource.
|
54
|
+
def create(order_id, line_item)
|
55
|
+
validate_type!(line_item)
|
56
|
+
|
57
|
+
attributes = sanitize(line_item)
|
58
|
+
_, _, root = @client.post("/orders/#{order_id}/line_items", attributes)
|
59
|
+
|
60
|
+
LineItem.new(root[:data])
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
# Retrieve a single line item
|
65
|
+
#
|
66
|
+
# get '/orders/{order_id}/line_items/{id}'
|
67
|
+
#
|
68
|
+
# Returns a single line item of an order, according to the unique line item ID provided
|
69
|
+
#
|
70
|
+
# @param order_id [Integer] Unique identifier of a Order
|
71
|
+
# @param id [Integer] Unique identifier of a LineItem
|
72
|
+
# @return [LineItem] Searched resource object.
|
73
|
+
def find(order_id, id)
|
74
|
+
_, _, root = @client.get("/orders/#{order_id}/line_items/#{id}")
|
75
|
+
|
76
|
+
LineItem.new(root[:data])
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
# Delete a line item
|
81
|
+
#
|
82
|
+
# delete '/orders/{order_id}/line_items/{id}'
|
83
|
+
#
|
84
|
+
# Remove an order’s line item
|
85
|
+
# This operation cannot be undone
|
86
|
+
#
|
87
|
+
# @param order_id [Integer] Unique identifier of a Order
|
88
|
+
# @param id [Integer] Unique identifier of a LineItem
|
89
|
+
# @return [Boolean] Status of the operation.
|
90
|
+
def destroy(order_id, id)
|
91
|
+
status, _, _ = @client.delete("/orders/#{order_id}/line_items/#{id}")
|
92
|
+
status == 204
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
private
|
97
|
+
def validate_type!(line_item)
|
98
|
+
raise TypeError unless line_item.is_a?(LineItem) || line_item.is_a?(Hash)
|
99
|
+
end
|
100
|
+
|
101
|
+
def extract_params!(line_item, *args)
|
102
|
+
params = line_item.to_h.select{ |k, _| args.include?(k) }
|
103
|
+
raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length
|
104
|
+
params
|
105
|
+
end
|
106
|
+
|
107
|
+
def sanitize(line_item)
|
108
|
+
line_item.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) }
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema
|
2
|
+
|
3
|
+
module BaseCRM
|
4
|
+
class OrdersService
|
5
|
+
OPTS_KEYS_TO_PERSIST = Set[:deal_id, :discount]
|
6
|
+
|
7
|
+
def initialize(client)
|
8
|
+
@client = client
|
9
|
+
end
|
10
|
+
|
11
|
+
# Retrieve all orders
|
12
|
+
#
|
13
|
+
# get '/orders'
|
14
|
+
#
|
15
|
+
# If you want to use filtering or sorting (see #where).
|
16
|
+
# @return [Enumerable] Paginated resource you can use to iterate over all the resources.
|
17
|
+
def all
|
18
|
+
PaginatedResource.new(self)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Retrieve all orders
|
22
|
+
#
|
23
|
+
# get '/orders'
|
24
|
+
#
|
25
|
+
# Returns all orders available to the user according to the parameters provided
|
26
|
+
#
|
27
|
+
# @param options [Hash] Search options
|
28
|
+
# @option options [String] :ids Comma-separated list of order IDs to be returned in a request.
|
29
|
+
# @option options [Integer] :deal_id ID of the deal order is associated to.
|
30
|
+
# @option options [Integer] :page (1) Page number to start from. Page numbering starts at 1, and omitting the `page` parameter will return the first page.
|
31
|
+
# @option options [Integer] :per_page (25) Number of records to return per page. Default limit is *25* and the maximum number that can be returned is *100*.
|
32
|
+
# @option options [String] :sort_by (id:asc) A field to sort by. **Default** ordering is **ascending**. If you want to change the sort ordering to descending, append `:desc` to the field e.g. `sort_by=value:desc`.
|
33
|
+
# @return [Array<Order>] The list of Orders for the first page, unless otherwise specified.
|
34
|
+
def where(options = {})
|
35
|
+
_, _, root = @client.get("/orders", options)
|
36
|
+
|
37
|
+
root[:items].map{ |item| Order.new(item[:data]) }
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
# Create an order
|
42
|
+
#
|
43
|
+
# post '/orders'
|
44
|
+
#
|
45
|
+
# Create a new order for a deal
|
46
|
+
# User needs to have access to the deal to create an order
|
47
|
+
# Each deal can have at most one order and error is returned when attempting to create more
|
48
|
+
#
|
49
|
+
# @param order [Order, Hash] Either object of the Order type or Hash. This object's attributes describe the object to be created.
|
50
|
+
# @return [Order] The resulting object represting created resource.
|
51
|
+
def create(order)
|
52
|
+
validate_type!(order)
|
53
|
+
|
54
|
+
attributes = sanitize(order)
|
55
|
+
_, _, root = @client.post("/orders", attributes)
|
56
|
+
|
57
|
+
Order.new(root[:data])
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
# Retrieve a single order
|
62
|
+
#
|
63
|
+
# get '/orders/{id}'
|
64
|
+
#
|
65
|
+
# Returns a single order available to the user, according to the unique order ID provided
|
66
|
+
# If the specified order does not exist, the request will return an error
|
67
|
+
#
|
68
|
+
# @param id [Integer] Unique identifier of a Order
|
69
|
+
# @return [Order] Searched resource object.
|
70
|
+
def find(id)
|
71
|
+
_, _, root = @client.get("/orders/#{id}")
|
72
|
+
|
73
|
+
Order.new(root[:data])
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
# Update an order
|
78
|
+
#
|
79
|
+
# put '/orders/{id}'
|
80
|
+
#
|
81
|
+
# Updates order information
|
82
|
+
# If the specified order does not exist, the request will return an error
|
83
|
+
#
|
84
|
+
# @param order [Order, Hash] Either object of the Order type or Hash. This object's attributes describe the object to be updated.
|
85
|
+
# @return [Order] The resulting object represting updated resource.
|
86
|
+
def update(order)
|
87
|
+
validate_type!(order)
|
88
|
+
params = extract_params!(order, :id)
|
89
|
+
id = params[:id]
|
90
|
+
|
91
|
+
attributes = sanitize(order)
|
92
|
+
_, _, root = @client.put("/orders/#{id}", attributes)
|
93
|
+
|
94
|
+
Order.new(root[:data])
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
# Delete an order
|
99
|
+
#
|
100
|
+
# delete '/orders/{id}'
|
101
|
+
#
|
102
|
+
# Delete an existing order and remove all of the associated line items in a single call
|
103
|
+
# If the specified order does not exist, the request will return an error
|
104
|
+
# This operation cannot be undone
|
105
|
+
#
|
106
|
+
# @param id [Integer] Unique identifier of a Order
|
107
|
+
# @return [Boolean] Status of the operation.
|
108
|
+
def destroy(id)
|
109
|
+
status, _, _ = @client.delete("/orders/#{id}")
|
110
|
+
status == 204
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
private
|
115
|
+
def validate_type!(order)
|
116
|
+
raise TypeError unless order.is_a?(Order) || order.is_a?(Hash)
|
117
|
+
end
|
118
|
+
|
119
|
+
def extract_params!(order, *args)
|
120
|
+
params = order.to_h.select{ |k, _| args.include?(k) }
|
121
|
+
raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length
|
122
|
+
params
|
123
|
+
end
|
124
|
+
|
125
|
+
def sanitize(order)
|
126
|
+
order.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) }
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|