bigcommerce 1.0.1 → 1.1.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 +5 -5
- data/README.md +32 -13
- data/bigcommerce.gemspec +9 -10
- data/lib/bigcommerce/config.rb +16 -2
- data/lib/bigcommerce/connection.rb +4 -1
- data/lib/bigcommerce/exception.rb +13 -11
- data/lib/bigcommerce/middleware/auth.rb +8 -2
- data/lib/bigcommerce/middleware/http_exception.rb +2 -0
- data/lib/bigcommerce/path_builder.rb +44 -0
- data/lib/bigcommerce/request.rb +9 -29
- data/lib/bigcommerce/resource_actions.rb +8 -0
- data/lib/bigcommerce/resources/content/blog_post.rb +2 -0
- data/lib/bigcommerce/resources/content/blog_tag.rb +2 -0
- data/lib/bigcommerce/resources/content/redirect.rb +2 -0
- data/lib/bigcommerce/resources/customers/customer.rb +6 -3
- data/lib/bigcommerce/resources/customers/customer_address.rb +2 -0
- data/lib/bigcommerce/resources/customers/customer_group.rb +2 -0
- data/lib/bigcommerce/resources/geography/country.rb +2 -0
- data/lib/bigcommerce/resources/geography/state.rb +2 -0
- data/lib/bigcommerce/resources/marketing/banner.rb +2 -0
- data/lib/bigcommerce/resources/marketing/coupon.rb +2 -0
- data/lib/bigcommerce/resources/marketing/gift_certificates.rb +2 -0
- data/lib/bigcommerce/resources/orders/order.rb +10 -0
- data/lib/bigcommerce/resources/orders/order_coupon.rb +2 -0
- data/lib/bigcommerce/resources/orders/order_message.rb +2 -0
- data/lib/bigcommerce/resources/orders/order_product.rb +2 -0
- data/lib/bigcommerce/resources/orders/order_shipping_address.rb +2 -0
- data/lib/bigcommerce/resources/orders/order_status.rb +2 -0
- data/lib/bigcommerce/resources/orders/order_tax.rb +2 -0
- data/lib/bigcommerce/resources/orders/shipment.rb +2 -0
- data/lib/bigcommerce/resources/payments/payment_method.rb +2 -0
- data/lib/bigcommerce/resources/products/brand.rb +2 -0
- data/lib/bigcommerce/resources/products/bulk_pricing_rule.rb +2 -0
- data/lib/bigcommerce/resources/products/category.rb +2 -0
- data/lib/bigcommerce/resources/products/configurable_field.rb +2 -0
- data/lib/bigcommerce/resources/products/custom_field.rb +2 -0
- data/lib/bigcommerce/resources/products/google_product_search_mapping.rb +2 -0
- data/lib/bigcommerce/resources/products/option.rb +2 -0
- data/lib/bigcommerce/resources/products/option_set.rb +2 -0
- data/lib/bigcommerce/resources/products/option_set_option.rb +2 -0
- data/lib/bigcommerce/resources/products/option_value.rb +2 -0
- data/lib/bigcommerce/resources/products/product.rb +2 -0
- data/lib/bigcommerce/resources/products/product_image.rb +2 -0
- data/lib/bigcommerce/resources/products/product_option.rb +2 -0
- data/lib/bigcommerce/resources/products/product_review.rb +2 -0
- data/lib/bigcommerce/resources/products/product_rule.rb +2 -0
- data/lib/bigcommerce/resources/products/product_video.rb +2 -0
- data/lib/bigcommerce/resources/products/sku.rb +2 -0
- data/lib/bigcommerce/resources/resource.rb +2 -0
- data/lib/bigcommerce/resources/shipping/shipping_method.rb +2 -0
- data/lib/bigcommerce/resources/store/store_information.rb +2 -0
- data/lib/bigcommerce/resources/system/time.rb +2 -0
- data/lib/bigcommerce/resources/tax/tax_class.rb +2 -0
- data/lib/bigcommerce/resources/webhooks/webhook.rb +2 -0
- data/lib/bigcommerce/subresource_actions.rb +8 -0
- data/lib/bigcommerce/version.rb +3 -1
- data/lib/bigcommerce.rb +18 -10
- metadata +27 -46
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 91c155920d961947d4e7a2184fa2ffad660590d636bd70723d9eec87d4709f3b
|
|
4
|
+
data.tar.gz: dc8618135e2e88f8b2fa39954179d24ff56f435fa50185f4dd85baceb11684ef
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d3790b83072b92e5477bcdf2dffe1d13ca0da2beb501706dac775307701b68efc39c5168852309990f5255501d87c8178674820b0e6072ffe4208b439081ec2a
|
|
7
|
+
data.tar.gz: 411c3da75158d702890e5f764e44e708dabf2a713880f36af0283a40b05fff5b158eeea016a39b9253f1429dbb7322ec8c8737963696c3671fa960b65bcb394d
|
data/README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
# BigCommerce API Ruby
|
|
2
2
|
|
|
3
3
|
[](https://rubygems.org/gems/bigcommerce)
|
|
4
|
-
[](https://circleci.com/gh/bigcommerce/bigcommerce-api-ruby/tree/master)
|
|
5
|
+
[](https://codeclimate.com/github/bigcommerce/bigcommerce-api-ruby/test_coverage)
|
|
6
|
+
[](https://codeclimate.com/github/bigcommerce/bigcommerce-api-ruby/maintainability)
|
|
6
7
|
|
|
7
|
-
This is the official BigCommerce API client to support our Stores API. You can find more information about becoming a
|
|
8
|
+
This is the official BigCommerce API client to support our Stores API. You can find more information about becoming a
|
|
9
|
+
BigCommerce developer here: [developer.bigcommerce.com](http://developer.bigcommerce.com).
|
|
8
10
|
|
|
9
11
|
|
|
10
12
|
## Installation
|
|
@@ -21,18 +23,22 @@ gem 'bigcommerce', '~> 1.0'
|
|
|
21
23
|
```
|
|
22
24
|
|
|
23
25
|
## Requirements
|
|
24
|
-
|
|
26
|
+
|
|
27
|
+
- Ruby 2.7.5 or newer (Ruby 3.0+ is preferred)
|
|
25
28
|
|
|
26
29
|
## Getting Started
|
|
27
30
|
To make requests to our API, you must register as a developer and have your credentials ready.
|
|
28
31
|
|
|
29
|
-
Also very important: For the OAuth authentication mechanism, the resources to which you have acccess depend on the
|
|
32
|
+
Also very important: For the OAuth authentication mechanism, the resources to which you have acccess depend on the
|
|
33
|
+
scopes that the merchant has granted to your application. For more information about Store API scopes,
|
|
34
|
+
see: [OAuth Scopes](https://developer.bigcommerce.com/api/scopes).
|
|
30
35
|
|
|
31
36
|
## Authentication
|
|
32
37
|
We currently have two different authentication schemes that you can select, depending on your use case.
|
|
33
38
|
|
|
34
39
|
### OAuth
|
|
35
|
-
OAuth apps can be submitted to [BigCommerce App Store](https://www.bigcommerce.com/apps), allowing other merchants to install these apps in their
|
|
40
|
+
OAuth apps can be submitted to [BigCommerce App Store](https://www.bigcommerce.com/apps), allowing other merchants to install these apps in their
|
|
41
|
+
BigCommerce stores.
|
|
36
42
|
|
|
37
43
|
__[More Information](https://developer.bigcommerce.com/api/using-oauth-intro)__
|
|
38
44
|
|
|
@@ -60,7 +66,9 @@ end
|
|
|
60
66
|
|
|
61
67
|
### Basic Authentication (Legacy)
|
|
62
68
|
|
|
63
|
-
To get all the basic auth credentials, simply visit your store admin page, and navigate to the
|
|
69
|
+
To get all the basic auth credentials, simply visit your store admin page, and navigate to the
|
|
70
|
+
`Advanced Settings` > `Legacy API Settings`. Once there, you can create a new legacy API account on which to authenticate.
|
|
71
|
+
|
|
64
72
|
|
|
65
73
|
```rb
|
|
66
74
|
Bigcommerce.configure do |config|
|
|
@@ -73,7 +81,8 @@ end
|
|
|
73
81
|
|
|
74
82
|
__SSL Configuration__
|
|
75
83
|
|
|
76
|
-
If you are using your own, self-signed, certificate, you can pass SSL options to Faraday. This is not required, but
|
|
84
|
+
If you are using your own, self-signed, certificate, you can pass SSL options to Faraday. This is not required, but
|
|
85
|
+
might be useful in special edge cases.
|
|
77
86
|
|
|
78
87
|
```rb
|
|
79
88
|
Bigcommerce.configure do |config|
|
|
@@ -93,7 +102,8 @@ For more information about configuring SSL with Faraday, please see the followin
|
|
|
93
102
|
- [Faraday: Setting up SSL certificates](https://github.com/lostisland/faraday/wiki/Setting-up-SSL-certificates)
|
|
94
103
|
|
|
95
104
|
### Customer Login API
|
|
96
|
-
If you want to generate tokens for storefront login using the Customer Login API, you need to configure your app's
|
|
105
|
+
If you want to generate tokens for storefront login using the Customer Login API, you need to configure your app's
|
|
106
|
+
client secret.
|
|
97
107
|
|
|
98
108
|
- ```store_hash```: The store hash of the store you are operating against.
|
|
99
109
|
- ```client_id```: Obtained from the on the BigCommerce [Developer Portal's](http://developer.bigcommerce.com) "My Apps" section.
|
|
@@ -108,7 +118,8 @@ end
|
|
|
108
118
|
```
|
|
109
119
|
|
|
110
120
|
## Usage
|
|
111
|
-
For full examples of using the API client, please see the [examples folder](examples) and refer to
|
|
121
|
+
For full examples of using the API client, please see the [examples folder](examples) and refer to
|
|
122
|
+
BigCommerce's [developer documentation](https://developer.bigcommerce.com/api).
|
|
112
123
|
|
|
113
124
|
Example:
|
|
114
125
|
|
|
@@ -127,11 +138,16 @@ Bigcommerce::System.time
|
|
|
127
138
|
|
|
128
139
|
### Thread Safety
|
|
129
140
|
|
|
130
|
-
The `Bigcommerce.configure` method is NOT thread-safe. This mechanism is designed for applications or
|
|
141
|
+
The `Bigcommerce.configure` method is NOT thread-safe. This mechanism is designed for applications or
|
|
142
|
+
CLIs (command-line interfaces) where thread safety is not a concern. If you need to guarantee thread safety, we support
|
|
143
|
+
this alternative mechanism to make thread-safe API requests:
|
|
131
144
|
|
|
132
|
-
Rather then setting up a single `connection` for all API requests,
|
|
145
|
+
Rather then setting up a single `connection` for all API requests, construct a new connection for each thread.
|
|
146
|
+
If you can ensure that each of these connections is stored in a thread-safe manner, you can pass the `connection` as
|
|
147
|
+
you query the resource.
|
|
133
148
|
|
|
134
|
-
This connection is nothing more than a `Faraday::Connection` – so if you want to write your own, or to use your own
|
|
149
|
+
This connection is nothing more than a `Faraday::Connection` – so if you want to write your own, or to use your own
|
|
150
|
+
adapters, you can feel free. Please refer to this gem's [connection class](https://github.com/bigcommerce/bigcommerce-api-ruby/blob/master/lib/bigcommerce/connection.rb) for more details.
|
|
135
151
|
|
|
136
152
|
##### OAuth
|
|
137
153
|
|
|
@@ -174,3 +190,6 @@ Bigcommerce::System.raw_request(:get, 'time', connection: connection_legacy)
|
|
|
174
190
|
|
|
175
191
|
## Contributing
|
|
176
192
|
See [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
193
|
+
|
|
194
|
+
## License
|
|
195
|
+
See [LICENSE.md](LICENSE.md)
|
data/bigcommerce.gemspec
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH.unshift(File.expand_path('lib', __dir__))
|
|
3
4
|
require 'bigcommerce/version'
|
|
4
5
|
|
|
5
6
|
Gem::Specification.new do |s|
|
|
6
7
|
s.name = 'bigcommerce'
|
|
7
8
|
s.version = Bigcommerce::VERSION
|
|
8
9
|
s.platform = Gem::Platform::RUBY
|
|
9
|
-
s.required_ruby_version = '>= 2.
|
|
10
|
+
s.required_ruby_version = '>= 2.7.5'
|
|
10
11
|
s.license = 'MIT'
|
|
11
12
|
|
|
12
13
|
s.authors = ['BigCommerce Engineering']
|
|
13
14
|
s.homepage = 'https://github.com/bigcommerce/bigcommerce-api-ruby'
|
|
14
15
|
s.summary = 'Ruby client library for the BigCommerce API'
|
|
15
16
|
s.description = s.summary
|
|
17
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
|
16
18
|
|
|
17
19
|
s.require_paths = ['lib']
|
|
18
20
|
s.files = Dir['README.md', 'lib/**/*', 'bigcommerce.gemspec']
|
|
19
21
|
|
|
20
|
-
s.
|
|
21
|
-
s.
|
|
22
|
-
|
|
23
|
-
s.add_dependency '
|
|
24
|
-
s.add_dependency 'faraday_middleware', '~> 0.11'
|
|
25
|
-
s.add_dependency 'hashie', '~> 3.4'
|
|
26
|
-
s.add_dependency 'jwt', '~> 1.5.4'
|
|
22
|
+
s.add_dependency 'faraday', '~> 1.1.0'
|
|
23
|
+
s.add_dependency 'faraday_middleware', '~> 1.0'
|
|
24
|
+
s.add_dependency 'hashie', '>= 3.4', '~> 4'
|
|
25
|
+
s.add_dependency 'jwt', '>= 1.5.4', '~> 2'
|
|
27
26
|
end
|
data/lib/bigcommerce/config.rb
CHANGED
|
@@ -1,14 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Bigcommerce
|
|
2
4
|
class Config < Hashie::Mash
|
|
5
|
+
BC_API_ENDPOINT_ENV_KEY = 'BC_API_ENDPOINT'
|
|
3
6
|
DEFAULTS = {
|
|
4
7
|
base_url: 'https://api.bigcommerce.com'
|
|
5
8
|
}.freeze
|
|
6
9
|
|
|
10
|
+
##
|
|
11
|
+
# @return [String]
|
|
12
|
+
#
|
|
7
13
|
def api_url
|
|
8
14
|
return url if auth == 'legacy'
|
|
9
15
|
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
"#{base_url}/stores/#{store_hash}/v2"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
##
|
|
22
|
+
# @return [String]
|
|
23
|
+
#
|
|
24
|
+
def base_url
|
|
25
|
+
ENV[BC_API_ENDPOINT_ENV_KEY].to_s.empty? ? DEFAULTS[:base_url] : ENV.fetch(BC_API_ENDPOINT_ENV_KEY, nil)
|
|
12
26
|
end
|
|
13
27
|
end
|
|
14
28
|
end
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Bigcommerce
|
|
2
4
|
module Connection
|
|
5
|
+
LEGACY_AUTH_MODE = 'legacy'
|
|
3
6
|
HEADERS = {
|
|
4
7
|
'accept' => 'application/json',
|
|
5
8
|
'content-type' => 'application/json',
|
|
@@ -12,7 +15,7 @@ module Bigcommerce
|
|
|
12
15
|
Faraday.new(url: config.api_url, ssl: ssl_options) do |conn|
|
|
13
16
|
conn.request :json
|
|
14
17
|
conn.headers = HEADERS
|
|
15
|
-
if config.auth ==
|
|
18
|
+
if config.auth == LEGACY_AUTH_MODE
|
|
16
19
|
conn.use Faraday::Request::BasicAuthentication, config.username, config.api_key
|
|
17
20
|
else
|
|
18
21
|
conn.use Bigcommerce::Middleware::Auth, config
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Bigcommerce
|
|
2
4
|
class HttpError < StandardError
|
|
3
5
|
attr_accessor :response_headers
|
|
6
|
+
|
|
4
7
|
def initialize(headers)
|
|
5
8
|
@response_headers = headers
|
|
9
|
+
super()
|
|
6
10
|
end
|
|
7
11
|
end
|
|
8
12
|
|
|
@@ -39,19 +43,17 @@ module Bigcommerce
|
|
|
39
43
|
509 => Bigcommerce::BandwidthLimitExceeded
|
|
40
44
|
}.freeze
|
|
41
45
|
|
|
46
|
+
X_RETRY_AFTER_HEADER_KEY = 'x-retry-after'
|
|
47
|
+
|
|
42
48
|
def throw_http_exception!(code, env)
|
|
43
|
-
return unless ERRORS.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
{}
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
unless env[:response_headers] && env[:response_headers]['X-Retry-After'].nil?
|
|
53
|
-
response_headers[:retry_after] = env[:response_headers]['X-Retry-After'].to_i
|
|
49
|
+
return unless ERRORS.key?(code)
|
|
50
|
+
|
|
51
|
+
response_headers = Faraday::Utils::Headers.new(env.response_headers)
|
|
52
|
+
|
|
53
|
+
unless response_headers[X_RETRY_AFTER_HEADER_KEY].nil?
|
|
54
|
+
response_headers[:retry_after] = response_headers[X_RETRY_AFTER_HEADER_KEY].to_i
|
|
54
55
|
end
|
|
56
|
+
|
|
55
57
|
raise ERRORS[code].new(response_headers), env.body
|
|
56
58
|
end
|
|
57
59
|
end
|
|
@@ -1,14 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Bigcommerce
|
|
2
4
|
module Middleware
|
|
3
5
|
class Auth < Faraday::Middleware
|
|
6
|
+
X_AUTH_CLIENT_HEADER = 'X-Auth-Client'
|
|
7
|
+
X_AUTH_TOKEN_HEADER = 'X-Auth-Token'
|
|
8
|
+
|
|
4
9
|
def initialize(app, options = {})
|
|
5
10
|
@app = app
|
|
6
11
|
@options = options
|
|
12
|
+
super(app)
|
|
7
13
|
end
|
|
8
14
|
|
|
9
15
|
def call(env)
|
|
10
|
-
env[:request_headers][
|
|
11
|
-
env[:request_headers][
|
|
16
|
+
env[:request_headers][X_AUTH_CLIENT_HEADER] = @options[:client_id]
|
|
17
|
+
env[:request_headers][X_AUTH_TOKEN_HEADER] = @options[:access_token]
|
|
12
18
|
@app.call env
|
|
13
19
|
end
|
|
14
20
|
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bigcommerce
|
|
4
|
+
class PathBuilder
|
|
5
|
+
# @!attribute [r] uri
|
|
6
|
+
# @return [String] The URI of the path to build
|
|
7
|
+
attr_reader :uri
|
|
8
|
+
|
|
9
|
+
##
|
|
10
|
+
# @param [String] uri
|
|
11
|
+
#
|
|
12
|
+
def initialize(uri)
|
|
13
|
+
@uri = uri
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
##
|
|
17
|
+
# This takes the @uri and inserts the keys to form a path.
|
|
18
|
+
# To start we make sure that for nil/numeric values, we wrap those into an
|
|
19
|
+
# array. We then scan the string for %d and %s to find the number of times
|
|
20
|
+
# we possibly need to insert keys into the URI. Next, we check the size of
|
|
21
|
+
# the keys array, if the keys size is less than the number of possible keys
|
|
22
|
+
# in the URI, we will remove the trailing %d or %s, then remove the
|
|
23
|
+
# trailing /. We then pass the keys into the uri to form the path.
|
|
24
|
+
# ex. foo/%d/bar/%d => foo/1/bar/2
|
|
25
|
+
#
|
|
26
|
+
# @param [Array] keys
|
|
27
|
+
# @return [String]
|
|
28
|
+
#
|
|
29
|
+
def build(keys = [])
|
|
30
|
+
keys = [] if keys.nil?
|
|
31
|
+
keys = [keys] if keys.is_a? Numeric
|
|
32
|
+
ids = uri.scan('%d').count + uri.scan('%s').count
|
|
33
|
+
str = ids > keys.size ? uri.chomp('%d').chomp('%s').chomp('/') : uri
|
|
34
|
+
(str % keys).chomp('/')
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
##
|
|
38
|
+
# @return [String]
|
|
39
|
+
#
|
|
40
|
+
def to_s
|
|
41
|
+
@uri
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
data/lib/bigcommerce/request.rb
CHANGED
|
@@ -1,42 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'json'
|
|
2
4
|
|
|
3
5
|
module Bigcommerce
|
|
4
|
-
class PathBuilder
|
|
5
|
-
attr_reader :uri
|
|
6
|
-
|
|
7
|
-
def initialize(uri)
|
|
8
|
-
@uri = uri
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
# This takes the @uri and inserts the keys to form a path.
|
|
12
|
-
# To start we make sure that for nil/numeric values, we wrap those into an
|
|
13
|
-
# array. We then scan the string for %d and %s to find the number of times
|
|
14
|
-
# we possibly need to insert keys into the URI. Next, we check the size of
|
|
15
|
-
# the keys array, if the keys size is less than the number of possible keys
|
|
16
|
-
# in the URI, we will remove the trailing %d or %s, then remove the
|
|
17
|
-
# trailing /. We then pass the keys into the uri to form the path.
|
|
18
|
-
# ex. foo/%d/bar/%d => foo/1/bar/2
|
|
19
|
-
def build(keys = [])
|
|
20
|
-
keys = [] if keys.nil?
|
|
21
|
-
keys = [keys] if keys.is_a? Numeric
|
|
22
|
-
ids = uri.scan('%d').count + uri.scan('%s').count
|
|
23
|
-
str = ids > keys.size ? uri.chomp('%d').chomp('%s').chomp('/') : uri
|
|
24
|
-
(str % keys).chomp('/')
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def to_s
|
|
28
|
-
@uri
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
6
|
class Request < Module
|
|
33
7
|
def initialize(uri)
|
|
34
8
|
@uri = uri
|
|
9
|
+
super()
|
|
35
10
|
end
|
|
36
11
|
|
|
37
12
|
def included(base)
|
|
38
13
|
base.extend ClassMethods
|
|
39
|
-
path_builder = PathBuilder.new
|
|
14
|
+
path_builder = ::Bigcommerce::PathBuilder.new(@uri)
|
|
40
15
|
base.define_singleton_method :path do
|
|
41
16
|
path_builder
|
|
42
17
|
end
|
|
@@ -79,8 +54,13 @@ module Bigcommerce
|
|
|
79
54
|
end
|
|
80
55
|
end
|
|
81
56
|
|
|
57
|
+
##
|
|
58
|
+
# @return [Hash]
|
|
59
|
+
# @return [Array]
|
|
60
|
+
#
|
|
82
61
|
def parse(json)
|
|
83
62
|
return [] if json.empty?
|
|
63
|
+
|
|
84
64
|
JSON.parse(json, symbolize_names: true)
|
|
85
65
|
end
|
|
86
66
|
end
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Bigcommerce
|
|
2
4
|
class ResourceActions < Module
|
|
5
|
+
# @!attribute [r] options
|
|
6
|
+
# @return [Hash] Options passed to this module
|
|
3
7
|
attr_reader :options
|
|
4
8
|
|
|
5
9
|
def initialize(options = {})
|
|
@@ -9,6 +13,7 @@ module Bigcommerce
|
|
|
9
13
|
mod.options
|
|
10
14
|
end
|
|
11
15
|
end
|
|
16
|
+
super()
|
|
12
17
|
end
|
|
13
18
|
|
|
14
19
|
def included(base)
|
|
@@ -26,6 +31,7 @@ module Bigcommerce
|
|
|
26
31
|
|
|
27
32
|
def find(resource_id, params = {})
|
|
28
33
|
raise ArgumentError if resource_id.nil?
|
|
34
|
+
|
|
29
35
|
get path.build(resource_id), params
|
|
30
36
|
end
|
|
31
37
|
|
|
@@ -35,11 +41,13 @@ module Bigcommerce
|
|
|
35
41
|
|
|
36
42
|
def update(resource_id, params = {})
|
|
37
43
|
raise ArgumentError if resource_id.nil?
|
|
44
|
+
|
|
38
45
|
put path.build(resource_id), params
|
|
39
46
|
end
|
|
40
47
|
|
|
41
48
|
def destroy(resource_id, params = {})
|
|
42
49
|
raise ArgumentError if resource_id.nil?
|
|
50
|
+
|
|
43
51
|
delete path.build(resource_id), params
|
|
44
52
|
end
|
|
45
53
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'jwt'
|
|
2
4
|
require 'securerandom'
|
|
3
5
|
|
|
@@ -34,17 +36,18 @@ module Bigcommerce
|
|
|
34
36
|
# Generate a token that can be used to log the customer into the storefront.
|
|
35
37
|
# This requires your app to have the store_v2_customers_login scope and to
|
|
36
38
|
# be installed in the store.
|
|
37
|
-
def login_token(config: Bigcommerce.config)
|
|
39
|
+
def login_token(config: Bigcommerce.config, redirect_to: '/')
|
|
38
40
|
payload = {
|
|
39
41
|
'iss' => config.client_id,
|
|
40
42
|
'iat' => Time.now.to_i,
|
|
41
43
|
'jti' => SecureRandom.uuid,
|
|
42
44
|
'operation' => 'customer_login',
|
|
43
45
|
'store_hash' => config.store_hash,
|
|
44
|
-
'customer_id' => id
|
|
46
|
+
'customer_id' => id,
|
|
47
|
+
'redirect_to' => redirect_to
|
|
45
48
|
}
|
|
46
49
|
|
|
47
|
-
JWT.encode(payload, config.client_secret, 'HS256')
|
|
50
|
+
JWT.encode(payload, config.client_secret, 'HS256', { typ: 'JWT' })
|
|
48
51
|
end
|
|
49
52
|
end
|
|
50
53
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Order
|
|
2
4
|
# Purchases from a store.
|
|
3
5
|
# https://developer.bigcommerce.com/api/stores/v2/orders
|
|
@@ -67,6 +69,14 @@ module Bigcommerce
|
|
|
67
69
|
property :shipping_cost_tax_class_id
|
|
68
70
|
property :wrapping_cost_tax_class_id
|
|
69
71
|
property :count
|
|
72
|
+
property :cart_id
|
|
73
|
+
property :channel_id
|
|
74
|
+
property :custom_status
|
|
75
|
+
property :external_id
|
|
76
|
+
property :external_merchant_id
|
|
77
|
+
property :store_default_currency_code
|
|
78
|
+
property :store_default_to_transactional_exchange_rate
|
|
79
|
+
property :tax_provider_id
|
|
70
80
|
|
|
71
81
|
def self.count(params = {})
|
|
72
82
|
get 'orders/count', params
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Bigcommerce
|
|
2
4
|
class SubresourceActions < ResourceActions
|
|
3
5
|
def included(base)
|
|
@@ -11,31 +13,37 @@ module Bigcommerce
|
|
|
11
13
|
module ClassMethods
|
|
12
14
|
def all(parent_id, params = {})
|
|
13
15
|
raise ArgumentError if parent_id.nil?
|
|
16
|
+
|
|
14
17
|
get path.build(parent_id), params
|
|
15
18
|
end
|
|
16
19
|
|
|
17
20
|
def find(parent_id, resource_id, params = {})
|
|
18
21
|
raise ArgumentError if [parent_id, resource_id].any?(&:nil?)
|
|
22
|
+
|
|
19
23
|
get path.build([parent_id, resource_id]), params
|
|
20
24
|
end
|
|
21
25
|
|
|
22
26
|
def create(parent_id, params = {})
|
|
23
27
|
raise ArgumentError if parent_id.nil?
|
|
28
|
+
|
|
24
29
|
post path.build(parent_id), params
|
|
25
30
|
end
|
|
26
31
|
|
|
27
32
|
def update(parent_id, resource_id, params = {})
|
|
28
33
|
raise ArgumentError if [parent_id, resource_id].any?(&:nil?)
|
|
34
|
+
|
|
29
35
|
put path.build([parent_id, resource_id]), params
|
|
30
36
|
end
|
|
31
37
|
|
|
32
38
|
def destroy(parent_id, resource_id, params = {})
|
|
33
39
|
raise ArgumentError if [parent_id, resource_id].any?(&:nil?)
|
|
40
|
+
|
|
34
41
|
delete path.build([parent_id, resource_id]), params
|
|
35
42
|
end
|
|
36
43
|
|
|
37
44
|
def destroy_all(parent_id, params = {})
|
|
38
45
|
raise ArgumentError if parent_id.nil?
|
|
46
|
+
|
|
39
47
|
delete path.build(parent_id), params
|
|
40
48
|
end
|
|
41
49
|
end
|
data/lib/bigcommerce/version.rb
CHANGED
data/lib/bigcommerce.rb
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'hashie'
|
|
2
4
|
require 'faraday_middleware'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
require_relative 'bigcommerce/version'
|
|
6
|
+
require_relative 'bigcommerce/config'
|
|
7
|
+
require_relative 'bigcommerce/connection'
|
|
8
|
+
require_relative 'bigcommerce/path_builder'
|
|
9
|
+
require_relative 'bigcommerce/middleware/auth'
|
|
10
|
+
require_relative 'bigcommerce/middleware/http_exception'
|
|
11
|
+
require_relative 'bigcommerce/resources/resource'
|
|
9
12
|
|
|
10
13
|
module Bigcommerce
|
|
11
14
|
resources = File.join(File.dirname(__FILE__), 'bigcommerce', 'resources', '**', '*.rb')
|
|
12
|
-
Dir.glob(resources
|
|
15
|
+
Dir.glob(resources).sort.each { |r| require r }
|
|
13
16
|
|
|
14
17
|
class << self
|
|
15
|
-
|
|
18
|
+
# @!attribute [r] api
|
|
19
|
+
# @return [::Faraday::Connection]
|
|
20
|
+
attr_reader :api
|
|
21
|
+
# @!attribute [r] config
|
|
22
|
+
# @return [::Bigcommerce::Config]
|
|
23
|
+
attr_reader :config
|
|
16
24
|
|
|
17
|
-
def configure
|
|
18
|
-
@config = Bigcommerce::Config.new.tap
|
|
25
|
+
def configure(&block)
|
|
26
|
+
@config = Bigcommerce::Config.new.tap(&block)
|
|
19
27
|
@api = Bigcommerce::Connection.build(@config)
|
|
20
28
|
end
|
|
21
29
|
end
|
metadata
CHANGED
|
@@ -1,101 +1,83 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bigcommerce
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- BigCommerce Engineering
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
|
-
- !ruby/object:Gem::Dependency
|
|
14
|
-
name: bundler
|
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
|
16
|
-
requirements:
|
|
17
|
-
- - ">="
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: '0'
|
|
20
|
-
type: :development
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - ">="
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: '0'
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: rake
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - ">="
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0'
|
|
34
|
-
type: :development
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - ">="
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '0'
|
|
41
12
|
- !ruby/object:Gem::Dependency
|
|
42
13
|
name: faraday
|
|
43
14
|
requirement: !ruby/object:Gem::Requirement
|
|
44
15
|
requirements:
|
|
45
16
|
- - "~>"
|
|
46
17
|
- !ruby/object:Gem::Version
|
|
47
|
-
version:
|
|
18
|
+
version: 1.1.0
|
|
48
19
|
type: :runtime
|
|
49
20
|
prerelease: false
|
|
50
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
22
|
requirements:
|
|
52
23
|
- - "~>"
|
|
53
24
|
- !ruby/object:Gem::Version
|
|
54
|
-
version:
|
|
25
|
+
version: 1.1.0
|
|
55
26
|
- !ruby/object:Gem::Dependency
|
|
56
27
|
name: faraday_middleware
|
|
57
28
|
requirement: !ruby/object:Gem::Requirement
|
|
58
29
|
requirements:
|
|
59
30
|
- - "~>"
|
|
60
31
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '0
|
|
32
|
+
version: '1.0'
|
|
62
33
|
type: :runtime
|
|
63
34
|
prerelease: false
|
|
64
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
36
|
requirements:
|
|
66
37
|
- - "~>"
|
|
67
38
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '0
|
|
39
|
+
version: '1.0'
|
|
69
40
|
- !ruby/object:Gem::Dependency
|
|
70
41
|
name: hashie
|
|
71
42
|
requirement: !ruby/object:Gem::Requirement
|
|
72
43
|
requirements:
|
|
73
|
-
- - "
|
|
44
|
+
- - ">="
|
|
74
45
|
- !ruby/object:Gem::Version
|
|
75
46
|
version: '3.4'
|
|
47
|
+
- - "~>"
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '4'
|
|
76
50
|
type: :runtime
|
|
77
51
|
prerelease: false
|
|
78
52
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
53
|
requirements:
|
|
80
|
-
- - "
|
|
54
|
+
- - ">="
|
|
81
55
|
- !ruby/object:Gem::Version
|
|
82
56
|
version: '3.4'
|
|
57
|
+
- - "~>"
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: '4'
|
|
83
60
|
- !ruby/object:Gem::Dependency
|
|
84
61
|
name: jwt
|
|
85
62
|
requirement: !ruby/object:Gem::Requirement
|
|
86
63
|
requirements:
|
|
87
|
-
- - "
|
|
64
|
+
- - ">="
|
|
88
65
|
- !ruby/object:Gem::Version
|
|
89
66
|
version: 1.5.4
|
|
67
|
+
- - "~>"
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '2'
|
|
90
70
|
type: :runtime
|
|
91
71
|
prerelease: false
|
|
92
72
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
73
|
requirements:
|
|
94
|
-
- - "
|
|
74
|
+
- - ">="
|
|
95
75
|
- !ruby/object:Gem::Version
|
|
96
76
|
version: 1.5.4
|
|
77
|
+
- - "~>"
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: '2'
|
|
97
80
|
description: Ruby client library for the BigCommerce API
|
|
98
|
-
email:
|
|
99
81
|
executables: []
|
|
100
82
|
extensions: []
|
|
101
83
|
extra_rdoc_files: []
|
|
@@ -108,6 +90,7 @@ files:
|
|
|
108
90
|
- lib/bigcommerce/exception.rb
|
|
109
91
|
- lib/bigcommerce/middleware/auth.rb
|
|
110
92
|
- lib/bigcommerce/middleware/http_exception.rb
|
|
93
|
+
- lib/bigcommerce/path_builder.rb
|
|
111
94
|
- lib/bigcommerce/request.rb
|
|
112
95
|
- lib/bigcommerce/resource_actions.rb
|
|
113
96
|
- lib/bigcommerce/resources/content/blog_post.rb
|
|
@@ -158,8 +141,8 @@ files:
|
|
|
158
141
|
homepage: https://github.com/bigcommerce/bigcommerce-api-ruby
|
|
159
142
|
licenses:
|
|
160
143
|
- MIT
|
|
161
|
-
metadata:
|
|
162
|
-
|
|
144
|
+
metadata:
|
|
145
|
+
rubygems_mfa_required: 'true'
|
|
163
146
|
rdoc_options: []
|
|
164
147
|
require_paths:
|
|
165
148
|
- lib
|
|
@@ -167,16 +150,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
167
150
|
requirements:
|
|
168
151
|
- - ">="
|
|
169
152
|
- !ruby/object:Gem::Version
|
|
170
|
-
version: 2.
|
|
153
|
+
version: 2.7.5
|
|
171
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
155
|
requirements:
|
|
173
156
|
- - ">="
|
|
174
157
|
- !ruby/object:Gem::Version
|
|
175
158
|
version: '0'
|
|
176
159
|
requirements: []
|
|
177
|
-
|
|
178
|
-
rubygems_version: 2.6.14
|
|
179
|
-
signing_key:
|
|
160
|
+
rubygems_version: 3.6.9
|
|
180
161
|
specification_version: 4
|
|
181
162
|
summary: Ruby client library for the BigCommerce API
|
|
182
163
|
test_files: []
|