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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01abb5cc7c76c570309b4e94698f1c24e4a5c59f
4
- data.tar.gz: a6a7cd9349a3092e189a9642c5d71a7692409bb1
3
+ metadata.gz: 9d3066447f844c7d5ef596f8858d00c24dd909e5
4
+ data.tar.gz: 72b7f45bbc559b5c397de28cf81eb875347e7fd6
5
5
  SHA512:
6
- metadata.gz: 94507ff8220f1d9785d0dbd72c38b84c6cd175c01672b883cd0cade6d3604aeddca24da80affd2a825e73c6a7e0ce19c1d604f65465c6d67e59ca7394669b706
7
- data.tar.gz: 2ababf2435e4cebd995a33209b0f0dc54436afb85407d0eac6fb005810c554bb1f4fb06849283a7691579a1c61e9e99f770a388e782404da2ad76cf26d5de3b3
6
+ metadata.gz: 2c78bb60cc4a41cf4283c87effc4ea0a6800a89319926517581bd7ca7e2abb243c653c02ebc275b7d13031fd9fe85e0f98d07028a8523f7d60eb5e5c3758f347
7
+ data.tar.gz: ec654c8e1088386c19a16ccdaaa4112174339319ee1981672e0b155c22b5762c9dc194b05b71d238dba60f8e5c6940d77b1ef3420f231631844e0ad4b2286aad
@@ -7,10 +7,14 @@ require 'bigcommerce_api/inflections'
7
7
  require 'bigcommerce_api/modules/countable'
8
8
  require 'bigcommerce_api/base'
9
9
  require 'bigcommerce_api/resource'
10
+ require 'bigcommerce_api/error'
10
11
 
11
12
  # Resources
12
- require 'bigcommerce_api/category'
13
+ require 'bigcommerce_api/address'
13
14
  require 'bigcommerce_api/brand'
15
+ require 'bigcommerce_api/category'
16
+ require 'bigcommerce_api/customer'
17
+ require 'bigcommerce_api/hook'
14
18
  require 'bigcommerce_api/image'
15
19
  require 'bigcommerce_api/option'
16
20
  require 'bigcommerce_api/option_set'
@@ -24,6 +28,6 @@ require 'bigcommerce_api/product_option'
24
28
  require 'bigcommerce_api/result'
25
29
  require 'bigcommerce_api/rule'
26
30
  require 'bigcommerce_api/shipment'
27
- require 'bigcommerce_api/shippingaddress'
31
+ require 'bigcommerce_api/shipping_address'
28
32
  require 'bigcommerce_api/sku'
29
33
  require 'bigcommerce_api/store'
@@ -0,0 +1,45 @@
1
+ module BigcommerceAPI
2
+ class Address < Resource
3
+ attr_accessor :id,
4
+ :customer_id,
5
+ :first_name,
6
+ :last_name,
7
+ :company,
8
+ :street_1,
9
+ :street_2,
10
+ :city,
11
+ :state,
12
+ :zip,
13
+ :country,
14
+ :country_iso2,
15
+ :phone,
16
+ :address_type
17
+
18
+ belongs_to :customer
19
+
20
+ def resource_url
21
+ "customers/#{self.customer_id}/addresses"
22
+ end
23
+
24
+ def parent
25
+ 'customer'
26
+ end
27
+
28
+ # we override this on resources that need paired IDs for find
29
+ def find_for_reload
30
+ self.class.find(self.customer_id, self.id)
31
+ end
32
+
33
+ class << self
34
+ def all(customer_id, params={})
35
+ resources = BigcommerceAPI::Base.get("/customers/#{customer_id}/addresses", query: date_adjust(params))
36
+ (resources.success? and !resources.nil?) ? resources.collect{|r| self.new(r)} : []
37
+ end
38
+
39
+ def find(customer_id, id)
40
+ r = BigcommerceAPI::Base.get("/customers/#{customer_id}/addresses/#{id}")
41
+ (r.success? and !r.nil?) ? self.new(r) : nil
42
+ end
43
+ end
44
+ end
45
+ end
@@ -4,27 +4,37 @@ module BigcommerceAPI
4
4
  extend BigcommerceAPI
5
5
 
6
6
  include HTTParty
7
- format :json
8
- headers 'Accept' => "application/json"
9
- headers 'Content-Type' => "application/json"
7
+
8
+ def self.default_options
9
+ Thread.current["BigcommerceAPI"] ||= {
10
+ parser: HTTParty::Parser,
11
+ format: :json,
12
+ headers: { "Accept" => "application/json", "Content-Type" => "application/json" }
13
+ }
14
+ end
10
15
 
11
16
  def initialize(params={})
12
17
  # for the time being, accept old school API params
18
+ session_options = self.class.default_options
13
19
  if params[:username] and params[:api_key]
14
- self.class.basic_auth params[:username], params[:api_key]
15
- # default to Oauth
20
+ session_options[:username] = params[:username]
21
+ session_options[:password] = params[:api_key]
22
+ # default to Oauth
16
23
  else
17
- self.class.headers 'X-Auth-Client' => params[:client_id]
18
- self.class.headers 'X-Auth-Token' => params[:access_token]
24
+ session_options[:headers]['X-Auth-Client'] = params[:client_id]
25
+ session_options[:headers]['X-Auth-Token'] = params[:access_token]
19
26
  end
20
27
 
21
28
  # if we're using Oauth, we're probably grabbing :store_hash
22
29
  # 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
30
+ session_options[:base_uri] = if params[:store_url]
31
+ "#{params[:store_url]}/api/v2"
32
+ else
33
+ "https://api.bigcommerce.com/stores/#{params[:store_hash]}/v2"
34
+ end
35
+ session_options[:base_uri] = HTTParty.normalize_base_uri(session_options[:base_uri])
36
+
37
+ Thread.current["BigcommerceAPI"] = session_options
28
38
  end
29
39
 
30
40
  def time
@@ -74,7 +84,7 @@ module BigcommerceAPI
74
84
 
75
85
  class << self
76
86
  def clean!(hash)
77
- hash.each do |k, v|
87
+ hash.each do |k, v|
78
88
  if v.is_a? Hash
79
89
  clean!(v)
80
90
  else
@@ -88,7 +98,7 @@ module BigcommerceAPI
88
98
  def to_rfc2822(datetime)
89
99
  datetime.strftime("%a, %d %b %Y %H:%M:%S %z")
90
100
  end
91
-
101
+
92
102
  def date_adjust(params)
93
103
  [: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|
94
104
  [date, date.to_s].each do |d|
@@ -104,7 +114,7 @@ module BigcommerceAPI
104
114
  return params
105
115
  end
106
116
  end
107
-
117
+
108
118
  end
109
119
 
110
- end
120
+ end
@@ -1,10 +1,12 @@
1
1
  module BigcommerceAPI
2
-
3
2
  class Brand < Resource
4
- attr_accessor :id, :name, :page_title, :meta_keywords, :meta_description,
5
- :image_file, :search_keywords
6
-
3
+ attr_accessor :id,
4
+ :image_file,
5
+ :meta_description,
6
+ :meta_keywords,
7
+ :name,
8
+ :page_title,
9
+ :search_keywords
7
10
  end
8
-
9
11
  end
10
12
 
@@ -1,12 +1,19 @@
1
1
  module BigcommerceAPI
2
-
3
2
  class Category < Resource
4
- attr_accessor :id, :parent_id, :name, :description, :sort_order,
5
- :page_title, :meta_keywords, :meta_description,
6
- :layout_file, :parent_category_list, :image_file,
7
- :is_visible, :search_keywords, :url
8
-
3
+ attr_accessor :id,
4
+ :description,
5
+ :image_file,
6
+ :is_visible,
7
+ :layout_file,
8
+ :meta_description,
9
+ :meta_keywords,
10
+ :name,
11
+ :page_title,
12
+ :parent_category_list,
13
+ :parent_id,
14
+ :search_keywords,
15
+ :sort_order,
16
+ :url
9
17
  end
10
-
11
18
  end
12
19
 
@@ -0,0 +1,6 @@
1
+ module BigcommerceAPI
2
+ class Coupon < Resource
3
+ attr_accessor :id
4
+
5
+ end
6
+ end
@@ -0,0 +1,26 @@
1
+ module BigcommerceAPI
2
+ class Customer < Resource
3
+ extend BigcommerceAPI::Countable
4
+ attr_accessor :id,
5
+ :company,
6
+ :first_name,
7
+ :last_name,
8
+ :email,
9
+ :phone,
10
+ :date_created,
11
+ :date_modified,
12
+ :store_credit,
13
+ :registration_ip_address,
14
+ :customer_group_id,
15
+ :notes
16
+
17
+ attr_accessor :addresses_hash
18
+
19
+ belongs_to :order
20
+ has_many :addresses
21
+
22
+ def self.find(id)
23
+ super unless id.to_i == 0
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,9 @@
1
+ module BigcommerceAPI
2
+ class Error < StandardError
3
+ attr_reader :code
4
+ def initialize(code, message)
5
+ @code = code
6
+ super(message)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module BigcommerceAPI
2
+ class Hook < Resource
3
+ attr_accessor :id,
4
+ :store_hash,
5
+ :client_id,
6
+ :scope,
7
+ :headers,
8
+ :destination,
9
+ :is_active
10
+ end
11
+ end
@@ -1,10 +1,41 @@
1
1
  module BigcommerceAPI
2
-
3
2
  class Image < Resource
4
- attr_accessor :id, :image_file, :product_id, :sort_order, :is_thumbnail, :description, :date_created, :zoom_url, :thumbnail_url, :standard_url, :tiny_url
3
+ attr_accessor :id,
4
+ :date_created,
5
+ :description,
6
+ :image_file,
7
+ :is_thumbnail,
8
+ :product_id,
9
+ :sort_order,
10
+ :standard_url,
11
+ :thumbnail_url,
12
+ :tiny_url,
13
+ :zoom_url
5
14
 
6
15
  belongs_to :product
7
-
8
- end
9
16
 
10
- end
17
+ def resource_url
18
+ "products/#{self.product_id}/images"
19
+ end
20
+
21
+ def parent
22
+ 'product'
23
+ end
24
+
25
+ def find_for_reload
26
+ self.class.find(self.product_id, self.id)
27
+ end
28
+
29
+ class << self
30
+ def all(product_id, params={})
31
+ resources = BigcommerceAPI::Base.get("/products/#{product_id}/images", query: date_adjust(params))
32
+ (resources.success? and !resources.nil?) ? resources.collect{|r| self.new(r)} : []
33
+ end
34
+
35
+ def find(product_id, id)
36
+ r = BigcommerceAPI::Base.get("/products/#{product_id}/images/#{id}")
37
+ (r.success? and !r.nil?) ? self.new(r) : nil
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,10 +1,11 @@
1
1
  module BigcommerceAPI
2
-
3
2
  class Option < Resource
4
- attr_accessor :id, :name, :display_name, :option_type, :values_hash
5
-
6
- has_many :values => :option_values
7
-
8
- end
3
+ attr_accessor :id,
4
+ :display_name,
5
+ :name,
6
+ :type,
7
+ :values_hash
9
8
 
10
- end
9
+ has_many values: :option_values
10
+ end
11
+ end
@@ -1,10 +1,9 @@
1
1
  module BigcommerceAPI
2
-
3
2
  class OptionSet < Resource
4
- attr_accessor :id, :name, :options_hash
3
+ attr_accessor :id,
4
+ :options_hash,
5
+ :name
5
6
 
6
- has_many :options => :option_set_options
7
-
7
+ has_many options: :option_set_options
8
8
  end
9
-
10
- end
9
+ end
@@ -1,11 +1,38 @@
1
1
  module BigcommerceAPI
2
-
3
2
  class OptionSetOption < Resource
4
- attr_accessor :id, :option_id, :display_name, :option_set_id, :sort_order, :is_required, :option_resource
3
+ attr_accessor :id,
4
+ :display_name,
5
+ :is_required,
6
+ :option_id,
7
+ :option_resource,
8
+ :option_set_id,
9
+ :sort_order
5
10
 
6
11
  has_one :option
7
12
  belongs_to :option_set
8
-
9
- end
10
13
 
11
- end
14
+ def resource_url
15
+ "option_sets/#{self.option_set_id}/options"
16
+ end
17
+
18
+ def parent
19
+ 'option_set'
20
+ end
21
+
22
+ def find_for_reload
23
+ self.class.find(self.option_set_id, self.id)
24
+ end
25
+
26
+ class << self
27
+ def all(option_set_id, params={})
28
+ resources = BigcommerceAPI::Base.get("/option_sets/#{option_set_id}/options", query: date_adjust(params))
29
+ (resources.success? and !resources.nil?) ? resources.collect{|r| self.new(r)} : []
30
+ end
31
+
32
+ def find(option_set_id, id)
33
+ r = BigcommerceAPI::Base.get("/option_sets/#{option_set_id}/options/#{id}")
34
+ (r.success? and !r.nil?) ? self.new(r) : nil
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,10 +1,35 @@
1
1
  module BigcommerceAPI
2
-
3
2
  class OptionValue < Resource
4
- attr_accessor :id, :option_id, :sort_order, :value, :label
5
-
3
+ attr_accessor :id,
4
+ :label,
5
+ :option_id,
6
+ :sort_order,
7
+ :value
8
+
6
9
  belongs_to :option
7
-
8
- end
9
10
 
10
- end
11
+ def resource_url
12
+ "options/#{self.option_id}/values"
13
+ end
14
+
15
+ def parent
16
+ 'option'
17
+ end
18
+
19
+ def find_for_reload
20
+ self.class.find(self.option_id, self.id)
21
+ end
22
+
23
+ class << self
24
+ def all(option_id, params={})
25
+ resources = BigcommerceAPI::Base.get("/options/#{option_id}/values", query: date_adjust(params))
26
+ (resources.success? and !resources.nil?) ? resources.collect{|r| self.new(r)} : []
27
+ end
28
+
29
+ def find(option_id, id)
30
+ r = BigcommerceAPI::Base.get("/options/#{option_id}/values/#{id}")
31
+ (r.success? and !r.nil?) ? self.new(r) : nil
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,19 +1,81 @@
1
1
  module BigcommerceAPI
2
-
3
2
  class Order < Resource
4
3
  extend BigcommerceAPI::Countable
5
-
6
- 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
7
- # :coupons, :shipping_addresses,
8
4
 
9
- has_many :coupons, {:products => :order_products}, {:shipping_addresses => :shippingaddresses}
10
- belongs_to :customer, :currency, :default_currency, :shipping_cost_tax_class, :wrapping_cost_tax_class, :payment_provider, :handling_cost_tax_class
11
-
12
- def shipments
13
- s = BigcommerceAPI::Base.get '/orders/' + self.id.to_s + '/shipments'
14
- (s.success? and !s.nil?) ? s.collect{|o| BigcommerceAPI::Shipment.new(o)} : []
15
- end
5
+ attr_accessor :id,
6
+ :base_handling_cost,
7
+ :base_shipping_cost,
8
+ :base_wrapping_cost,
9
+ :billing_address,
10
+ :coupon_discount,
11
+ :coupons_hash,
12
+ :currency_code,
13
+ :currency_exchange_rate,
14
+ :currency_id,
15
+ :customer_id,
16
+ :customer_message,
17
+ :date_created,
18
+ :date_modified,
19
+ :date_shipped,
20
+ :default_currency_code,
21
+ :default_currency_id,
22
+ :discount_amount,
23
+ :geoip_country,
24
+ :geoip_country_iso2,
25
+ :gift_certificate_amount,
26
+ :handling_cost_ex_tax,
27
+ :handling_cost_inc_tax,
28
+ :handling_cost_tax,
29
+ :handling_cost_tax_class_id,
30
+ :ip_address,
31
+ :is_deleted,
32
+ :items_shipped,
33
+ :items_total,
34
+ :order_is_digital,
35
+ :payment_method,
36
+ :payment_provider_id,
37
+ :payment_status,
38
+ :products_hash,
39
+ :refunded_amount,
40
+ :shipping_address_count,
41
+ :shipping_addresses_hash,
42
+ :shipping_cost_ex_tax,
43
+ :shipping_cost_inc_tax,
44
+ :shipping_cost_tax,
45
+ :shipping_cost_tax_class_id,
46
+ :staff_notes,
47
+ :status,
48
+ :status_id,
49
+ :store_credit_amount,
50
+ :subtotal_ex_tax,
51
+ :subtotal_inc_tax,
52
+ :subtotal_tax,
53
+ :total_ex_tax,
54
+ :total_inc_tax,
55
+ :total_tax,
56
+ :wrapping_cost_ex_tax,
57
+ :wrapping_cost_inc_tax,
58
+ :wrapping_cost_tax,
59
+ :wrapping_cost_tax_class_id
16
60
 
17
- end
61
+ has_many :coupons,
62
+ { products: :order_products },
63
+ :shipping_addresses,
64
+ :shipments
65
+ alias_method :order_line_items, :products
66
+ alias_method :shippingaddresses, :shipping_addresses
18
67
 
19
- end
68
+ belongs_to :customer,
69
+ :currency,
70
+ :default_currency,
71
+ :shipping_cost_tax_class,
72
+ :wrapping_cost_tax_class,
73
+ :payment_provider,
74
+ :handling_cost_tax_class
75
+
76
+ alias_method :old_customer, :customer
77
+ def customer
78
+ old_customer unless customer_id == 0
79
+ end
80
+ end
81
+ end