bigcommerce_api 0.6.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bigcommerce_api.rb +6 -2
- data/lib/bigcommerce_api/address.rb +45 -0
- data/lib/bigcommerce_api/base.rb +26 -16
- data/lib/bigcommerce_api/brand.rb +7 -5
- data/lib/bigcommerce_api/category.rb +14 -7
- data/lib/bigcommerce_api/coupon.rb +6 -0
- data/lib/bigcommerce_api/customer.rb +26 -0
- data/lib/bigcommerce_api/error.rb +9 -0
- data/lib/bigcommerce_api/hook.rb +11 -0
- data/lib/bigcommerce_api/image.rb +36 -5
- data/lib/bigcommerce_api/option.rb +8 -7
- data/lib/bigcommerce_api/option_set.rb +5 -6
- data/lib/bigcommerce_api/option_set_option.rb +32 -5
- data/lib/bigcommerce_api/option_value.rb +31 -6
- data/lib/bigcommerce_api/order.rb +75 -13
- data/lib/bigcommerce_api/order_coupon.rb +13 -0
- data/lib/bigcommerce_api/order_product.rb +58 -12
- data/lib/bigcommerce_api/order_status.rb +4 -5
- data/lib/bigcommerce_api/product.rb +88 -10
- data/lib/bigcommerce_api/product_option.rb +6 -5
- data/lib/bigcommerce_api/resource.rb +97 -53
- data/lib/bigcommerce_api/rule.rb +13 -7
- data/lib/bigcommerce_api/shipment.rb +17 -8
- data/lib/bigcommerce_api/shipping_address.rb +75 -0
- data/lib/bigcommerce_api/sku.rb +16 -11
- data/lib/bigcommerce_api/store.rb +21 -6
- data/lib/bigcommerce_api/tax_class.rb +3 -5
- metadata +52 -18
- data/lib/bigcommerce_api/shippingaddress.rb +0 -47
@@ -1,14 +1,62 @@
|
|
1
1
|
module BigcommerceAPI
|
2
|
-
|
3
2
|
class OrderProduct < Resource
|
4
|
-
attr_accessor :
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
attr_accessor :id,
|
4
|
+
:applied_discounts,
|
5
|
+
:base_cost_price,
|
6
|
+
:base_price,
|
7
|
+
:base_total,
|
8
|
+
:base_wrapping_cost,
|
9
|
+
:bin_picking_number,
|
10
|
+
:configurable_fields,
|
11
|
+
:cost_price_ex_tax,
|
12
|
+
:cost_price_inc_tax,
|
13
|
+
:cost_price_tax,
|
14
|
+
:ebay_item_id,
|
15
|
+
:ebay_transaction_id,
|
16
|
+
:event_date,
|
17
|
+
:event_name,
|
18
|
+
:fixed_shipping_cost,
|
19
|
+
:is_bundled_product,
|
20
|
+
:is_refunded,
|
21
|
+
:name,
|
22
|
+
:option_set_id,
|
23
|
+
:order_address_id,
|
24
|
+
:order_id,
|
25
|
+
:parent_order_product_id,
|
26
|
+
:price_ex_tax,
|
27
|
+
:price_inc_tax,
|
28
|
+
:price_tax,
|
29
|
+
:product_id,
|
30
|
+
:product_options,
|
31
|
+
:quantity,
|
32
|
+
:quantity_shipped,
|
33
|
+
:refund_amount,
|
34
|
+
:return_id,
|
35
|
+
:sku,
|
36
|
+
:total_ex_tax,
|
37
|
+
:total_inc_tax,
|
38
|
+
:total_tax,
|
39
|
+
:type,
|
40
|
+
:weight,
|
41
|
+
:wrapping_cost_ex_tax,
|
42
|
+
:wrapping_cost_inc_tax,
|
43
|
+
:wrapping_cost_tax,
|
44
|
+
:wrapping_message,
|
45
|
+
:wrapping_name
|
46
|
+
|
47
|
+
belongs_to :option_set,
|
48
|
+
{ parent_order_product: :order_product },
|
49
|
+
:ebay_item,
|
50
|
+
:ebay_transaction,
|
51
|
+
:return,
|
52
|
+
:product,
|
53
|
+
:order
|
54
|
+
|
55
|
+
# reserved
|
8
56
|
attr_accessor :orderproduct_type
|
9
|
-
|
10
|
-
def
|
11
|
-
a = BigcommerceAPI::Base.get "/orders/#{self.order_id}/
|
57
|
+
|
58
|
+
def shipping_address
|
59
|
+
a = BigcommerceAPI::Base.get "/orders/#{self.order_id}/shipping_addresses/#{self.order_address_id}"
|
12
60
|
(a.success? and !a.nil?) ? BigcommerceAPI::Shippingaddress.new(a) : nil
|
13
61
|
end
|
14
62
|
|
@@ -38,7 +86,7 @@ module BigcommerceAPI
|
|
38
86
|
|
39
87
|
class << self
|
40
88
|
def all(order_id, params={})
|
41
|
-
resources = BigcommerceAPI::Base.get("/orders/#{order_id}/products", :
|
89
|
+
resources = BigcommerceAPI::Base.get("/orders/#{order_id}/products", query: date_adjust(params))
|
42
90
|
(resources.success? and !resources.nil?) ? resources.collect{|r| self.new(r)} : []
|
43
91
|
end
|
44
92
|
|
@@ -47,7 +95,5 @@ module BigcommerceAPI
|
|
47
95
|
(r.success? and !r.nil?) ? self.new(r) : nil
|
48
96
|
end
|
49
97
|
end
|
50
|
-
|
51
98
|
end
|
52
|
-
|
53
|
-
end
|
99
|
+
end
|
@@ -1,24 +1,102 @@
|
|
1
1
|
module BigcommerceAPI
|
2
|
-
|
3
2
|
class Product < Resource
|
4
3
|
extend BigcommerceAPI::Countable
|
5
4
|
|
6
5
|
# incoming attributes
|
7
|
-
attr_accessor :
|
6
|
+
attr_accessor :id,
|
7
|
+
:availability,
|
8
|
+
:availability_description,
|
9
|
+
:bin_picking_number,
|
10
|
+
:brand_id,
|
11
|
+
:categories,
|
12
|
+
:condition,
|
13
|
+
:configurable_fields,
|
14
|
+
:cost_price,
|
15
|
+
:custom_fields,
|
16
|
+
:custom_url,
|
17
|
+
:date_created,
|
18
|
+
:date_last_imported,
|
19
|
+
:date_modified,
|
20
|
+
:depth,
|
21
|
+
:description,
|
22
|
+
:discount_rules,
|
23
|
+
:downloads,
|
24
|
+
:event_date_end,
|
25
|
+
:event_date_field_name,
|
26
|
+
:event_date_start,
|
27
|
+
:event_date_type,
|
28
|
+
:fixed_cost_shipping_price,
|
29
|
+
:height,
|
30
|
+
:inventory_level,
|
31
|
+
:inventory_tracking,
|
32
|
+
:inventory_warning_level,
|
33
|
+
:is_condition_shown,
|
34
|
+
:is_featured,
|
35
|
+
:is_free_shipping,
|
36
|
+
:is_open_graph_thumbnail,
|
37
|
+
:is_preorder_only,
|
38
|
+
:is_price_hidden,
|
39
|
+
:is_visible,
|
40
|
+
:layout_file,
|
41
|
+
:meta_description,
|
42
|
+
:meta_keywords,
|
43
|
+
:myob_asset_account,
|
44
|
+
:myob_expense_account,
|
45
|
+
:myob_income_account,
|
46
|
+
:name,
|
47
|
+
:open_graph_description,
|
48
|
+
:open_graph_title,
|
49
|
+
:open_graph_type,
|
50
|
+
:option_set_display,
|
51
|
+
:option_set_id,
|
52
|
+
:order_quantity_maximum,
|
53
|
+
:order_quantity_minimum,
|
54
|
+
:page_title,
|
55
|
+
:peachtree_gl_account,
|
56
|
+
:preorder_message,
|
57
|
+
:preorder_release_date,
|
58
|
+
:price,
|
59
|
+
:price_hidden_label,
|
60
|
+
:rating_count,
|
61
|
+
:rating_total,
|
62
|
+
:related_products,
|
63
|
+
:retail_price,
|
64
|
+
:sale_price,
|
65
|
+
:search_keywords,
|
66
|
+
:sku,
|
67
|
+
:sort_order,
|
68
|
+
:tax_class_id,
|
69
|
+
:total_sold,
|
70
|
+
:type,
|
71
|
+
:upc,
|
72
|
+
:videos,
|
73
|
+
:view_count,
|
74
|
+
:warranty,
|
75
|
+
:weight,
|
76
|
+
:width
|
77
|
+
|
8
78
|
# has_many
|
9
|
-
attr_accessor :options_hash,
|
79
|
+
attr_accessor :options_hash,
|
80
|
+
:skus_hash,
|
81
|
+
:rules_hash,
|
82
|
+
:images_hash
|
10
83
|
|
11
84
|
# has_one
|
12
|
-
attr_accessor :option_set_resource,
|
85
|
+
attr_accessor :option_set_resource,
|
86
|
+
:brand_resource
|
13
87
|
|
14
|
-
# reserved
|
88
|
+
# reserved
|
15
89
|
attr_accessor :product_type
|
16
90
|
|
17
91
|
|
18
|
-
has_many :skus,
|
19
|
-
|
92
|
+
has_many :skus,
|
93
|
+
:rules,
|
94
|
+
:images,
|
95
|
+
{ options: :product_options }
|
96
|
+
|
97
|
+
has_one :brand,
|
98
|
+
:option_set
|
99
|
+
|
20
100
|
belongs_to :tax_class
|
21
|
-
|
22
101
|
end
|
23
|
-
|
24
|
-
end
|
102
|
+
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module BigcommerceAPI
|
2
|
-
|
3
2
|
class ProductOption < Resource
|
4
|
-
attr_accessor :id,
|
3
|
+
attr_accessor :id,
|
4
|
+
:display_name,
|
5
|
+
:is_required,
|
6
|
+
:option_id,
|
7
|
+
:sort_order
|
5
8
|
|
6
9
|
belongs_to :option
|
7
|
-
|
8
10
|
end
|
9
|
-
|
10
|
-
end
|
11
|
+
end
|
@@ -1,20 +1,10 @@
|
|
1
|
-
module BigcommerceAPI
|
1
|
+
module BigcommerceAPI
|
2
2
|
|
3
3
|
class Resource < Base
|
4
4
|
attr_accessor :errors
|
5
5
|
|
6
|
-
|
7
|
-
data
|
8
|
-
if v and v.is_a? String
|
9
|
-
val = v.gsub(/\n/, '').gsub(/\t/, '').strip
|
10
|
-
else
|
11
|
-
val = v
|
12
|
-
end
|
13
|
-
k = "#{k}_hash" if !self.class.has_many_options.nil? and self.class.has_many_options.include? k
|
14
|
-
k = "#{k}_resource" if !self.class.has_one_options.nil? and self.class.has_one_options.include? k
|
15
|
-
k = "#{self.resource}_#{k}" if k == 'type'
|
16
|
-
send(:"#{k}=", val) if self.respond_to? "#{k}="
|
17
|
-
end
|
6
|
+
def initialize(data)
|
7
|
+
self.assign_attributes(data)
|
18
8
|
self.attributes_were = data
|
19
9
|
end
|
20
10
|
|
@@ -24,7 +14,7 @@ module BigcommerceAPI
|
|
24
14
|
end
|
25
15
|
|
26
16
|
def save
|
27
|
-
|
17
|
+
url = self.resource_url
|
28
18
|
if self.id.nil?
|
29
19
|
# delete the parent id if there is one
|
30
20
|
self.send(self.parent + '_id=', nil) if !self.parent.nil?
|
@@ -33,30 +23,52 @@ module BigcommerceAPI
|
|
33
23
|
else
|
34
24
|
# only send updated attributes
|
35
25
|
attrs = self.attributes
|
36
|
-
body = Hash.new
|
26
|
+
body = Hash.new
|
37
27
|
self.changed.each{|c| body[c] = attrs[c]}
|
28
|
+
body.delete('date_modified')
|
38
29
|
response = BigcommerceAPI::Resource.http_request(:put, "/#{url}/#{self.id}", :body => body.to_json)
|
39
30
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
31
|
+
|
32
|
+
self.class.new(response.parsed_response)
|
33
|
+
end
|
34
|
+
|
35
|
+
def update_attributes(attributes)
|
36
|
+
assign_attributes(attributes) && save
|
37
|
+
end
|
38
|
+
|
39
|
+
def assign_attributes(attributes)
|
40
|
+
attributes.each do |k, v|
|
41
|
+
if v and v.is_a? String
|
42
|
+
val = v.gsub(/\n/, '').gsub(/\t/, '').strip
|
43
|
+
else
|
44
|
+
val = v
|
45
|
+
end
|
46
|
+
k = "#{k}_hash" if !self.class.has_many_options.nil? and self.class.has_many_options.include? k
|
47
|
+
k = "#{k}_resource" if !self.class.has_one_options.nil? and self.class.has_one_options.include? k
|
48
|
+
k = "#{self.resource}_#{k}" if k == 'type'
|
49
|
+
send(:"#{k}=", val) if self.respond_to? "#{k}="
|
45
50
|
end
|
46
51
|
end
|
47
52
|
|
48
|
-
def create
|
53
|
+
def create
|
49
54
|
# delete the parent id if there is one
|
50
55
|
url = self.resource_url
|
51
56
|
self.send(self.parent + '_id=', nil) if !self.parent.nil?
|
52
57
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
attrs = self.attributes
|
59
|
+
body = Hash.new
|
60
|
+
self.changed.each{|c| body[c] = attrs[c]}
|
61
|
+
|
62
|
+
response = BigcommerceAPI::Resource.http_request(:post, "/#{url}", :body => body.to_json)
|
63
|
+
|
64
|
+
return self.class.new(response.parsed_response)
|
65
|
+
end
|
66
|
+
|
67
|
+
def delete
|
68
|
+
url = self.resource_url
|
69
|
+
BigcommerceAPI::Resource.http_request(:delete, "/#{url}/#{self.id}")
|
70
|
+
|
71
|
+
return true
|
60
72
|
end
|
61
73
|
|
62
74
|
def find_for_reload
|
@@ -92,7 +104,7 @@ module BigcommerceAPI
|
|
92
104
|
return changed
|
93
105
|
end
|
94
106
|
|
95
|
-
|
107
|
+
class << self
|
96
108
|
attr_accessor :has_many_options, :has_one_options, :belongs_to_options
|
97
109
|
|
98
110
|
def has_many(*names)
|
@@ -134,7 +146,7 @@ module BigcommerceAPI
|
|
134
146
|
end
|
135
147
|
end
|
136
148
|
end
|
137
|
-
|
149
|
+
|
138
150
|
def belongs_to(*names)
|
139
151
|
self.belongs_to_options = names.collect{|x| x.is_a?(Hash) ? x.keys.first.to_s : x.to_s}
|
140
152
|
names.each do |m|
|
@@ -156,41 +168,73 @@ module BigcommerceAPI
|
|
156
168
|
end
|
157
169
|
end
|
158
170
|
|
159
|
-
|
160
|
-
|
161
|
-
|
171
|
+
def resource
|
172
|
+
out = self.name.split('::').last.downcase
|
173
|
+
last = out.split(//).last.to_s
|
162
174
|
if last == 'y'
|
163
175
|
out = out.chomp('y') + 'ies'
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
176
|
+
elsif last == 's'
|
177
|
+
out += 'es'
|
178
|
+
else
|
179
|
+
out += 's'
|
180
|
+
end
|
181
|
+
return out
|
182
|
+
end
|
183
|
+
|
184
|
+
def all(params={})
|
185
|
+
resources = BigcommerceAPI::Resource.http_request(:get, "/#{resource}", :query => date_adjust(params))
|
186
|
+
(resources.success? and !resources.nil?) ? resources.collect{|r| self.new(r)} : []
|
187
|
+
end
|
188
|
+
|
189
|
+
def find(id)
|
190
|
+
return if id.blank?
|
178
191
|
r = BigcommerceAPI::Resource.http_request(:get, "/#{resource}/#{id}")
|
179
|
-
|
180
|
-
|
192
|
+
(r.success? and !r.nil?) ? self.new(r) : nil
|
193
|
+
end
|
181
194
|
|
182
195
|
def http_request(verb, url, options={})
|
183
196
|
begin
|
184
|
-
BigcommerceAPI::Base.send(verb, url, options)
|
197
|
+
response = BigcommerceAPI::Base.send(verb, url, options)
|
198
|
+
if response.code >= 400
|
199
|
+
message = case response.code
|
200
|
+
when 429
|
201
|
+
"Too many requests, please retry in #{response.headers["x-retry-after"]} second."
|
202
|
+
when 500
|
203
|
+
"Internal Error"
|
204
|
+
else
|
205
|
+
parse_errors(response)
|
206
|
+
end
|
207
|
+
raise BigcommerceAPI::Error.new(response.code, message)
|
208
|
+
end
|
209
|
+
response
|
185
210
|
rescue SocketError => e
|
186
211
|
BigcommerceAPI::Result.new(:success => false, :errors => "Invalid URL")
|
187
212
|
end
|
188
213
|
end
|
189
|
-
|
214
|
+
|
215
|
+
private
|
216
|
+
|
217
|
+
# recursive function to convert hash into string, e.g. {a: {b: "c"}, d: "e"} becomes "c e"
|
218
|
+
def hash_to_s(hash)
|
219
|
+
if hash.is_a?(Array)
|
220
|
+
hash.map do |value|
|
221
|
+
hash_to_s(value)
|
222
|
+
end.to_sentence
|
223
|
+
elsif hash.is_a?(Hash)
|
224
|
+
hash_to_s(hash.values)
|
225
|
+
else
|
226
|
+
hash.to_s.gsub(/[,.]$/, '')
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
def parse_errors(response)
|
231
|
+
hash_to_s(response.parsed_response)
|
232
|
+
end
|
233
|
+
end # end class methods
|
190
234
|
|
191
235
|
private
|
192
|
-
|
236
|
+
attr_accessor :attributes_were
|
193
237
|
|
194
238
|
end
|
195
239
|
|
196
|
-
end
|
240
|
+
end
|