bigcommerce_api 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +20 -0
- data/README.md +112 -0
- data/lib/bigcommerce_api/base.rb +95 -0
- data/lib/bigcommerce_api/image.rb +10 -0
- data/lib/bigcommerce_api/option.rb +10 -0
- data/lib/bigcommerce_api/option_set.rb +10 -0
- data/lib/bigcommerce_api/option_set_option.rb +11 -0
- data/lib/bigcommerce_api/option_value.rb +10 -0
- data/lib/bigcommerce_api/order.rb +17 -0
- data/lib/bigcommerce_api/order_product.rb +49 -0
- data/lib/bigcommerce_api/order_status.rb +8 -0
- data/lib/bigcommerce_api/product.rb +22 -0
- data/lib/bigcommerce_api/product_option.rb +10 -0
- data/lib/bigcommerce_api/resource.rb +152 -0
- data/lib/bigcommerce_api/shipment.rb +31 -0
- data/lib/bigcommerce_api/shippingaddress.rb +43 -0
- data/lib/bigcommerce_api/sku.rb +58 -0
- data/lib/bigcommerce_api/store.rb +21 -0
- data/lib/bigcommerce_api.rb +20 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6a2d1f41c5fd3384735697fa107295fdfcc973b9
|
4
|
+
data.tar.gz: d2b8cb2d60cb397d7e02a8b2e534fc9ef58cce07
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5f809dcf20e171ca37b01f6336f3b7eb5d9618bdc41a338e8a9eaab64f32acde69bf992f529d7addb23d6c8aad6d43d61df0848f28dd36eb912b9b278d7e7f02
|
7
|
+
data.tar.gz: 6f64c6f13d33851e15108ca7733547e6e539e05e2031a3caf6a52e8b9e3666abefd52872f844c7b4e05ffca487e16a53fc46b877f3b1503b0c8b5ec39fb473d3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Mark Dickson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
Bigcommerce API (V2) Client
|
2
|
+
================================
|
3
|
+
Full featured Ruby Gem to connect to the Big Commerce API. Similar to the the official gem by Bigcommerce, but with more Ruby-like syntax, allowing you to interact with Ruby objects (with familiar `find` and `save` methods) instead of hashes.
|
4
|
+
|
5
|
+
Additionally, it is compatible with the new OAuth authentication.
|
6
|
+
|
7
|
+
Developed and maintained by [Whiplash Merchandising](http://www.whiplashmerch.com).
|
8
|
+
|
9
|
+
### Requirements
|
10
|
+
|
11
|
+
- Ruby 1.8.7+
|
12
|
+
- Rubygems
|
13
|
+
- JSON
|
14
|
+
- ActiveSupport 2.3.5+
|
15
|
+
- Httparty
|
16
|
+
|
17
|
+
A valid username, API key, and store URL OR app client id, OAuth token, and store hash/id are required to authenticate requests.
|
18
|
+
|
19
|
+
### Installation
|
20
|
+
|
21
|
+
```
|
22
|
+
git clone git://github.com/ideaoforder/bigcommerce_api.git
|
23
|
+
cd bigcommerce_api
|
24
|
+
rake install
|
25
|
+
```
|
26
|
+
|
27
|
+
Or if you're using Bundler:
|
28
|
+
|
29
|
+
```
|
30
|
+
gem 'bigcommerce_api', '>=0.4.3', :git => 'git://github.com/ideaoforder/bigcommerce_api'
|
31
|
+
```
|
32
|
+
|
33
|
+
### Configuration
|
34
|
+
|
35
|
+
To use the API client in your Ruby code:
|
36
|
+
```
|
37
|
+
require 'rubygems'
|
38
|
+
require 'bigcommerce_api'
|
39
|
+
```
|
40
|
+
|
41
|
+
You can currently connect using the existing api key auth:
|
42
|
+
```
|
43
|
+
api = BigcommerceAPI::Base.new(
|
44
|
+
:api_key => 'XXXXXXXXXXXXX',
|
45
|
+
:username => 'XXXXXXXX',
|
46
|
+
:store_url => 'https://YOUR_STORE.mybigcommerce.com'
|
47
|
+
)
|
48
|
+
```
|
49
|
+
|
50
|
+
Or using the new OAuth credentials (currently in Alpha at Bigcommerce):
|
51
|
+
```
|
52
|
+
api = BigcommerceAPI::Base.new(
|
53
|
+
:client_id => APP_CLIENT_ID,
|
54
|
+
:store_hash => STORE_HASH/ID,
|
55
|
+
:access_token => OAUTH_ACCESS_TOKEN
|
56
|
+
)
|
57
|
+
```
|
58
|
+
|
59
|
+
You can test your connection by getting the time
|
60
|
+
|
61
|
+
```
|
62
|
+
BigcommerceAPI::Base.get_time
|
63
|
+
```
|
64
|
+
|
65
|
+
A valid time means your connection and credentials are good.
|
66
|
+
|
67
|
+
### Usage
|
68
|
+
|
69
|
+
The API currently gives you read/write access to MOST of your Big Commerce API V2 resources (https://developer.bigcommerce.com/docs/api/v2)
|
70
|
+
|
71
|
+
```
|
72
|
+
$ irb
|
73
|
+
|
74
|
+
BigcommerceAPI::Base.new(:api_key => 'XXXXXXXXXXXXX', :username => 'XXXXXXXX', :store_url => 'https://YOUR_STORE.mybigcommerce.com')
|
75
|
+
|
76
|
+
products = BigcommerceAPI::Product.all
|
77
|
+
|
78
|
+
order = BigcommerceAPI::Order.find(NNN)
|
79
|
+
order.status_id = 3
|
80
|
+
if order.save
|
81
|
+
puts "success!"
|
82
|
+
else
|
83
|
+
puts order.errors.join('; ')
|
84
|
+
end
|
85
|
+
|
86
|
+
orders = BigcommerceAPI::Order.all(:status_id => 11, :min_date_created => '2008-01-01'})
|
87
|
+
|
88
|
+
shipment = BigcommerceAPI::Shipment.create(
|
89
|
+
:order_id => bc_order.id,
|
90
|
+
:order_address_id => SHIPMENT_ADDRESS_ID,
|
91
|
+
:tracking_number => 'XXXXXX',
|
92
|
+
:order_date => bc_order.date_created,
|
93
|
+
:items => [{:order_product_id => bc_order_product.id, :quantity => NNN}]
|
94
|
+
)
|
95
|
+
|
96
|
+
```
|
97
|
+
|
98
|
+
### Contributing to bigcommerce_api
|
99
|
+
|
100
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
101
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
102
|
+
* Fork the project.
|
103
|
+
* Start a feature/bugfix branch.
|
104
|
+
* Commit and push until you are happy with your contribution.
|
105
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
106
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
107
|
+
|
108
|
+
### Copyright
|
109
|
+
|
110
|
+
Copyright (c) 2014 Mark Dickson / Whiplash Merchandising. See LICENSE.txt for
|
111
|
+
further details.
|
112
|
+
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module BigcommerceAPI
|
2
|
+
|
3
|
+
class Base
|
4
|
+
extend BigcommerceAPI
|
5
|
+
|
6
|
+
include HTTParty
|
7
|
+
format :json
|
8
|
+
headers 'Accept' => "application/json"
|
9
|
+
headers 'Content-Type' => "application/json"
|
10
|
+
|
11
|
+
def initialize(params={})
|
12
|
+
# for the time being, accept old school API params
|
13
|
+
if params[:username] and params[:api_key]
|
14
|
+
self.class.basic_auth params[:username], params[:api_key]
|
15
|
+
# default to Oauth
|
16
|
+
else
|
17
|
+
self.class.headers 'X-Auth-Client' => params[:client_id]
|
18
|
+
self.class.headers 'X-Auth-Token' => params[:access_token]
|
19
|
+
end
|
20
|
+
|
21
|
+
# if we're using Oauth, we're probably grabbing :store_hash
|
22
|
+
# accept :store_url for legacy purposes
|
23
|
+
if params[:store_url]
|
24
|
+
self.class.base_uri(params[:store_url] + '/api/v2/')
|
25
|
+
else
|
26
|
+
self.class.base_uri("https://api.bigcommerce.com/stores/#{params[:store_hash]}/v2/")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def time
|
31
|
+
response = self.class.get('/time')
|
32
|
+
response.parsed_response['time']
|
33
|
+
end
|
34
|
+
alias_method :get_time, :time
|
35
|
+
|
36
|
+
def store
|
37
|
+
response = self.class.get('/store')
|
38
|
+
if response
|
39
|
+
return Store.new(response.parsed_response)
|
40
|
+
else
|
41
|
+
return nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
alias_method :info, :store
|
45
|
+
alias_method :information, :store
|
46
|
+
alias_method :settings, :store
|
47
|
+
|
48
|
+
# this grabs all of the FIRST LEVEL attributes
|
49
|
+
# it ignores hashed and constructed nested attributes,
|
50
|
+
# since Big Commerce won't let us set those anyway
|
51
|
+
def attributes(strip_empty=false)
|
52
|
+
hash = {}
|
53
|
+
self.instance_variables.each {|var| hash[var.to_s.delete("@")] = self.instance_variable_get(var) if (var.to_s['_hash'].nil? and var.to_s['_resource'].nil? and var.to_s[self.resource + '_type'].nil?) }
|
54
|
+
hash = BigcommerceAPI::Resource.date_adjust(hash)
|
55
|
+
BigcommerceAPI::Resource.clean!(hash) if strip_empty
|
56
|
+
hash.delete('id') if strip_empty
|
57
|
+
return hash
|
58
|
+
end
|
59
|
+
|
60
|
+
class << self
|
61
|
+
def clean!(hash)
|
62
|
+
hash.each do |k, v|
|
63
|
+
if v.is_a? Hash
|
64
|
+
clean!(v)
|
65
|
+
else
|
66
|
+
hash.delete(k) if v.nil? or v == ''
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Returns the date formatted as
|
72
|
+
# RFC 2822 string
|
73
|
+
def to_rfc2822(datetime)
|
74
|
+
datetime.strftime("%a, %d %b %Y %H:%M:%S %z")
|
75
|
+
end
|
76
|
+
|
77
|
+
def date_adjust(params)
|
78
|
+
[:date_created, :date_modified, :date_last_imported, :date_shipped, :min_date_created, :max_date_created, :min_date_modified, :max_date_modified, :min_date_last_imported, :max_date_last_imported].each do |date|
|
79
|
+
[date, date.to_s].each do |d|
|
80
|
+
if params[d] and !params[d].nil? and params[d] != ''
|
81
|
+
if params[d].is_a?(String)
|
82
|
+
params[d] = DateTime.parse(params[d])
|
83
|
+
end
|
84
|
+
# params[d] = CGI::escape(to_rfc2822(params[d]))
|
85
|
+
params[d] = to_rfc2822(params[d])
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
return params
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module BigcommerceAPI
|
2
|
+
|
3
|
+
class Order < Resource
|
4
|
+
attr_accessor :refunded_amount, :payment_status, :handling_cost_inc_tax, :shipping_cost_ex_tax, :handling_cost_tax, :currency_id, :items_shipped, :handling_cost_ex_tax, :discount_amount, :staff_notes, :default_currency_id, :store_credit_amount, :payment_method, :total_ex_tax, :subtotal_inc_tax, :subtotal_ex_tax, :date_modified, :currency_exchange_rate, :wrapping_cost_inc_tax, :wrapping_cost_ex_tax, :handling_cost_tax_class_id, :base_handling_cost, :id, :is_deleted, :coupon_discount, :customer_message, :geoip_country, :gift_certificate_amount, :total_inc_tax, :base_wrapping_cost, :date_shipped, :billing_address, :geoip_country_iso2, :payment_provider_id, :wrapping_cost_tax_class_id, :base_shipping_cost, :subtotal_tax, :wrapping_cost_tax, :status_id, :customer_id, :default_currency_code, :currency_code, :order_is_digital, :items_total, :total_tax, :shipping_cost_inc_tax, :status, :shipping_address_count, :ip_address, :shipping_cost_tax_class_id, :shipping_cost_tax, :date_created, :products_hash, :shipping_addresses_hash, :coupons_hash
|
5
|
+
# :coupons, :shipping_addresses,
|
6
|
+
|
7
|
+
has_many :coupons, {:products => :order_products}, {:shipping_addresses => :shippingaddresses}
|
8
|
+
belongs_to :customer, :currency, :default_currency, :shipping_cost_tax_class, :wrapping_cost_tax_class, :payment_provider, :handling_cost_tax_class
|
9
|
+
|
10
|
+
def shipments
|
11
|
+
s = BigcommerceAPI::Base.get '/orders/' + self.id.to_s + '/shipments'
|
12
|
+
(s.success? and !s.nil?) ? s.collect{|o| BigcommerceAPI::Shipment.new(o)} : []
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module BigcommerceAPI
|
2
|
+
|
3
|
+
class OrderProduct < Resource
|
4
|
+
attr_accessor :configurable_fields, :bin_picking_number, :cost_price_ex_tax, :base_total, :name, :fixed_shipping_cost, :price_tax, :price_ex_tax, :refund_amount, :quantity, :price_inc_tax, :product_id, :return_id, :is_refunded, :base_price, :order_id, :option_set_id, :weight, :total_ex_tax, :product_options, :event_name, :wrapping_cost_inc_tax, :wrapping_cost_ex_tax, :order_address_id, :id, :wrapping_message, :base_wrapping_cost, :cost_price_inc_tax, :total_inc_tax, :type, :applied_discounts, :wrapping_name, :cost_price_tax, :base_cost_price, :sku, :parent_order_product_id, :wrapping_cost_tax, :ebay_item_id, :quantity_shipped, :total_tax, :ebay_transaction_id, :event_date, :is_bundled_product
|
5
|
+
|
6
|
+
belongs_to :option_set, {:parent_order_product => :order_product}, :ebay_item, :ebay_transaction, :return, :product, :order
|
7
|
+
# reserved
|
8
|
+
attr_accessor :orderproduct_type
|
9
|
+
|
10
|
+
def shippingaddress
|
11
|
+
a = BigcommerceAPI::Base.get "/orders/#{self.order_id}/shippingaddresses/#{self.order_address_id}"
|
12
|
+
(a.success? and !a.nil?) ? BigcommerceAPI::Shippingaddress.new(a) : nil
|
13
|
+
end
|
14
|
+
|
15
|
+
# TODO: these can probably go in a ReadOnly class
|
16
|
+
def save
|
17
|
+
self.errors = ["Shipping Addresses are readonly"]
|
18
|
+
return false
|
19
|
+
end
|
20
|
+
|
21
|
+
def create(params={})
|
22
|
+
self.errors = ["Shipping Addresses are readonly"]
|
23
|
+
return false
|
24
|
+
end
|
25
|
+
|
26
|
+
# this overrides the default method, since this has to come in with an order id
|
27
|
+
def resource_url
|
28
|
+
"orders/#{self.order_id}/products"
|
29
|
+
end
|
30
|
+
|
31
|
+
def parent
|
32
|
+
'order'
|
33
|
+
end
|
34
|
+
|
35
|
+
class << self
|
36
|
+
def all(order_id, params={})
|
37
|
+
resources = BigcommerceAPI::Base.get("/orders/#{order_id}/products", :query => date_adjust(params))
|
38
|
+
(resources.success? and !resources.nil?) ? resources.collect{|r| self.new(r)} : []
|
39
|
+
end
|
40
|
+
|
41
|
+
def find(order_id, id)
|
42
|
+
r = BigcommerceAPI::Base.get("/orders/#{order_id}/products/#{id}")
|
43
|
+
(r.success? and !r.nil?) ? self.new(r) : nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module BigcommerceAPI
|
2
|
+
|
3
|
+
class Product < Resource
|
4
|
+
# incoming attributes
|
5
|
+
attr_accessor :brand_id, :myob_expense_account, :inventory_tracking, :preorder_release_date, :tax_class_id, :sku, :date_modified, :fixed_cost_shipping_price, :categories, :meta_description, :sort_order, :related_products, :tax_class, :is_visible, :description, :layout_file, :meta_keywords, :rating_total, :price, :event_date_field_name, :height, :order_quantity_minimum, :myob_asset_account, :order_quantity_maximum, :peachtree_gl_account, :retail_price, :availability_description, :weight, :is_preorder_only, :date_created, :open_graph_title, :rating_count, :open_graph_type, :option_set_id, :is_featured, :date_last_imported, :option_set_display, :availability, :is_condition_shown, :name, :inventory_warning_level, :event_date_end, :cost_price, :inventory_level, :event_date_type, :upc, :open_graph_description, :depth, :custom_url, :myob_income_account, :condition, :is_price_hidden, :custom_fields, :configurable_fields, :discount_rules, :warranty, :total_sold, :view_count, :event_date_start, :price_hidden_label, :videos, :sale_price, :bin_picking_number, :preorder_message, :is_open_graph_thumbnail, :search_keywords, :is_free_shipping, :width, :type, :id, :page_title, :downloads
|
6
|
+
# has_many
|
7
|
+
attr_accessor :options_hash, :skus_hash, :rules_hash, :images_hash
|
8
|
+
|
9
|
+
# has_one
|
10
|
+
attr_accessor :option_set_resource, :brand_resource
|
11
|
+
|
12
|
+
# reserved
|
13
|
+
attr_accessor :product_type
|
14
|
+
|
15
|
+
|
16
|
+
has_many :skus, :rules, :images, {:options => :product_options}
|
17
|
+
has_one :brand, :option_set
|
18
|
+
belongs_to :tax_class
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
module BigcommerceAPI
|
2
|
+
|
3
|
+
class Resource < Base
|
4
|
+
attr_accessor :errors
|
5
|
+
|
6
|
+
def initialize(data)
|
7
|
+
data.each do |k, v|
|
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
|
18
|
+
end
|
19
|
+
|
20
|
+
def save
|
21
|
+
# delete the parent id if there is one
|
22
|
+
url = self.resource_url
|
23
|
+
self.send(self.parent + '_id=', nil) if !self.parent.nil?
|
24
|
+
|
25
|
+
if self.id.nil?
|
26
|
+
response = BigcommerceAPI::Base.post("/#{url}", :body => self.attributes(true).to_json)
|
27
|
+
else
|
28
|
+
response = BigcommerceAPI::Base.put("/#{url}/#{self.id}", :body => self.attributes(true).to_json)
|
29
|
+
end
|
30
|
+
if response.success?
|
31
|
+
return self.id.nil? ? self.class.new(response.parsed_response) : true
|
32
|
+
else
|
33
|
+
self.errors = response.parsed_response
|
34
|
+
return false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def create(params={})
|
39
|
+
# delete the parent id if there is one
|
40
|
+
url = self.resource_url
|
41
|
+
self.send(self.parent + '_id=', nil) if !self.parent.nil?
|
42
|
+
|
43
|
+
response = BigcommerceAPI::Base.post("/#{url}", :body => date_adjust(params).to_json)
|
44
|
+
if response.success?
|
45
|
+
return self.class.new(response.parsed_response)
|
46
|
+
else
|
47
|
+
self.errors = response.parsed_response
|
48
|
+
return false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def resource
|
53
|
+
self.class.name.downcase.to_s.split('::').last
|
54
|
+
end
|
55
|
+
|
56
|
+
def resource_url
|
57
|
+
self.class.resource
|
58
|
+
end
|
59
|
+
|
60
|
+
def parent
|
61
|
+
nil
|
62
|
+
end
|
63
|
+
|
64
|
+
class << self
|
65
|
+
attr_accessor :has_many_options, :has_one_options, :belongs_to_options
|
66
|
+
|
67
|
+
def has_many(*names)
|
68
|
+
self.has_many_options = names.collect{|x| x.is_a?(Hash) ? x.keys.first.to_s : x.to_s}
|
69
|
+
names.each do |m|
|
70
|
+
if m.is_a? Hash
|
71
|
+
meth = m.keys.first.to_s
|
72
|
+
res = m.values.first.to_s
|
73
|
+
else
|
74
|
+
meth = m.to_s
|
75
|
+
res = m.to_s
|
76
|
+
end
|
77
|
+
define_method meth do
|
78
|
+
out = BigcommerceAPI::Base.get("#{self.send(meth + '_hash')['resource']}")
|
79
|
+
obj = res.singularize.camelize
|
80
|
+
if out and !defined?('BigcommerceAPI::' + obj).nil?
|
81
|
+
(out.success? and !out.nil?) ? out.collect{|o| ('BigcommerceAPI::' + obj).constantize.new(o)} : []
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def has_one(*names)
|
88
|
+
self.has_one_options = names.collect{|x| x.is_a?(Hash) ? x.keys.first.to_s : x.to_s}
|
89
|
+
names.each do |m|
|
90
|
+
if m.is_a? Hash
|
91
|
+
meth = m.keys.first.to_s
|
92
|
+
resource = m.values.first.to_s
|
93
|
+
else
|
94
|
+
meth = m.to_s
|
95
|
+
resource = m.to_s
|
96
|
+
end
|
97
|
+
define_method meth do
|
98
|
+
out = BigcommerceAPI::Base.get("#{self.send(meth + '_resource')['resource']}")
|
99
|
+
obj = resource.singularize.camelize
|
100
|
+
if out and !defined?('BigcommerceAPI::' + obj).nil?
|
101
|
+
(out.success? and !out.nil?) ? ('BigcommerceAPI::' + obj).constantize.new(out) : nil
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def belongs_to(*names)
|
108
|
+
self.belongs_to_options = names.collect{|x| x.is_a?(Hash) ? x.keys.first.to_s : x.to_s}
|
109
|
+
names.each do |m|
|
110
|
+
if m.is_a? Hash
|
111
|
+
meth = m.keys.first.to_s
|
112
|
+
resource = m.values.first.to_s
|
113
|
+
else
|
114
|
+
meth = m.to_s
|
115
|
+
resource = m.to_s
|
116
|
+
end
|
117
|
+
define_method meth do
|
118
|
+
obj = resource.singularize.camelize
|
119
|
+
url = '/' + meth.pluralize + '/' + self.send(meth + "_id").to_s
|
120
|
+
out = BigcommerceAPI::Base.get("#{url}")
|
121
|
+
if out and !defined?('BigcommerceAPI::' + obj).nil?
|
122
|
+
(out.success? and !out.nil?) ? ('BigcommerceAPI::' + obj).constantize.new(out) : nil
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def resource
|
129
|
+
out = self.name.split('::').last.downcase
|
130
|
+
last = out.split(//).last(1).to_s
|
131
|
+
if last == 's'
|
132
|
+
out += 'es'
|
133
|
+
else
|
134
|
+
out += 's'
|
135
|
+
end
|
136
|
+
return out
|
137
|
+
end
|
138
|
+
|
139
|
+
def all(params={})
|
140
|
+
resources = BigcommerceAPI::Base.get("/#{resource}", :query => date_adjust(params))
|
141
|
+
(resources.success? and !resources.nil?) ? resources.collect{|r| self.new(r)} : []
|
142
|
+
end
|
143
|
+
|
144
|
+
def find(id)
|
145
|
+
r = BigcommerceAPI::Base.get("/#{resource}/#{id}")
|
146
|
+
(r.success? and !r.nil?) ? self.new(r) : nil
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module BigcommerceAPI
|
2
|
+
|
3
|
+
class Shipment < Resource
|
4
|
+
attr_accessor :items, :comments, :order_id, :shipping_address, :order_address_id, :id, :tracking_number, :billing_address, :customer_id, :shipping_method, :date_created
|
5
|
+
|
6
|
+
belongs_to :customer, {:order_address => :shipping_address}, :order
|
7
|
+
|
8
|
+
# these are all overrides, since Shipments work a little differently
|
9
|
+
def resource_url
|
10
|
+
"orders/#{self.order_id}/shipments"
|
11
|
+
end
|
12
|
+
|
13
|
+
def parent
|
14
|
+
'order'
|
15
|
+
end
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def all(order_id, params={})
|
19
|
+
resources = BigcommerceAPI::Base.get("/orders/#{order_id}/shipments", :query => date_adjust(params))
|
20
|
+
(resources.success? and !resources.nil?) ? resources.collect{|r| self.new(r)} : []
|
21
|
+
end
|
22
|
+
|
23
|
+
def find(order_id, id)
|
24
|
+
r = BigcommerceAPI::Base.get("/orders/#{order_id}/shipments/#{id}")
|
25
|
+
(r.success? and !r.nil?) ? self.new(r) : nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module BigcommerceAPI
|
2
|
+
|
3
|
+
class Shippingaddress < Resource
|
4
|
+
attr_accessor :shipping_zone_id, :handling_cost_inc_tax, :city, :company, :handling_cost_tax, :cost_tax_class_id, :zip, :street_1, :items_shipped, :country_iso2, :country, :street_2, :handling_cost_ex_tax, :cost_tax, :order_id, :shipping_zone_name, :handling_cost_tax_class_id, :base_handling_cost, :id, :phone, :last_name, :cost_inc_tax, :base_cost, :shipping_method, :items_total, :cost_ex_tax, :email, :state, :first_name
|
5
|
+
|
6
|
+
belongs_to :shipping_zone, :order
|
7
|
+
|
8
|
+
# this overrides the default method, since this has to come in with an order id
|
9
|
+
def resource_url
|
10
|
+
"orders/#{self.order_id}/shippingaddresses"
|
11
|
+
end
|
12
|
+
|
13
|
+
def parent
|
14
|
+
'order'
|
15
|
+
end
|
16
|
+
|
17
|
+
# TODO: these can probably go in a ReadOnly class
|
18
|
+
def save
|
19
|
+
self.errors = ["Shipping Addresses are readonly"]
|
20
|
+
return false
|
21
|
+
end
|
22
|
+
|
23
|
+
def create(params={})
|
24
|
+
self.errors = ["Shipping Addresses are readonly"]
|
25
|
+
return false
|
26
|
+
end
|
27
|
+
|
28
|
+
class << self
|
29
|
+
def all(order_id, params={})
|
30
|
+
resources = BigcommerceAPI::Base.get("/orders/#{order_id}/shippingaddresses", :query => date_adjust(params))
|
31
|
+
(resources.success? and !resources.nil?) ? resources.collect{|r| self.new(r)} : []
|
32
|
+
end
|
33
|
+
|
34
|
+
def find(order_id, id)
|
35
|
+
r = BigcommerceAPI::Base.get("/orders/#{order_id}/shippingaddresses/#{id}")
|
36
|
+
(r.success? and !r.nil?) ? self.new(r) : nil
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module BigcommerceAPI
|
2
|
+
|
3
|
+
class Sku < Resource
|
4
|
+
attr_accessor :id, :sku, :product_id, :cost_price, :upc, :inventory_level, :inventory_warning_level, :bin_picking_number, :options
|
5
|
+
|
6
|
+
belongs_to :product
|
7
|
+
|
8
|
+
def resource_url
|
9
|
+
"products/#{self.product_id}/skus"
|
10
|
+
end
|
11
|
+
|
12
|
+
def parent
|
13
|
+
'product'
|
14
|
+
end
|
15
|
+
|
16
|
+
def product_option_id
|
17
|
+
self.options.first['product_option_id']
|
18
|
+
end
|
19
|
+
|
20
|
+
def option_value_id
|
21
|
+
self.options.first['option_value_id']
|
22
|
+
end
|
23
|
+
|
24
|
+
def product_option
|
25
|
+
po = BigcommerceAPI::Base.get '/products/' + self.product_id.to_s + '/options/' + self.product_option_id.to_s
|
26
|
+
(po.success? and !po.nil?) ? ProductOption.new(po) : nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def option_value
|
30
|
+
option_id = self.product_option.option_id
|
31
|
+
ov = BigcommerceAPI::Base.get '/options/' + option_id.to_s + '/values/' + self.option_value_id.to_s
|
32
|
+
(ov.success? and !ov.nil?) ? OptionValue.new(ov) : nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def description
|
36
|
+
out = Array.new
|
37
|
+
po = self.product_option
|
38
|
+
ov = self.option_value
|
39
|
+
out << po.display_name if po
|
40
|
+
out << ov.label if ov
|
41
|
+
return out.join(' ')
|
42
|
+
end
|
43
|
+
|
44
|
+
class << self
|
45
|
+
def all(product_id, params={})
|
46
|
+
resources = BigcommerceAPI::Base.get("/products/#{product_id}/skus", :query => date_adjust(params))
|
47
|
+
(resources.success? and !resources.nil?) ? resources.collect{|r| self.new(r)} : []
|
48
|
+
end
|
49
|
+
|
50
|
+
def find(product_id, id)
|
51
|
+
r = BigcommerceAPI::Base.get("/products/#{product_id}/skus/#{id}")
|
52
|
+
(r.success? and !r.nil?) ? self.new(r) : nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module BigcommerceAPI
|
2
|
+
|
3
|
+
class Store < Base
|
4
|
+
attr_accessor :errors, :id, :domain, :name, :address, :phone, :admin_email, :order_email, :language, :currency, :currency_symbol, :currency_symbol_location, :decimal_separator, :thousands_separator, :decimal_places, :weight_units, :dimension_units, :plan_name
|
5
|
+
|
6
|
+
# Sample response
|
7
|
+
# {"id"=>"XXXX", "domain"=>"XXXX.mybigcommerce.com", "name"=>"XXXX", "address"=>"", "phone"=>"", "admin_email"=>"XXX", "order_email"=>"XXX", "language"=>"en", "currency"=>"USD", "currency_symbol"=>"$", "decimal_separator"=>".", "thousands_separator"=>",", "decimal_places"=>2, "currency_symbol_location"=>"left", "weight_units"=>"LBS", "dimension_units"=>"Inches", "plan_name"=>"Partner Sandbox"}
|
8
|
+
def initialize(data)
|
9
|
+
data.each do |k, v|
|
10
|
+
if v and v.is_a? String
|
11
|
+
val = v.gsub(/\n/, '').gsub(/\t/, '').strip
|
12
|
+
else
|
13
|
+
val = v
|
14
|
+
end
|
15
|
+
send(:"#{k}=", val) if self.respond_to? "#{k}="
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require 'httparty'
|
3
|
+
require 'active_support/inflector'
|
4
|
+
|
5
|
+
require 'bigcommerce_api/base'
|
6
|
+
require 'bigcommerce_api/resource'
|
7
|
+
require 'bigcommerce_api/image'
|
8
|
+
require 'bigcommerce_api/option'
|
9
|
+
require 'bigcommerce_api/option_set'
|
10
|
+
require 'bigcommerce_api/option_set_option'
|
11
|
+
require 'bigcommerce_api/option_value'
|
12
|
+
require 'bigcommerce_api/order'
|
13
|
+
require 'bigcommerce_api/order_product'
|
14
|
+
require 'bigcommerce_api/order_status'
|
15
|
+
require 'bigcommerce_api/product'
|
16
|
+
require 'bigcommerce_api/product_option'
|
17
|
+
require 'bigcommerce_api/shipment'
|
18
|
+
require 'bigcommerce_api/shippingaddress'
|
19
|
+
require 'bigcommerce_api/sku'
|
20
|
+
require 'bigcommerce_api/store'
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bigcommerce_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Dickson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.3.5
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.3.5
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rdoc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: jeweler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Enables Ruby applications to communicate with the BigCommerce API V2.
|
84
|
+
email: mark@sitesteaders.com
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files:
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
files:
|
91
|
+
- lib/bigcommerce_api.rb
|
92
|
+
- lib/bigcommerce_api/base.rb
|
93
|
+
- lib/bigcommerce_api/image.rb
|
94
|
+
- lib/bigcommerce_api/option.rb
|
95
|
+
- lib/bigcommerce_api/option_set.rb
|
96
|
+
- lib/bigcommerce_api/option_set_option.rb
|
97
|
+
- lib/bigcommerce_api/option_value.rb
|
98
|
+
- lib/bigcommerce_api/order.rb
|
99
|
+
- lib/bigcommerce_api/order_product.rb
|
100
|
+
- lib/bigcommerce_api/order_status.rb
|
101
|
+
- lib/bigcommerce_api/product.rb
|
102
|
+
- lib/bigcommerce_api/product_option.rb
|
103
|
+
- lib/bigcommerce_api/resource.rb
|
104
|
+
- lib/bigcommerce_api/shipment.rb
|
105
|
+
- lib/bigcommerce_api/shippingaddress.rb
|
106
|
+
- lib/bigcommerce_api/sku.rb
|
107
|
+
- lib/bigcommerce_api/store.rb
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
homepage: http://github.com/ideaoforder/bigcommerce_api
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ! '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.1.11
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Enables Ruby applications to communicate with the BigCommerce API
|
134
|
+
test_files: []
|