bigcommerce 1.0.0.beta → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +98 -36
- data/bigcommerce.gemspec +11 -13
- data/lib/bigcommerce.rb +4 -33
- data/lib/bigcommerce/config.rb +14 -0
- data/lib/bigcommerce/connection.rb +24 -0
- data/lib/bigcommerce/exception.rb +25 -18
- data/lib/bigcommerce/request.rb +8 -9
- data/lib/bigcommerce/resource_actions.rb +11 -11
- data/lib/bigcommerce/resources/content/blog_post.rb +3 -5
- data/lib/bigcommerce/resources/content/blog_tag.rb +2 -3
- data/lib/bigcommerce/resources/content/redirect.rb +2 -2
- data/lib/bigcommerce/resources/customers/customer.rb +2 -2
- data/lib/bigcommerce/resources/customers/customer_address.rb +5 -5
- data/lib/bigcommerce/resources/customers/customer_group.rb +2 -2
- data/lib/bigcommerce/resources/geography/country.rb +4 -3
- data/lib/bigcommerce/resources/geography/state.rb +6 -5
- data/lib/bigcommerce/resources/marketing/banner.rb +21 -0
- data/lib/bigcommerce/resources/marketing/coupon.rb +2 -2
- data/lib/bigcommerce/resources/marketing/gift_certificates.rb +25 -0
- data/lib/bigcommerce/resources/orders/order.rb +46 -44
- data/lib/bigcommerce/resources/orders/order_coupon.rb +5 -5
- data/lib/bigcommerce/resources/orders/order_message.rb +8 -7
- data/lib/bigcommerce/resources/orders/order_product.rb +37 -36
- data/lib/bigcommerce/resources/orders/order_shipping_address.rb +24 -23
- data/lib/bigcommerce/resources/orders/order_status.rb +2 -1
- data/lib/bigcommerce/resources/orders/order_tax.rb +8 -7
- data/lib/bigcommerce/resources/orders/shipment.rb +11 -10
- data/lib/bigcommerce/resources/products/brand.rb +2 -2
- data/lib/bigcommerce/resources/products/bulk_pricing_rule.rb +6 -5
- data/lib/bigcommerce/resources/products/category.rb +2 -2
- data/lib/bigcommerce/resources/products/configurable_field.rb +6 -5
- data/lib/bigcommerce/resources/products/custom_field.rb +6 -5
- data/lib/bigcommerce/resources/products/google_product_search_mapping.rb +9 -8
- data/lib/bigcommerce/resources/products/option.rb +2 -2
- data/lib/bigcommerce/resources/products/option_set.rb +2 -2
- data/lib/bigcommerce/resources/products/option_set_option.rb +2 -1
- data/lib/bigcommerce/resources/products/option_value.rb +1 -0
- data/lib/bigcommerce/resources/products/product.rb +61 -61
- data/lib/bigcommerce/resources/products/product_image.rb +4 -4
- data/lib/bigcommerce/resources/products/product_option.rb +2 -1
- data/lib/bigcommerce/resources/products/product_review.rb +1 -5
- data/lib/bigcommerce/resources/products/product_rule.rb +4 -4
- data/lib/bigcommerce/resources/products/product_video.rb +4 -4
- data/lib/bigcommerce/resources/products/sku.rb +15 -9
- data/lib/bigcommerce/resources/shipping/shipping_method.rb +2 -1
- data/lib/bigcommerce/resources/store/store_information.rb +18 -14
- data/lib/bigcommerce/resources/system/time.rb +2 -2
- data/lib/bigcommerce/resources/tax/tax_class.rb +2 -1
- data/lib/bigcommerce/resources/webhooks/webhook.rb +2 -1
- data/lib/bigcommerce/subresource_actions.rb +14 -14
- data/lib/bigcommerce/version.rb +1 -1
- metadata +32 -165
- data/.gitignore +0 -17
- data/.rspec +0 -2
- data/.rubocop.yml +0 -620
- data/.travis.yml +0 -15
- data/CHANGELOG.md +0 -11
- data/CONTRIBUTING.md +0 -119
- data/DEPENDENCIES.md +0 -7
- data/Gemfile +0 -15
- data/Guardfile +0 -22
- data/LICENSE +0 -20
- data/RELEASING.md +0 -64
- data/Rakefile +0 -13
- data/examples/README.md +0 -148
- data/examples/configuration/legacy_auth.rb +0 -12
- data/examples/configuration/oauth.rb +0 -9
- data/examples/content/blog_post.rb +0 -39
- data/examples/content/blog_tag.rb +0 -10
- data/examples/content/redirect.rb +0 -43
- data/examples/customers/customer.rb +0 -36
- data/examples/customers/customer_address.rb +0 -50
- data/examples/customers/customer_group.rb +0 -35
- data/examples/exception_handling.rb +0 -50
- data/examples/geography/country.rb +0 -16
- data/examples/geography/state.rb +0 -19
- data/examples/marketing/coupon.rb +0 -44
- data/examples/orders/order.rb +0 -53
- data/examples/orders/order_coupon.rb +0 -17
- data/examples/orders/order_message.rb +0 -17
- data/examples/orders/order_product.rb +0 -23
- data/examples/orders/order_shipping_address.rb +0 -23
- data/examples/orders/order_status.rb +0 -15
- data/examples/orders/order_tax.rb +0 -17
- data/examples/orders/shipment.rb +0 -57
- data/examples/payments/payment_method.rb +0 -10
- data/examples/products/brand.rb +0 -36
- data/examples/products/bulk_pricing_rule.rb +0 -47
- data/examples/products/category.rb +0 -37
- data/examples/products/configurable_field.rb +0 -29
- data/examples/products/custom_field.rb +0 -44
- data/examples/products/google_product_search_mapping.rb +0 -12
- data/examples/products/option.rb +0 -37
- data/examples/products/option_set.rb +0 -35
- data/examples/products/option_set_option.rb +0 -50
- data/examples/products/option_value.rb +0 -43
- data/examples/products/product.rb +0 -44
- data/examples/products/product_image.rb +0 -42
- data/examples/products/product_option.rb +0 -17
- data/examples/products/product_review.rb +0 -12
- data/examples/products/product_rule.rb +0 -54
- data/examples/products/product_video.rb +0 -45
- data/examples/products/sku.rb +0 -48
- data/examples/shipping/shipping_method.rb +0 -13
- data/examples/store/store_info.rb +0 -10
- data/examples/system/time.rb +0 -10
- data/examples/tax/tax_class.rb +0 -13
- data/examples/webhooks/webhook.rb +0 -29
- data/spec/bigcommerce/bigcommerce_spec.rb +0 -76
- data/spec/bigcommerce/unit/actions_spec.rb +0 -151
- data/spec/bigcommerce/unit/exception_spec.rb +0 -53
- data/spec/bigcommerce/unit/middleware/auth_spec.rb +0 -18
- data/spec/bigcommerce/unit/middleware/http_exception_spec.rb +0 -40
- data/spec/bigcommerce/unit/request_spec.rb +0 -180
- data/spec/bigcommerce/unit/resources/content/blog_post_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/content/blog_tag_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/content/redirect_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/customers/customer_address_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/customers/customer_group_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/customers/customer_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/geography/country_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/geography/state_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/marketing/coupon_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/orders/order_product_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/orders/order_shipping_address_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/orders/order_spec.rb +0 -13
- data/spec/bigcommerce/unit/resources/orders/shipment_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/payments/payment_method_spec.rb +0 -23
- data/spec/bigcommerce/unit/resources/products/brand_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/products/bulk_pricing_rule_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/products/category_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/products/configurable_field_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/products/custom_field_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/products/google_product_search_mapping_spec.rb +0 -14
- data/spec/bigcommerce/unit/resources/products/option_set_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/products/option_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/products/product_image_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/products/product_review_spec.rb +0 -14
- data/spec/bigcommerce/unit/resources/products/product_rule_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/products/product_spec.rb +0 -13
- data/spec/bigcommerce/unit/resources/products/product_video_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/products/sku_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/resource_spec.rb +0 -4
- data/spec/bigcommerce/unit/resources/store_info/store_information_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/system/time_spec.rb +0 -12
- data/spec/bigcommerce/unit/version_spec.rb +0 -7
- data/spec/spec_helper.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 699fc230ea09d9242c9cbfb7e1d2183891127627
|
4
|
+
data.tar.gz: 94e9e4eeb4a9b8cdf53ff2bd26f78612d8457d25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 131581aaa53a9933c978f7649530128857e7a46e467c091b77effc27828ca895388bc78edfdd0cf5bb58bb14f8041a55417b90f52af98aab82480c3748563cc0
|
7
|
+
data.tar.gz: 88d65c0fa84ad4d4968e58b7780eaac14408d5ad123eafe1c1b158c04822ade1007cbf3c460c95235765efdb548baa0c34a4778b9a60283b8f45c4efa07479a1
|
data/README.md
CHANGED
@@ -1,54 +1,50 @@
|
|
1
|
-
#
|
1
|
+
# BigCommerce API Ruby
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/bigcommerce.
|
4
|
-
[![Build Status](https://travis-ci.org/bigcommerce/bigcommerce-api-ruby.
|
5
|
-
[![Dependency Status](https://gemnasium.com/bigcommerce/bigcommerce-api-ruby.
|
6
|
-
[![Code Climate](https://codeclimate.com/github/bigcommerce/bigcommerce-api-ruby.png)](https://codeclimate.com/github/bigcommerce/bigcommerce-api-ruby)
|
7
|
-
[![Coverage Status](https://coveralls.io/repos/bigcommerce/bigcommerce-api-ruby/badge.png?branch=master)](https://coveralls.io/r/bigcommerce/bigcommerce-api-ruby?branch=master)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/bigcommerce.svg)](https://rubygems.org/gems/bigcommerce)
|
4
|
+
[![Build Status](https://travis-ci.org/bigcommerce/bigcommerce-api-ruby.svg?branch=master)](https://travis-ci.org/bigcommerce/bigcommerce-api-ruby)
|
5
|
+
[![Dependency Status](https://gemnasium.com/bigcommerce/bigcommerce-api-ruby.svg?travis)](https://gemnasium.com/bigcommerce/bigcommerce-api-ruby)
|
8
6
|
|
9
|
-
This is the official
|
10
|
-
|
11
|
-
#### ⚠️ A note about the current client: ⚠️
|
12
|
-
This is a preview release of the 1.0.0 version of the Bigcommerce API Client. Please report issues if they come up.
|
13
|
-
|
14
|
-
We have introduced a new major version of the API client and it is a complete rewrite (for the better). If you want to see the old version of the API client, please view it here: [Bigcommerce API client v0.x](https://github.com/bigcommerce/bigcommerce-api-ruby/tree/0.x). We recommend that developers upgrade to the latest client, but we will still support our developers who are unable to upgrade.
|
7
|
+
This is the official BigCommerce API client to support our Stores API. You can find more information about becoming a BigCommerce developer here: [developer.bigcommerce.com](http://developer.bigcommerce.com).
|
15
8
|
|
16
9
|
|
17
10
|
## Installation
|
18
|
-
|
11
|
+
BigCommerce is available on [RubyGems](https://rubygems.org/gems/bigcommerce).
|
19
12
|
|
20
13
|
```sh
|
21
|
-
gem install bigcommerce
|
14
|
+
gem install bigcommerce
|
22
15
|
```
|
23
16
|
|
24
17
|
You can also add it to your Gemfile.
|
25
18
|
|
26
19
|
```rb
|
27
|
-
gem 'bigcommerce', '
|
20
|
+
gem 'bigcommerce', '~> 1.0.0'
|
28
21
|
```
|
29
22
|
|
23
|
+
## Requirements
|
24
|
+
- Ruby 2.0.0 or newer. Please refer to the `.travis.yml` to see which versions we officially support.
|
25
|
+
|
30
26
|
## Getting Started
|
31
|
-
In order to make requests to our API, you must register as a developer and have your credentials ready.
|
27
|
+
In order to make requests to our API, you must register as a developer and have your credentials ready.
|
32
28
|
|
33
|
-
|
29
|
+
Its also very important to note that for the OAuth authentication mechanism, the resources you have acccess to depend on the scopes which your application has been granted by the merchant. For more information about the Store API scopes, see: [OAuth Scopes](https://developer.bigcommerce.com/api/scopes).
|
34
30
|
|
35
|
-
|
36
|
-
|
31
|
+
## Authentication
|
32
|
+
We currently have two different authentication schemes you can use depending on your use case.
|
37
33
|
|
38
|
-
|
34
|
+
### OAuth
|
35
|
+
OAuth apps can be submitted to [BigCommerce App Store](https://www.bigcommerce.com/apps), allowing other merchants to install it in their BigCommerce store.
|
39
36
|
|
40
|
-
|
41
|
-
To develop a custom integration for one store, your app needs to use Basic Authentication.
|
37
|
+
__[More Information](https://developer.bigcommerce.com/api/using-oauth-intro)__
|
42
38
|
|
43
|
-
|
39
|
+
### Basic Authentication (Legacy)
|
40
|
+
To develop a custom integration for one store, your app needs to use Basic Authentication.
|
44
41
|
|
45
|
-
|
46
|
-
For full examples on using the API client, please see the [examples folder](examples).
|
42
|
+
__[More Information](https://developer.bigcommerce.com/api/legacy/basic-auth)__
|
47
43
|
|
48
44
|
## Configuration
|
49
|
-
In order to authenticate the API client, you will need to configure the client like
|
45
|
+
In order to authenticate the API client, you will need to configure the client like the following.
|
50
46
|
|
51
|
-
|
47
|
+
### OAuth App
|
52
48
|
|
53
49
|
- ```client_id```: Obtained from the "My Apps" section on the [developer portal](http://developer.bigcommerce.com).
|
54
50
|
- ```access_token```: Obtained after a token exchange in the auth callback.
|
@@ -56,26 +52,26 @@ In order to authenticate the API client, you will need to configure the client l
|
|
56
52
|
|
57
53
|
```rb
|
58
54
|
Bigcommerce.configure do |config|
|
59
|
-
config.store_hash = '
|
60
|
-
config.client_id = '
|
61
|
-
config.access_token = '
|
55
|
+
config.store_hash = ENV['BC_STORE_HASH']
|
56
|
+
config.client_id = ENV['BC_CLIENT_ID']
|
57
|
+
config.access_token = ENV['BC_ACCESS_TOKEN']
|
62
58
|
end
|
63
59
|
```
|
64
60
|
|
65
|
-
|
61
|
+
### Basic Authentication (Legacy)
|
66
62
|
|
67
|
-
To get all the
|
63
|
+
To get all the basic auth credentials, simply visit your store admin page and navigate to the `Advanced Settings > Legacy API Settings`. Once there, you can create a new legacy api account to authenticate with.
|
68
64
|
|
69
65
|
```rb
|
70
66
|
Bigcommerce.configure do |config|
|
71
67
|
config.auth = 'legacy'
|
72
|
-
config.url = '
|
73
|
-
config.username = '
|
74
|
-
config.api_key = '
|
68
|
+
config.url = ENV['BC_API_ENDPOINT_LEGACY']
|
69
|
+
config.username = ENV['BC_USERNAME']
|
70
|
+
config.api_key = ENV['BC_API_KEY']
|
75
71
|
end
|
76
72
|
```
|
77
73
|
|
78
|
-
__SSL
|
74
|
+
__SSL Configuration__
|
79
75
|
|
80
76
|
If you are using your own self-signed certificate, you can pass SSL options to Faraday. This is not required, but may be useful in special edge cases.
|
81
77
|
|
@@ -96,5 +92,71 @@ For more information about configuring SSL with Faraday, please see the followin
|
|
96
92
|
- [Faraday SSL example](https://gist.github.com/mislav/938183)
|
97
93
|
- [Setting up SSL certificates](https://github.com/lostisland/faraday/wiki/Setting-up-SSL-certificates)
|
98
94
|
|
95
|
+
|
96
|
+
## Usage
|
97
|
+
For full examples on using the API client, please see the [examples folder](examples) and refer to the [developer documentation](https://developer.bigcommerce.com/api).
|
98
|
+
|
99
|
+
Example:
|
100
|
+
|
101
|
+
```rb
|
102
|
+
# Configure the client to talk to a given store
|
103
|
+
Bigcommerce.configure do |config|
|
104
|
+
config.store_hash = ENV['BC_STORE_HASH']
|
105
|
+
config.client_id = ENV['BC_CLIENT_ID']
|
106
|
+
config.access_token = ENV['BC_ACCESS_TOKEN']
|
107
|
+
end
|
108
|
+
|
109
|
+
# Make an API request for a given resource
|
110
|
+
Bigcommerce::System.time
|
111
|
+
=> #<Bigcommerce::System time=1466801314>
|
112
|
+
```
|
113
|
+
|
114
|
+
### Thread Safety
|
115
|
+
|
116
|
+
The `Bigcommerce.configure` method is NOT thread safe. This mechanism is designed for applications or cli where thread safety is not a concern. If you need to guarantee thread safety, we support another mechanism to make threadsafe API requests.
|
117
|
+
|
118
|
+
Rather then setting up a single `connection` for all API requests, you will want to construct a new connection for each thread. If you can make sure that each of these connections is stored in a thread safe manner, you can pass the `connection` as you query the resource.
|
119
|
+
|
120
|
+
This connection is nothing more than a `Faraday::Connection` so if you want to write your own, or use your own adapers, you can feel free. Please refer to the [connection class](https://github.com/bigcommerce/bigcommerce-api-ruby/blob/master/lib/bigcommerce/connection.rb) for more details.
|
121
|
+
|
122
|
+
##### OAuth
|
123
|
+
|
124
|
+
```rb
|
125
|
+
connection = Bigcommerce::Connection.build(
|
126
|
+
Bigcommerce::Config.new(
|
127
|
+
store_hash: ENV['BC_STORE_HASH'],
|
128
|
+
client_id: ENV['BC_CLIENT_ID'],
|
129
|
+
access_token: ENV['BC_ACCESS_TOKEN']
|
130
|
+
)
|
131
|
+
)
|
132
|
+
=> #<Faraday::Connection:0x007fbf95068978 ... >>
|
133
|
+
|
134
|
+
Bigcommerce::System.time(connection: connection)
|
135
|
+
=> #<Bigcommerce::System time=1466546702>
|
136
|
+
|
137
|
+
Bigcommerce::System.raw_request(:get, 'time', connection: connection)
|
138
|
+
=> #<Faraday::Response:0x007fd4a4063170 ... >>
|
139
|
+
```
|
140
|
+
|
141
|
+
##### Basic Auth
|
142
|
+
|
143
|
+
```rb
|
144
|
+
connection_legacy = Bigcommerce::Connection.build(
|
145
|
+
Bigcommerce::Config.new(
|
146
|
+
auth: 'legacy',
|
147
|
+
url: ENV['BC_API_ENDPOINT_LEGACY'],
|
148
|
+
username: ENV['BC_USERNAME'],
|
149
|
+
api_key: ENV['BC_API_KEY']
|
150
|
+
)
|
151
|
+
)
|
152
|
+
=> #<Faraday::Connection:0x007fbf95068978 ... >>
|
153
|
+
|
154
|
+
Bigcommerce::System.time(connection: connection_legacy)
|
155
|
+
=> #<Bigcommerce::System time=1466546702>
|
156
|
+
|
157
|
+
Bigcommerce::System.raw_request(:get, 'time', connection: connection_legacy)
|
158
|
+
=> #<Faraday::Response:0x007fd4a4063170 ... >>
|
159
|
+
```
|
160
|
+
|
99
161
|
## Contributing
|
100
162
|
See [CONTRIBUTING.md](CONTRIBUTING.md)
|
data/bigcommerce.gemspec
CHANGED
@@ -4,25 +4,23 @@ require 'bigcommerce/version'
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = 'bigcommerce'
|
7
|
-
s.homepage = 'https://github.com/bigcommerce/bigcommerce-api-ruby'
|
8
|
-
s.authors = ['Patrick Edelman']
|
9
7
|
s.version = Bigcommerce::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.required_ruby_version = '>= 2.0.0'
|
10
10
|
s.license = 'MIT'
|
11
11
|
|
12
|
-
s.
|
13
|
-
|
14
|
-
|
15
|
-
s.
|
12
|
+
s.authors = ['Patrick Edelman']
|
13
|
+
s.homepage = 'https://github.com/bigcommerce/bigcommerce-api-ruby'
|
14
|
+
s.summary = 'Ruby client library for the BigCommerce API'
|
15
|
+
s.description = s.summary
|
16
16
|
|
17
|
-
s.required_ruby_version = '>= 1.9.3'
|
18
17
|
s.require_paths = ['lib']
|
19
|
-
s.files =
|
20
|
-
s.test_files = Dir['spec/**/*.rb']
|
18
|
+
s.files = Dir['README.md', 'lib/**/*', 'bigcommerce.gemspec']
|
21
19
|
|
22
|
-
s.add_development_dependency 'rake'
|
23
20
|
s.add_development_dependency 'bundler'
|
21
|
+
s.add_development_dependency 'rake'
|
24
22
|
|
25
|
-
s.add_dependency 'faraday'
|
26
|
-
s.add_dependency 'faraday_middleware'
|
27
|
-
s.add_dependency 'hashie'
|
23
|
+
s.add_dependency 'faraday', '~> 0.9'
|
24
|
+
s.add_dependency 'faraday_middleware', '~> 0.10.0'
|
25
|
+
s.add_dependency 'hashie', '~> 3.4'
|
28
26
|
end
|
data/lib/bigcommerce.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'hashie'
|
2
2
|
require 'faraday_middleware'
|
3
3
|
require 'bigcommerce/version'
|
4
|
+
require 'bigcommerce/config'
|
5
|
+
require 'bigcommerce/connection'
|
4
6
|
require 'bigcommerce/middleware/auth'
|
5
7
|
require 'bigcommerce/middleware/http_exception'
|
6
8
|
require 'bigcommerce/resources/resource'
|
@@ -9,43 +11,12 @@ module Bigcommerce
|
|
9
11
|
resources = File.join(File.dirname(__FILE__), 'bigcommerce', 'resources', '**', '*.rb')
|
10
12
|
Dir.glob(resources, &method(:require))
|
11
13
|
|
12
|
-
DEFAULTS = {
|
13
|
-
base_url: 'https://api.bigcommerce.com'
|
14
|
-
}
|
15
|
-
|
16
|
-
HEADERS = {
|
17
|
-
'accept' => 'application/json',
|
18
|
-
'content-type' => 'application/json',
|
19
|
-
'user-agent' => 'bigcommerce-api-ruby'
|
20
|
-
}
|
21
|
-
|
22
14
|
class << self
|
23
15
|
attr_reader :api
|
24
|
-
attr_accessor :api_limit
|
25
16
|
|
26
17
|
def configure
|
27
|
-
config =
|
28
|
-
|
29
|
-
ssl_options = config.ssl if config.auth == 'legacy'
|
30
|
-
|
31
|
-
@api = Faraday.new(url: build_url(config), ssl: ssl_options) do |conn|
|
32
|
-
conn.request :json
|
33
|
-
conn.headers = HEADERS
|
34
|
-
if config.auth == 'legacy'
|
35
|
-
conn.use Faraday::Request::BasicAuthentication, config.username, config.api_key
|
36
|
-
else
|
37
|
-
conn.use Bigcommerce::Middleware::Auth, config
|
38
|
-
end
|
39
|
-
conn.use Bigcommerce::Middleware::HttpException
|
40
|
-
conn.adapter Faraday.default_adapter
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def build_url(config)
|
45
|
-
return config.url if config.auth == 'legacy'
|
46
|
-
|
47
|
-
base = ENV['BC_API_ENDPOINT'].nil? ? DEFAULTS[:base_url] : ENV['BC_API_ENDPOINT']
|
48
|
-
"#{base}/stores/#{config.store_hash}/v2"
|
18
|
+
@config = Bigcommerce::Config.new.tap { |h| yield(h) }
|
19
|
+
@api = Bigcommerce::Connection.build(@config)
|
49
20
|
end
|
50
21
|
end
|
51
22
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Bigcommerce
|
2
|
+
class Config < Hashie::Mash
|
3
|
+
DEFAULTS = {
|
4
|
+
base_url: 'https://api.bigcommerce.com'
|
5
|
+
}.freeze
|
6
|
+
|
7
|
+
def api_url
|
8
|
+
return url if auth == 'legacy'
|
9
|
+
|
10
|
+
base = ENV['BC_API_ENDPOINT'].to_s.empty? ? DEFAULTS[:base_url] : ENV['BC_API_ENDPOINT']
|
11
|
+
"#{base}/stores/#{store_hash}/v2"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Bigcommerce
|
2
|
+
module Connection
|
3
|
+
HEADERS = {
|
4
|
+
'accept' => 'application/json',
|
5
|
+
'content-type' => 'application/json',
|
6
|
+
'user-agent' => 'bigcommerce-api-ruby'
|
7
|
+
}.freeze
|
8
|
+
|
9
|
+
def self.build(config)
|
10
|
+
ssl_options = config.ssl if config.auth == 'legacy'
|
11
|
+
Faraday.new(url: config.api_url, ssl: ssl_options) do |conn|
|
12
|
+
conn.request :json
|
13
|
+
conn.headers = HEADERS
|
14
|
+
if config.auth == 'legacy'
|
15
|
+
conn.use Faraday::Request::BasicAuthentication, config.username, config.api_key
|
16
|
+
else
|
17
|
+
conn.use Bigcommerce::Middleware::Auth, config
|
18
|
+
end
|
19
|
+
conn.use Bigcommerce::Middleware::HttpException
|
20
|
+
conn.adapter Faraday.default_adapter
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -6,19 +6,19 @@ module Bigcommerce
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
class BadRequest
|
10
|
-
class Unauthorized
|
11
|
-
class Forbidden
|
12
|
-
class NotFound
|
13
|
-
class MethodNotAllowed
|
14
|
-
class NotAccepted
|
15
|
-
class TimeOut
|
16
|
-
class ResourceConflict
|
17
|
-
class TooManyRequests
|
18
|
-
class InternalServerError
|
19
|
-
class BadGateway
|
20
|
-
class ServiceUnavailable
|
21
|
-
class GatewayTimeout
|
9
|
+
class BadRequest < HttpError; end
|
10
|
+
class Unauthorized < HttpError; end
|
11
|
+
class Forbidden < HttpError; end
|
12
|
+
class NotFound < HttpError; end
|
13
|
+
class MethodNotAllowed < HttpError; end
|
14
|
+
class NotAccepted < HttpError; end
|
15
|
+
class TimeOut < HttpError; end
|
16
|
+
class ResourceConflict < HttpError; end
|
17
|
+
class TooManyRequests < HttpError; end
|
18
|
+
class InternalServerError < HttpError; end
|
19
|
+
class BadGateway < HttpError; end
|
20
|
+
class ServiceUnavailable < HttpError; end
|
21
|
+
class GatewayTimeout < HttpError; end
|
22
22
|
class BandwidthLimitExceeded < HttpError; end
|
23
23
|
|
24
24
|
module HttpErrors
|
@@ -37,15 +37,22 @@ module Bigcommerce
|
|
37
37
|
503 => Bigcommerce::ServiceUnavailable,
|
38
38
|
504 => Bigcommerce::GatewayTimeout,
|
39
39
|
509 => Bigcommerce::BandwidthLimitExceeded
|
40
|
-
}
|
40
|
+
}.freeze
|
41
41
|
|
42
42
|
def throw_http_exception!(code, env)
|
43
43
|
return unless ERRORS.keys.include? code
|
44
|
-
|
45
|
-
unless env
|
46
|
-
|
44
|
+
response_headers = {}
|
45
|
+
unless env.body.empty?
|
46
|
+
response_headers = begin
|
47
|
+
JSON.parse(env.body, symbolize_names: true)
|
48
|
+
rescue
|
49
|
+
{}
|
50
|
+
end
|
47
51
|
end
|
48
|
-
|
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
|
54
|
+
end
|
55
|
+
raise ERRORS[code].new(response_headers), env.body
|
49
56
|
end
|
50
57
|
end
|
51
58
|
end
|
data/lib/bigcommerce/request.rb
CHANGED
@@ -43,30 +43,29 @@ module Bigcommerce
|
|
43
43
|
end
|
44
44
|
|
45
45
|
module ClassMethods
|
46
|
-
def get(path, params =
|
46
|
+
def get(path, params = {})
|
47
47
|
response = raw_request(:get, path, params)
|
48
48
|
build_response_object response
|
49
49
|
end
|
50
50
|
|
51
|
-
def delete(path)
|
52
|
-
response = raw_request(:delete, path)
|
51
|
+
def delete(path, params = {})
|
52
|
+
response = raw_request(:delete, path, params)
|
53
53
|
response.body
|
54
54
|
end
|
55
55
|
|
56
|
-
def post(path, params)
|
56
|
+
def post(path, params = {})
|
57
57
|
response = raw_request(:post, path, params)
|
58
58
|
build_response_object response
|
59
59
|
end
|
60
60
|
|
61
|
-
def put(path, params)
|
61
|
+
def put(path, params = {})
|
62
62
|
response = raw_request(:put, path, params)
|
63
63
|
build_response_object response
|
64
64
|
end
|
65
65
|
|
66
|
-
def raw_request(method, path, params =
|
67
|
-
|
68
|
-
|
69
|
-
response
|
66
|
+
def raw_request(method, path, params = {})
|
67
|
+
client = params.delete(:connection) || Bigcommerce.api
|
68
|
+
client.send(method, path.to_s, params)
|
70
69
|
end
|
71
70
|
|
72
71
|
private
|
@@ -24,27 +24,27 @@ module Bigcommerce
|
|
24
24
|
get path.build, params
|
25
25
|
end
|
26
26
|
|
27
|
-
def find(resource_id)
|
28
|
-
|
29
|
-
get path.build(resource_id)
|
27
|
+
def find(resource_id, params = {})
|
28
|
+
raise ArgumentError if resource_id.nil?
|
29
|
+
get path.build(resource_id), params
|
30
30
|
end
|
31
31
|
|
32
|
-
def create(params)
|
32
|
+
def create(params = {})
|
33
33
|
post path.build, params
|
34
34
|
end
|
35
35
|
|
36
|
-
def update(resource_id, params)
|
37
|
-
|
36
|
+
def update(resource_id, params = {})
|
37
|
+
raise ArgumentError if resource_id.nil?
|
38
38
|
put path.build(resource_id), params
|
39
39
|
end
|
40
40
|
|
41
|
-
def destroy(resource_id)
|
42
|
-
|
43
|
-
delete path.build(resource_id)
|
41
|
+
def destroy(resource_id, params = {})
|
42
|
+
raise ArgumentError if resource_id.nil?
|
43
|
+
delete path.build(resource_id), params
|
44
44
|
end
|
45
45
|
|
46
|
-
def destroy_all
|
47
|
-
delete path.build
|
46
|
+
def destroy_all(params = {})
|
47
|
+
delete path.build, params
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|