bigcommerce 1.0.0.beta → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +115 -39
- data/bigcommerce.gemspec +12 -13
- data/lib/bigcommerce.rb +5 -34
- data/lib/bigcommerce/config.rb +14 -0
- data/lib/bigcommerce/connection.rb +26 -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 +22 -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 +47 -166
- 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: f89e22fe6e4042c5231912f0594eccc6e20cf2d2
|
4
|
+
data.tar.gz: e72dc04e6ea9894c47740882e89edfc14ceb84ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab56f2ab83b837201fc23c4e749633b47702a0ef48d081854b14ce220760f130675200a1513f2a8ba516419a2cf44b2e2da120289ab458130de333e5756f8077
|
7
|
+
data.tar.gz: b35e6c9009776ad58a0565d8d8785de254dfba5f1cadd10980c8c133d7fa70038485008c15bbcd6cf9f5f11f8e886b940c45ce269cb8e9a51e995207a70a53c9
|
data/README.md
CHANGED
@@ -1,83 +1,79 @@
|
|
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'
|
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
|
-
|
27
|
+
To make requests to our API, you must register as a developer and have your credentials ready.
|
32
28
|
|
33
|
-
|
29
|
+
Also very important: For the OAuth authentication mechanism, the resources to which you have acccess depend on the scopes that the merchant has granted to your application. For more information about 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 that you can select, 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 these apps in their BigCommerce stores.
|
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
|
-
|
45
|
+
To authenticate your API client, you will need to configure the client like the following examples.
|
50
46
|
|
51
|
-
|
47
|
+
### OAuth App
|
52
48
|
|
53
|
-
- ```client_id```: Obtained from the
|
49
|
+
- ```client_id```: Obtained from the on the BigCommerce [Developer Portal's](http://developer.bigcommerce.com) "My Apps" section.
|
54
50
|
- ```access_token```: Obtained after a token exchange in the auth callback.
|
55
51
|
- ```store_hash```: Also obtained after the token exchange.
|
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 on which to authenticate.
|
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
|
-
If you are using your own self-signed certificate, you can pass SSL options to Faraday. This is not required, but
|
76
|
+
If you are using your own, self-signed, certificate, you can pass SSL options to Faraday. This is not required, but might be useful in special edge cases.
|
81
77
|
|
82
78
|
```rb
|
83
79
|
Bigcommerce.configure do |config|
|
@@ -94,7 +90,87 @@ end
|
|
94
90
|
For more information about configuring SSL with Faraday, please see the following:
|
95
91
|
|
96
92
|
- [Faraday SSL example](https://gist.github.com/mislav/938183)
|
97
|
-
- [Setting up SSL certificates](https://github.com/lostisland/faraday/wiki/Setting-up-SSL-certificates)
|
93
|
+
- [Faraday: Setting up SSL certificates](https://github.com/lostisland/faraday/wiki/Setting-up-SSL-certificates)
|
94
|
+
|
95
|
+
### 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
|
+
|
98
|
+
- ```store_hash```: The store hash of the store you are operating against.
|
99
|
+
- ```client_id```: Obtained from the on the BigCommerce [Developer Portal's](http://developer.bigcommerce.com) "My Apps" section.
|
100
|
+
- ```client_secret```: Obtained from the on the BigCommerce [Developer Portal's](http://developer.bigcommerce.com) "My Apps" section.
|
101
|
+
|
102
|
+
```rb
|
103
|
+
Bigcommerce.configure do |config|
|
104
|
+
config.store_hash = ENV['BC_STORE_HASH']
|
105
|
+
config.client_id = ENV['BC_CLIENT_ID']
|
106
|
+
config.client_secret = ENV['BC_CLIENT_SECRET']
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
110
|
+
## Usage
|
111
|
+
For full examples of using the API client, please see the [examples folder](examples) and refer to BigCommerce's [developer documentation](https://developer.bigcommerce.com/api).
|
112
|
+
|
113
|
+
Example:
|
114
|
+
|
115
|
+
```rb
|
116
|
+
# Configure the client to talk to a given store
|
117
|
+
Bigcommerce.configure do |config|
|
118
|
+
config.store_hash = ENV['BC_STORE_HASH']
|
119
|
+
config.client_id = ENV['BC_CLIENT_ID']
|
120
|
+
config.access_token = ENV['BC_ACCESS_TOKEN']
|
121
|
+
end
|
122
|
+
|
123
|
+
# Make an API request for a given resource
|
124
|
+
Bigcommerce::System.time
|
125
|
+
=> #<Bigcommerce::System time=1466801314>
|
126
|
+
```
|
127
|
+
|
128
|
+
### Thread Safety
|
129
|
+
|
130
|
+
The `Bigcommerce.configure` method is NOT thread-safe. This mechanism is designed for applications or CLI's (command-line interfaces) where thread safety is not a concern. If you need to guarantee thread safety, we support this alternative mechanism to make thread-safe API requests:
|
131
|
+
|
132
|
+
Rather then setting up a single `connection` for all API requests, you would construct a new connection for each thread. If you can ensure that each of these connections is stored in a thread-safe manner, you can pass the `connection` as you query the resource.
|
133
|
+
|
134
|
+
This connection is nothing more than a `Faraday::Connection` – so if you want to write your own, or to use your own 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
|
+
|
136
|
+
##### OAuth
|
137
|
+
|
138
|
+
```rb
|
139
|
+
connection = Bigcommerce::Connection.build(
|
140
|
+
Bigcommerce::Config.new(
|
141
|
+
store_hash: ENV['BC_STORE_HASH'],
|
142
|
+
client_id: ENV['BC_CLIENT_ID'],
|
143
|
+
access_token: ENV['BC_ACCESS_TOKEN']
|
144
|
+
)
|
145
|
+
)
|
146
|
+
=> #<Faraday::Connection:0x007fbf95068978 ... >>
|
147
|
+
|
148
|
+
Bigcommerce::System.time(connection: connection)
|
149
|
+
=> #<Bigcommerce::System time=1466546702>
|
150
|
+
|
151
|
+
Bigcommerce::System.raw_request(:get, 'time', connection: connection)
|
152
|
+
=> #<Faraday::Response:0x007fd4a4063170 ... >>
|
153
|
+
```
|
154
|
+
|
155
|
+
##### Basic Auth
|
156
|
+
|
157
|
+
```rb
|
158
|
+
connection_legacy = Bigcommerce::Connection.build(
|
159
|
+
Bigcommerce::Config.new(
|
160
|
+
auth: 'legacy',
|
161
|
+
url: ENV['BC_API_ENDPOINT_LEGACY'],
|
162
|
+
username: ENV['BC_USERNAME'],
|
163
|
+
api_key: ENV['BC_API_KEY']
|
164
|
+
)
|
165
|
+
)
|
166
|
+
=> #<Faraday::Connection:0x007fbf95068978 ... >>
|
167
|
+
|
168
|
+
Bigcommerce::System.time(connection: connection_legacy)
|
169
|
+
=> #<Bigcommerce::System time=1466546702>
|
170
|
+
|
171
|
+
Bigcommerce::System.raw_request(:get, 'time', connection: connection_legacy)
|
172
|
+
=> #<Faraday::Response:0x007fd4a4063170 ... >>
|
173
|
+
```
|
98
174
|
|
99
175
|
## Contributing
|
100
176
|
See [CONTRIBUTING.md](CONTRIBUTING.md)
|
data/bigcommerce.gemspec
CHANGED
@@ -4,25 +4,24 @@ 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 = ['BigCommerce Engineering']
|
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.11'
|
24
|
+
s.add_dependency 'faraday_middleware', '~> 0.11'
|
25
|
+
s.add_dependency 'hashie', '~> 3.4'
|
26
|
+
s.add_dependency 'jwt', '~> 1.5.4'
|
28
27
|
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
|
-
attr_reader :api
|
24
|
-
attr_accessor :api_limit
|
15
|
+
attr_reader :api, :config
|
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,26 @@
|
|
1
|
+
module Bigcommerce
|
2
|
+
module Connection
|
3
|
+
HEADERS = {
|
4
|
+
'accept' => 'application/json',
|
5
|
+
'content-type' => 'application/json',
|
6
|
+
'user-agent' => 'bigcommerce-api-ruby',
|
7
|
+
'accept-encoding' => 'gzip'
|
8
|
+
}.freeze
|
9
|
+
|
10
|
+
def self.build(config)
|
11
|
+
ssl_options = config.ssl || {}
|
12
|
+
Faraday.new(url: config.api_url, ssl: ssl_options) do |conn|
|
13
|
+
conn.request :json
|
14
|
+
conn.headers = HEADERS
|
15
|
+
if config.auth == 'legacy'
|
16
|
+
conn.use Faraday::Request::BasicAuthentication, config.username, config.api_key
|
17
|
+
else
|
18
|
+
conn.use Bigcommerce::Middleware::Auth, config
|
19
|
+
end
|
20
|
+
conn.use Bigcommerce::Middleware::HttpException
|
21
|
+
conn.use FaradayMiddleware::Gzip
|
22
|
+
conn.adapter Faraday.default_adapter
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
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 StandardError
|
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
|