bigcommerce 1.0.1 → 2.0.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 +48 -27
- data/bigcommerce.gemspec +9 -10
- data/lib/bigcommerce/config.rb +16 -2
- data/lib/bigcommerce/connection.rb +6 -3
- data/lib/bigcommerce/exception.rb +13 -11
- data/lib/bigcommerce/middleware/auth.rb +14 -6
- data/lib/bigcommerce/middleware/http_exception.rb +9 -1
- data/lib/bigcommerce/path_builder.rb +44 -0
- data/lib/bigcommerce/request.rb +10 -30
- 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 +7 -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 +20 -11
- metadata +34 -47
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: b85e649ea8b069cb792e147e901165cd5f81c8975ac434bf0182d369d07f0eb7
|
|
4
|
+
data.tar.gz: 89e5a3dff01013f56c51bf8aa5eaa3ef21c0af3e8304ccd6b2d72e4315d5117f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c715fd627a137ff3a2a3e18d230bab0eeb0e4622574c123f08391fa483b3f342c34c68d8e05377d4db824997d76aaebaf6cb82145ae209c7658422db4a0e19a9
|
|
7
|
+
data.tar.gz: 61ed2eaa4b6d5bb724ded917e40a881187523d0cb9df63c87833d2eaa109bc0c165e7bc0510dd5388f5016ea6313454d7947698827a0a9d55b6395780fab60f4
|
data/README.md
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
# BigCommerce API Ruby
|
|
2
2
|
|
|
3
3
|
[](https://rubygems.org/gems/bigcommerce)
|
|
4
|
-
[.
|
|
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)
|
|
8
7
|
|
|
8
|
+
This is the official BigCommerce API client to support our Stores API. You can find more information about becoming a
|
|
9
|
+
BigCommerce developer on the [docs site](https://docs.bigcommerce.com).
|
|
9
10
|
|
|
10
11
|
## Installation
|
|
12
|
+
|
|
11
13
|
BigCommerce is available on [RubyGems](https://rubygems.org/gems/bigcommerce).
|
|
12
14
|
|
|
13
15
|
```sh
|
|
@@ -17,38 +19,41 @@ gem install bigcommerce
|
|
|
17
19
|
You can also add it to your Gemfile.
|
|
18
20
|
|
|
19
21
|
```rb
|
|
20
|
-
gem 'bigcommerce', '~>
|
|
22
|
+
gem 'bigcommerce', '~> 2.0'
|
|
21
23
|
```
|
|
22
24
|
|
|
23
25
|
## Requirements
|
|
24
|
-
|
|
26
|
+
|
|
27
|
+
- Ruby 3.2 or newer
|
|
25
28
|
|
|
26
29
|
## Getting Started
|
|
30
|
+
|
|
27
31
|
To make requests to our API, you must register as a developer and have your credentials ready.
|
|
28
32
|
|
|
29
|
-
Also very important: For the OAuth authentication mechanism, the resources to which you have acccess depend on the
|
|
33
|
+
Also very important: For the OAuth authentication mechanism, the resources to which you have acccess depend on the
|
|
34
|
+
scopes that the merchant has granted to your application. For more information about Store API scopes,
|
|
35
|
+
see: [OAuth Scopes](https://docs.bigcommerce.com/developer/docs/overview/api-fundamentals/api-accounts#oauth-scopes).
|
|
30
36
|
|
|
31
37
|
## Authentication
|
|
38
|
+
|
|
32
39
|
We currently have two different authentication schemes that you can select, depending on your use case.
|
|
33
40
|
|
|
34
41
|
### 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 BigCommerce stores.
|
|
36
|
-
|
|
37
|
-
__[More Information](https://developer.bigcommerce.com/api/using-oauth-intro)__
|
|
38
42
|
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
OAuth apps can be submitted to [BigCommerce App Store](https://www.bigcommerce.com/apps), allowing other merchants to install these apps in their
|
|
44
|
+
BigCommerce stores.
|
|
41
45
|
|
|
42
|
-
|
|
46
|
+
**[More Information](https://docs.bigcommerce.com/developer/docs/overview/api-fundamentals/api-accounts#authentication)**
|
|
43
47
|
|
|
44
48
|
## Configuration
|
|
49
|
+
|
|
45
50
|
To authenticate your API client, you will need to configure the client like the following examples.
|
|
46
51
|
|
|
47
52
|
### OAuth App
|
|
48
53
|
|
|
49
|
-
-
|
|
50
|
-
-
|
|
51
|
-
-
|
|
54
|
+
- `client_id`: Obtained from the on the BigCommerce [Developer Portal's](https://build.bigcommerce.com) Apps section.
|
|
55
|
+
- `access_token`: Obtained after a token exchange in the auth callback.
|
|
56
|
+
- `store_hash`: Also obtained after the token exchange.
|
|
52
57
|
|
|
53
58
|
```rb
|
|
54
59
|
Bigcommerce.configure do |config|
|
|
@@ -60,7 +65,8 @@ end
|
|
|
60
65
|
|
|
61
66
|
### Basic Authentication (Legacy)
|
|
62
67
|
|
|
63
|
-
To get all the basic auth credentials, simply visit your store admin page, and navigate to the
|
|
68
|
+
To get all the basic auth credentials, simply visit your store admin page, and navigate to the
|
|
69
|
+
`Advanced Settings` > `Legacy API Settings`. Once there, you can create a new legacy API account on which to authenticate.
|
|
64
70
|
|
|
65
71
|
```rb
|
|
66
72
|
Bigcommerce.configure do |config|
|
|
@@ -71,9 +77,10 @@ Bigcommerce.configure do |config|
|
|
|
71
77
|
end
|
|
72
78
|
```
|
|
73
79
|
|
|
74
|
-
|
|
80
|
+
**SSL Configuration**
|
|
75
81
|
|
|
76
|
-
If you are using your own, self-signed, certificate, you can pass SSL options to Faraday. This is not required, but
|
|
82
|
+
If you are using your own, self-signed, certificate, you can pass SSL options to Faraday. This is not required, but
|
|
83
|
+
might be useful in special edge cases.
|
|
77
84
|
|
|
78
85
|
```rb
|
|
79
86
|
Bigcommerce.configure do |config|
|
|
@@ -93,11 +100,13 @@ For more information about configuring SSL with Faraday, please see the followin
|
|
|
93
100
|
- [Faraday: Setting up SSL certificates](https://github.com/lostisland/faraday/wiki/Setting-up-SSL-certificates)
|
|
94
101
|
|
|
95
102
|
### 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 client secret.
|
|
97
103
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
104
|
+
If you want to generate tokens for storefront login using the Customer Login API, you need to configure your app's
|
|
105
|
+
client secret.
|
|
106
|
+
|
|
107
|
+
- `store_hash`: The store hash of the store you are operating against.
|
|
108
|
+
- `client_id`: Obtained from the on the BigCommerce [Developer Portal's](https://build.bigcommerce.com) Apps section.
|
|
109
|
+
- `client_secret`: Obtained from the on the BigCommerce [Developer Portal's](https://build.bigcommerce.com) Apps section.
|
|
101
110
|
|
|
102
111
|
```rb
|
|
103
112
|
Bigcommerce.configure do |config|
|
|
@@ -108,7 +117,9 @@ end
|
|
|
108
117
|
```
|
|
109
118
|
|
|
110
119
|
## Usage
|
|
111
|
-
|
|
120
|
+
|
|
121
|
+
For full examples of using the API client, please see the [examples folder](examples) and refer to
|
|
122
|
+
BigCommerce's [developer documentation](https://docs.bigcommerce.com/).
|
|
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
|
|
|
@@ -173,4 +189,9 @@ Bigcommerce::System.raw_request(:get, 'time', connection: connection_legacy)
|
|
|
173
189
|
```
|
|
174
190
|
|
|
175
191
|
## Contributing
|
|
192
|
+
|
|
176
193
|
See [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
194
|
+
|
|
195
|
+
## License
|
|
196
|
+
|
|
197
|
+
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', '>= 2.14', '< 3.0'
|
|
23
|
+
s.add_dependency 'faraday-gzip', '~> 3.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,13 +15,13 @@ 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 ==
|
|
16
|
-
conn.
|
|
18
|
+
if config.auth == LEGACY_AUTH_MODE
|
|
19
|
+
conn.request :authorization, :basic, config.username, config.api_key
|
|
17
20
|
else
|
|
18
21
|
conn.use Bigcommerce::Middleware::Auth, config
|
|
19
22
|
end
|
|
23
|
+
conn.request :gzip
|
|
20
24
|
conn.use Bigcommerce::Middleware::HttpException
|
|
21
|
-
conn.use FaradayMiddleware::Gzip
|
|
22
25
|
conn.adapter Faraday.default_adapter
|
|
23
26
|
end
|
|
24
27
|
end
|
|
@@ -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,16 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Bigcommerce
|
|
2
4
|
module Middleware
|
|
3
5
|
class Auth < Faraday::Middleware
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
@options = options
|
|
7
|
-
end
|
|
6
|
+
X_AUTH_CLIENT_HEADER = 'X-Auth-Client'
|
|
7
|
+
X_AUTH_TOKEN_HEADER = 'X-Auth-Token'
|
|
8
8
|
|
|
9
9
|
def call(env)
|
|
10
|
-
env[:request_headers][
|
|
11
|
-
env[:request_headers][
|
|
10
|
+
env[:request_headers][X_AUTH_CLIENT_HEADER] = option_value(:client_id)
|
|
11
|
+
env[:request_headers][X_AUTH_TOKEN_HEADER] = option_value(:access_token)
|
|
12
12
|
@app.call env
|
|
13
13
|
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def option_value(key)
|
|
18
|
+
return @options[key] if @options.key?(key)
|
|
19
|
+
|
|
20
|
+
@options[key.to_s]
|
|
21
|
+
end
|
|
14
22
|
end
|
|
15
23
|
end
|
|
16
24
|
end
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'bigcommerce/exception'
|
|
2
4
|
|
|
3
5
|
module Bigcommerce
|
|
4
6
|
module Middleware
|
|
5
|
-
class HttpException < Faraday::
|
|
7
|
+
class HttpException < Faraday::Middleware
|
|
6
8
|
include Bigcommerce::HttpErrors
|
|
7
9
|
|
|
10
|
+
def call(env)
|
|
11
|
+
@app.call(env).on_complete do |response_env|
|
|
12
|
+
on_complete(response_env)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
8
16
|
def on_complete(env)
|
|
9
17
|
throw_http_exception! env[:status].to_i, env
|
|
10
18
|
env
|
|
@@ -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
|
|
@@ -71,7 +46,7 @@ module Bigcommerce
|
|
|
71
46
|
private
|
|
72
47
|
|
|
73
48
|
def build_response_object(response)
|
|
74
|
-
json = parse
|
|
49
|
+
json = parse(response.body)
|
|
75
50
|
if json.is_a? Array
|
|
76
51
|
json.map { |obj| new obj }
|
|
77
52
|
else
|
|
@@ -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
|
|
|
@@ -26,6 +28,7 @@ module Bigcommerce
|
|
|
26
28
|
property :addresses
|
|
27
29
|
property :tax_exempt_category
|
|
28
30
|
property :accepts_marketing
|
|
31
|
+
property :form_fields
|
|
29
32
|
|
|
30
33
|
def self.count(params = {})
|
|
31
34
|
get 'customers/count', params
|
|
@@ -34,17 +37,18 @@ module Bigcommerce
|
|
|
34
37
|
# Generate a token that can be used to log the customer into the storefront.
|
|
35
38
|
# This requires your app to have the store_v2_customers_login scope and to
|
|
36
39
|
# be installed in the store.
|
|
37
|
-
def login_token(config: Bigcommerce.config)
|
|
40
|
+
def login_token(config: Bigcommerce.config, redirect_to: '/')
|
|
38
41
|
payload = {
|
|
39
42
|
'iss' => config.client_id,
|
|
40
43
|
'iat' => Time.now.to_i,
|
|
41
44
|
'jti' => SecureRandom.uuid,
|
|
42
45
|
'operation' => 'customer_login',
|
|
43
46
|
'store_hash' => config.store_hash,
|
|
44
|
-
'customer_id' => id
|
|
47
|
+
'customer_id' => id,
|
|
48
|
+
'redirect_to' => redirect_to
|
|
45
49
|
}
|
|
46
50
|
|
|
47
|
-
JWT.encode(payload, config.client_secret, 'HS256')
|
|
51
|
+
JWT.encode(payload, config.client_secret, 'HS256', { typ: 'JWT' })
|
|
48
52
|
end
|
|
49
53
|
end
|
|
50
54
|
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,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'hashie'
|
|
2
|
-
require '
|
|
3
|
-
require '
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
require 'faraday'
|
|
5
|
+
require 'faraday/gzip'
|
|
6
|
+
require_relative 'bigcommerce/version'
|
|
7
|
+
require_relative 'bigcommerce/config'
|
|
8
|
+
require_relative 'bigcommerce/connection'
|
|
9
|
+
require_relative 'bigcommerce/path_builder'
|
|
10
|
+
require_relative 'bigcommerce/middleware/auth'
|
|
11
|
+
require_relative 'bigcommerce/middleware/http_exception'
|
|
12
|
+
require_relative 'bigcommerce/resources/resource'
|
|
9
13
|
|
|
10
14
|
module Bigcommerce
|
|
11
15
|
resources = File.join(File.dirname(__FILE__), 'bigcommerce', 'resources', '**', '*.rb')
|
|
12
|
-
Dir.glob(resources
|
|
16
|
+
Dir.glob(resources).sort.each { |r| require r }
|
|
13
17
|
|
|
14
18
|
class << self
|
|
15
|
-
|
|
19
|
+
# @!attribute [r] api
|
|
20
|
+
# @return [::Faraday::Connection]
|
|
21
|
+
attr_reader :api
|
|
22
|
+
# @!attribute [r] config
|
|
23
|
+
# @return [::Bigcommerce::Config]
|
|
24
|
+
attr_reader :config
|
|
16
25
|
|
|
17
|
-
def configure
|
|
18
|
-
@config = Bigcommerce::Config.new.tap
|
|
26
|
+
def configure(&block)
|
|
27
|
+
@config = Bigcommerce::Config.new.tap(&block)
|
|
19
28
|
@api = Bigcommerce::Connection.build(@config)
|
|
20
29
|
end
|
|
21
30
|
end
|
metadata
CHANGED
|
@@ -1,101 +1,89 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bigcommerce
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.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
12
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
13
|
+
name: faraday
|
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
|
16
15
|
requirements:
|
|
17
16
|
- - ">="
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
20
|
-
|
|
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
|
-
- - ">="
|
|
18
|
+
version: '2.14'
|
|
19
|
+
- - "<"
|
|
32
20
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0'
|
|
34
|
-
type: :
|
|
21
|
+
version: '3.0'
|
|
22
|
+
type: :runtime
|
|
35
23
|
prerelease: false
|
|
36
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
25
|
requirements:
|
|
38
26
|
- - ">="
|
|
39
27
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
41
|
-
-
|
|
42
|
-
name: faraday
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - "~>"
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: '0.11'
|
|
48
|
-
type: :runtime
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - "~>"
|
|
28
|
+
version: '2.14'
|
|
29
|
+
- - "<"
|
|
53
30
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '0
|
|
31
|
+
version: '3.0'
|
|
55
32
|
- !ruby/object:Gem::Dependency
|
|
56
|
-
name:
|
|
33
|
+
name: faraday-gzip
|
|
57
34
|
requirement: !ruby/object:Gem::Requirement
|
|
58
35
|
requirements:
|
|
59
36
|
- - "~>"
|
|
60
37
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '0
|
|
38
|
+
version: '3.0'
|
|
62
39
|
type: :runtime
|
|
63
40
|
prerelease: false
|
|
64
41
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
42
|
requirements:
|
|
66
43
|
- - "~>"
|
|
67
44
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '0
|
|
45
|
+
version: '3.0'
|
|
69
46
|
- !ruby/object:Gem::Dependency
|
|
70
47
|
name: hashie
|
|
71
48
|
requirement: !ruby/object:Gem::Requirement
|
|
72
49
|
requirements:
|
|
73
|
-
- - "
|
|
50
|
+
- - ">="
|
|
74
51
|
- !ruby/object:Gem::Version
|
|
75
52
|
version: '3.4'
|
|
53
|
+
- - "~>"
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: '4'
|
|
76
56
|
type: :runtime
|
|
77
57
|
prerelease: false
|
|
78
58
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
59
|
requirements:
|
|
80
|
-
- - "
|
|
60
|
+
- - ">="
|
|
81
61
|
- !ruby/object:Gem::Version
|
|
82
62
|
version: '3.4'
|
|
63
|
+
- - "~>"
|
|
64
|
+
- !ruby/object:Gem::Version
|
|
65
|
+
version: '4'
|
|
83
66
|
- !ruby/object:Gem::Dependency
|
|
84
67
|
name: jwt
|
|
85
68
|
requirement: !ruby/object:Gem::Requirement
|
|
86
69
|
requirements:
|
|
87
|
-
- - "
|
|
70
|
+
- - ">="
|
|
88
71
|
- !ruby/object:Gem::Version
|
|
89
72
|
version: 1.5.4
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '2'
|
|
90
76
|
type: :runtime
|
|
91
77
|
prerelease: false
|
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
79
|
requirements:
|
|
94
|
-
- - "
|
|
80
|
+
- - ">="
|
|
95
81
|
- !ruby/object:Gem::Version
|
|
96
82
|
version: 1.5.4
|
|
83
|
+
- - "~>"
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: '2'
|
|
97
86
|
description: Ruby client library for the BigCommerce API
|
|
98
|
-
email:
|
|
99
87
|
executables: []
|
|
100
88
|
extensions: []
|
|
101
89
|
extra_rdoc_files: []
|
|
@@ -108,6 +96,7 @@ files:
|
|
|
108
96
|
- lib/bigcommerce/exception.rb
|
|
109
97
|
- lib/bigcommerce/middleware/auth.rb
|
|
110
98
|
- lib/bigcommerce/middleware/http_exception.rb
|
|
99
|
+
- lib/bigcommerce/path_builder.rb
|
|
111
100
|
- lib/bigcommerce/request.rb
|
|
112
101
|
- lib/bigcommerce/resource_actions.rb
|
|
113
102
|
- lib/bigcommerce/resources/content/blog_post.rb
|
|
@@ -158,8 +147,8 @@ files:
|
|
|
158
147
|
homepage: https://github.com/bigcommerce/bigcommerce-api-ruby
|
|
159
148
|
licenses:
|
|
160
149
|
- MIT
|
|
161
|
-
metadata:
|
|
162
|
-
|
|
150
|
+
metadata:
|
|
151
|
+
rubygems_mfa_required: 'true'
|
|
163
152
|
rdoc_options: []
|
|
164
153
|
require_paths:
|
|
165
154
|
- lib
|
|
@@ -167,16 +156,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
167
156
|
requirements:
|
|
168
157
|
- - ">="
|
|
169
158
|
- !ruby/object:Gem::Version
|
|
170
|
-
version: 2.
|
|
159
|
+
version: 2.7.5
|
|
171
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
161
|
requirements:
|
|
173
162
|
- - ">="
|
|
174
163
|
- !ruby/object:Gem::Version
|
|
175
164
|
version: '0'
|
|
176
165
|
requirements: []
|
|
177
|
-
|
|
178
|
-
rubygems_version: 2.6.14
|
|
179
|
-
signing_key:
|
|
166
|
+
rubygems_version: 3.6.9
|
|
180
167
|
specification_version: 4
|
|
181
168
|
summary: Ruby client library for the BigCommerce API
|
|
182
169
|
test_files: []
|