solidus_json_api 0.3.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 +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +224 -0
- data/Gemfile +6 -0
- data/LICENSE +26 -0
- data/README.md +94 -0
- data/Rakefile +38 -0
- data/app/controllers/concerns/spree/api/v2/renderable.rb +63 -0
- data/app/controllers/spree/api/v2/base_controller.rb +9 -0
- data/app/controllers/spree/api/v2/children_controller.rb +29 -0
- data/app/controllers/spree/api/v2/countries_controller.rb +21 -0
- data/app/controllers/spree/api/v2/images_controller.rb +29 -0
- data/app/controllers/spree/api/v2/line_items_controller.rb +36 -0
- data/app/controllers/spree/api/v2/option_types_controller.rb +31 -0
- data/app/controllers/spree/api/v2/option_values_controller.rb +29 -0
- data/app/controllers/spree/api/v2/orders_controller.rb +21 -0
- data/app/controllers/spree/api/v2/prices_controller.rb +27 -0
- data/app/controllers/spree/api/v2/products_controller.rb +37 -0
- data/app/controllers/spree/api/v2/states_controller.rb +29 -0
- data/app/controllers/spree/api/v2/taxonomies_controller.rb +21 -0
- data/app/controllers/spree/api/v2/taxons_controller.rb +40 -0
- data/app/controllers/spree/api/v2/variants_controller.rb +35 -0
- data/app/models/spree/base_decorator.rb +5 -0
- data/app/models/spree/image_decorator.rb +3 -0
- data/app/models/spree/line_item_decorator.rb +3 -0
- data/app/models/spree/order_decorator.rb +3 -0
- data/app/models/spree/price_decorator.rb +3 -0
- data/app/models/spree/state_decorator.rb +3 -0
- data/app/serializers/spree/address_serializer.rb +9 -0
- data/app/serializers/spree/base_serializer.rb +13 -0
- data/app/serializers/spree/country_serializer.rb +7 -0
- data/app/serializers/spree/error_serializer.rb +55 -0
- data/app/serializers/spree/image_serializer.rb +13 -0
- data/app/serializers/spree/line_item_serializer.rb +13 -0
- data/app/serializers/spree/option_type_serializer.rb +8 -0
- data/app/serializers/spree/option_value_serializer.rb +8 -0
- data/app/serializers/spree/order_serializer.rb +20 -0
- data/app/serializers/spree/price_serializer.rb +7 -0
- data/app/serializers/spree/product_serializer.rb +12 -0
- data/app/serializers/spree/role_serializer.rb +5 -0
- data/app/serializers/spree/state_serializer.rb +7 -0
- data/app/serializers/spree/store_serializer.rb +6 -0
- data/app/serializers/spree/taxon_serializer.rb +16 -0
- data/app/serializers/spree/taxonomy_serializer.rb +7 -0
- data/app/serializers/spree/user_serializer.rb +5 -0
- data/app/serializers/spree/variant_serializer.rb +12 -0
- data/circle.yml +12 -0
- data/config/locales/en.yml +25 -0
- data/config/routes.rb +53 -0
- data/docs/.nojekyll +0 -0
- data/docs/Dockerfile +12 -0
- data/docs/Gemfile +14 -0
- data/docs/README.md +12 -0
- data/docs/Rakefile +9 -0
- data/docs/config.rb +39 -0
- data/docs/font-selection.json +148 -0
- data/docs/source/CNAME +1 -0
- data/docs/source/fonts/slate.eot +0 -0
- data/docs/source/fonts/slate.svg +14 -0
- data/docs/source/fonts/slate.ttf +0 -0
- data/docs/source/fonts/slate.woff +0 -0
- data/docs/source/fonts/slate.woff2 +0 -0
- data/docs/source/images/favicon.ico +0 -0
- data/docs/source/images/navbar.png +0 -0
- data/docs/source/includes/_countries.md +133 -0
- data/docs/source/includes/_errors.md +17 -0
- data/docs/source/includes/_filtering.md +11 -0
- data/docs/source/includes/_images.md +201 -0
- data/docs/source/includes/_line_items.md +143 -0
- data/docs/source/includes/_option_types.md +267 -0
- data/docs/source/includes/_option_values.md +227 -0
- data/docs/source/includes/_orders.md +150 -0
- data/docs/source/includes/_pagination.md +10 -0
- data/docs/source/includes/_prices.md +188 -0
- data/docs/source/includes/_products.md +407 -0
- data/docs/source/includes/_states.md +96 -0
- data/docs/source/includes/_taxonomies.md +325 -0
- data/docs/source/includes/_taxons.md +414 -0
- data/docs/source/includes/_variants.md +430 -0
- data/docs/source/index.md +51 -0
- data/docs/source/javascripts/all.js +4 -0
- data/docs/source/javascripts/all_nosearch.js +3 -0
- data/docs/source/javascripts/app/_lang.js +162 -0
- data/docs/source/javascripts/app/_search.js +74 -0
- data/docs/source/javascripts/app/_toc.js +55 -0
- data/docs/source/javascripts/lib/_energize.js +169 -0
- data/docs/source/javascripts/lib/_imagesloaded.min.js +7 -0
- data/docs/source/javascripts/lib/_jquery.highlight.js +108 -0
- data/docs/source/javascripts/lib/_jquery.tocify.js +1042 -0
- data/docs/source/javascripts/lib/_jquery_ui.js +566 -0
- data/docs/source/javascripts/lib/_lunr.js +1910 -0
- data/docs/source/layouts/layout.erb +110 -0
- data/docs/source/stylesheets/_icon-font.scss +38 -0
- data/docs/source/stylesheets/_normalize.css +427 -0
- data/docs/source/stylesheets/_syntax.scss.erb +27 -0
- data/docs/source/stylesheets/_variables.scss +109 -0
- data/docs/source/stylesheets/print.css.scss +142 -0
- data/docs/source/stylesheets/screen.css.scss +622 -0
- data/lib/solidus_json_api/config.rb +8 -0
- data/lib/solidus_json_api/engine.rb +21 -0
- data/lib/solidus_json_api.rb +5 -0
- data/solidus_json_api.gemspec +36 -0
- data/spec/controllers/spree/api/v2/base_controller_spec.rb +46 -0
- data/spec/controllers/spree/api/v2/children_controller_spec.rb +28 -0
- data/spec/controllers/spree/api/v2/countries_controller_spec.rb +25 -0
- data/spec/controllers/spree/api/v2/images_controller_spec.rb +91 -0
- data/spec/controllers/spree/api/v2/line_items_controller_spec.rb +101 -0
- data/spec/controllers/spree/api/v2/option_types_controller_spec.rb +71 -0
- data/spec/controllers/spree/api/v2/option_values_controller_spec.rb +88 -0
- data/spec/controllers/spree/api/v2/orders_controller_spec.rb +61 -0
- data/spec/controllers/spree/api/v2/prices_controller_spec.rb +55 -0
- data/spec/controllers/spree/api/v2/products_controller_spec.rb +99 -0
- data/spec/controllers/spree/api/v2/states_controller_spec.rb +42 -0
- data/spec/controllers/spree/api/v2/taxonomies_controller_spec.rb +31 -0
- data/spec/controllers/spree/api/v2/taxons_controller_spec.rb +54 -0
- data/spec/controllers/spree/api/v2/variants_controller_spec.rb +106 -0
- data/spec/lib/solidus_json_api/config_spec.rb +10 -0
- data/spec/models/spree/base_decorator_spec.rb +9 -0
- data/spec/models/spree/price_decorator_spec.rb +3 -0
- data/spec/serializers/spree/address_serializer_spec.rb +35 -0
- data/spec/serializers/spree/country_serializer_spec.rb +27 -0
- data/spec/serializers/spree/error_serializer_spec.rb +141 -0
- data/spec/serializers/spree/image_serializer_spec.rb +30 -0
- data/spec/serializers/spree/line_item_serializer_spec.rb +40 -0
- data/spec/serializers/spree/option_type_serializer_spec.rb +27 -0
- data/spec/serializers/spree/option_value_serializer_spec.rb +29 -0
- data/spec/serializers/spree/order_serializer_spec.rb +68 -0
- data/spec/serializers/spree/price_serializer_spec.rb +28 -0
- data/spec/serializers/spree/product_serializer_spec.rb +47 -0
- data/spec/serializers/spree/role_serializer_spec.rb +17 -0
- data/spec/serializers/spree/state_serializer_spec.rb +25 -0
- data/spec/serializers/spree/store_serializer_spec.rb +25 -0
- data/spec/serializers/spree/taxon_serializer_spec.rb +44 -0
- data/spec/serializers/spree/taxonomy_serializer_spec.rb +27 -0
- data/spec/serializers/spree/user_serializer_spec.rb +17 -0
- data/spec/serializers/spree/variant_serializer_spec.rb +55 -0
- data/spec/spec_helper.rb +57 -0
- data/spec/support/shoulda_matchers.rb +6 -0
- metadata +442 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 9fbe78a78d8359475015cbfa74cfe9499ec41f73
|
|
4
|
+
data.tar.gz: 170c03853cf34ed402ad9b34696273351cbc1b4b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 08ea9cfa3e8e47208b3278806d57e8155a39a3f48e64f27c0d8775684cb72ba28acdf131ef0a9b0cb0369693b6a1657a10b6af7be07698037838b9a020eb5025
|
|
7
|
+
data.tar.gz: 36e642a9ddc3c7e8433aa976235f40d5ce87f8e5a8b089c265d7472b4949d64ba8a07c84f43fee8a4f1e038d5321ccdcd3be579d0278f86b9278836f9c979836
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
* Support `status` and `code` for Error Objects
|
|
6
|
+
|
|
7
|
+
When an error is handed back to the user, we now provide the status and the
|
|
8
|
+
code keys. This adds another feature to the API that is supported by the
|
|
9
|
+
JSON API specification.
|
|
10
|
+
|
|
11
|
+
[Ben A. Morgan](https://github.com/BenMorganIO)
|
|
12
|
+
|
|
13
|
+
* Add Friendly ID Support for `Spree::Product`
|
|
14
|
+
|
|
15
|
+
When a request came in for `/api/v2/products/example-product` and there was
|
|
16
|
+
a product in the DB with a corresponding slug, it would return a 404. The
|
|
17
|
+
controller now calls `Spree::Product.friendly` before rendering any
|
|
18
|
+
instance.
|
|
19
|
+
|
|
20
|
+
[Ben A. Morgan](https://github.com/BenMorganIO)
|
|
21
|
+
|
|
22
|
+
* Drop Spree Support
|
|
23
|
+
|
|
24
|
+
After trying to get the spree support working, I’ve concluded that its just
|
|
25
|
+
not worth it. I know there’s a lot of you out there that really want this.
|
|
26
|
+
If you truly need to keep using Spree, please fork this repo and make the
|
|
27
|
+
necessary changes.
|
|
28
|
+
|
|
29
|
+
[Ben A. Morgan](https://github.com/BenMorganIO)
|
|
30
|
+
|
|
31
|
+
* The project has been renamed from `spree_api_v2` to `solidus_json_api`.
|
|
32
|
+
Since the Spree project is no longer maintained, then there's no reason to
|
|
33
|
+
give Spree a second API version. This means that you need to update the
|
|
34
|
+
following code:
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
### Before ###
|
|
38
|
+
|
|
39
|
+
# Gemfile
|
|
40
|
+
gem 'spree_api_v2'
|
|
41
|
+
|
|
42
|
+
# config/initializers/spree_api_v2.rb
|
|
43
|
+
SolidusApiV2.setup do |config|
|
|
44
|
+
config.parent_serializer = ApplicationSerializer
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
### After ###
|
|
48
|
+
|
|
49
|
+
# Gemfile
|
|
50
|
+
gem 'solidus_json_api'
|
|
51
|
+
|
|
52
|
+
# config/initializers/solidus_json_api.rb
|
|
53
|
+
SolidusJsonApi.setup do |config|
|
|
54
|
+
config.parent_serializer = ApplicationSerializer
|
|
55
|
+
end
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
[Ben A. Morgan](https://github.com/BenMorganIO)
|
|
59
|
+
|
|
60
|
+
* In Spree, you will receive an error if the stock is not sufficient when
|
|
61
|
+
updating a line item. This is done in this project since the API requires
|
|
62
|
+
it. However, when transition to Solidus, we discovered that this feature was
|
|
63
|
+
constrained to the complete state. We've added a validation check before
|
|
64
|
+
saving a line item. Please open an issue if you believe this to be an
|
|
65
|
+
anti-pattern.
|
|
66
|
+
|
|
67
|
+
[Ben A. Morgan](https://github.com/BenMorganIO)
|
|
68
|
+
|
|
69
|
+
* Removed `Spree::Order#considered_risky` from the JSON response since Solidus
|
|
70
|
+
doesn't support this anymore.
|
|
71
|
+
|
|
72
|
+
[Ben A. Morgan](https://github.com/BenMorganIO)
|
|
73
|
+
|
|
74
|
+
* `Spree::Variant#depth`, `Spree::Variant#width`, and `Spree::Variant#height`
|
|
75
|
+
now return `null` instead of `""` when empty.
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
// Before
|
|
79
|
+
{
|
|
80
|
+
"type" : "spree_variant",
|
|
81
|
+
"data" : {
|
|
82
|
+
"attributes" : {
|
|
83
|
+
"depth" : "",
|
|
84
|
+
"width" : "",
|
|
85
|
+
"height" : "",
|
|
86
|
+
...
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// After
|
|
92
|
+
{
|
|
93
|
+
"type" : "spree_variant",
|
|
94
|
+
"data" : {
|
|
95
|
+
"attributes" : {
|
|
96
|
+
"depth" : null,
|
|
97
|
+
"width" : null,
|
|
98
|
+
"height" : null,
|
|
99
|
+
...
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
[Ben A. Morgan](https://github.com/BenMorganIO)
|
|
106
|
+
|
|
107
|
+
* `Spree::LineItem#additional_tax_total` and `Spree::LineItem#adjustment_total`
|
|
108
|
+
now return as strings instead of floats in the api:
|
|
109
|
+
|
|
110
|
+
```json
|
|
111
|
+
// Before
|
|
112
|
+
{
|
|
113
|
+
"type" : "spree_line_item",
|
|
114
|
+
"data" : {
|
|
115
|
+
"attributes" : {
|
|
116
|
+
"additional_tax_total" : 0,
|
|
117
|
+
"adjustment_total" : 0.0,
|
|
118
|
+
...
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// After
|
|
124
|
+
{
|
|
125
|
+
"type" : "spree_line_item",
|
|
126
|
+
"data" : {
|
|
127
|
+
"attributes" : {
|
|
128
|
+
"additional_tax_total" : "0",
|
|
129
|
+
"adjustment_total" : "0.0",
|
|
130
|
+
...
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
[Ben A. Morgan](https://github.com/BenMorganIO)
|
|
137
|
+
|
|
138
|
+
* For Orders, you can now list them. A user can only view their own orders.
|
|
139
|
+
If the user is an admin, they can view all of the orders.
|
|
140
|
+
|
|
141
|
+
[Ben A. Morgan](https://github.com/BenMorganIO)
|
|
142
|
+
|
|
143
|
+
* POST `/api/v2/line_items` now requires JSON API format instead of the rails
|
|
144
|
+
format.
|
|
145
|
+
|
|
146
|
+
```shell
|
|
147
|
+
# Before
|
|
148
|
+
curl "https://example.com/api/v2/line_items"
|
|
149
|
+
-X POST
|
|
150
|
+
-d token=abc123
|
|
151
|
+
-d line_item[order_id]=1
|
|
152
|
+
-d line_item[variant_id]=1
|
|
153
|
+
-d line_item[quantity]=1
|
|
154
|
+
|
|
155
|
+
# After
|
|
156
|
+
curl "https://example.com/api/v2/line_items"
|
|
157
|
+
-X POST
|
|
158
|
+
-d token=abc123
|
|
159
|
+
-d data[attributes][order_id]=1
|
|
160
|
+
-d data[attributes][variant_id]=1
|
|
161
|
+
-d data[attributes][quantity]=1
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
[Ben A. Morgan](https://github.com/BenMorganIO)
|
|
165
|
+
|
|
166
|
+
## 0.2.2
|
|
167
|
+
|
|
168
|
+
* The parent serializer for `Spree::BaseSerializer` is now configurable.
|
|
169
|
+
In some instances, you may have an `ApplicationSerializer`.
|
|
170
|
+
To make the `Spree::BaseSerializer` use an `ApplicationSerializer` instead
|
|
171
|
+
of the `ActiveModel::Serializer`:
|
|
172
|
+
|
|
173
|
+
```ruby
|
|
174
|
+
# config/initializers/spree_api_v2.rb; or
|
|
175
|
+
# config/initializers/solidus_api_v2.rb
|
|
176
|
+
SpreeApiV2.setup do |config|
|
|
177
|
+
config.parent_serializer = ApplicationSerializer
|
|
178
|
+
end
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
[Ben A. Morgan](https://github.com/BenMorganIO)
|
|
182
|
+
|
|
183
|
+
## 0.2.1
|
|
184
|
+
|
|
185
|
+
* Fixes a bug where the user serializer wasn't extending from the `Spree::BaseSerializer` this is now fixed.
|
|
186
|
+
|
|
187
|
+
[Ben A. Morgan](https://github.com/BenMorganIO)
|
|
188
|
+
|
|
189
|
+
## 0.2.0
|
|
190
|
+
|
|
191
|
+
* Calling `super` inside fo `#index` and `#show` actions is now deprecated.
|
|
192
|
+
Since these are methods that are meant to be called, they have been renamed to `#render_collection` and `#render_instance`.
|
|
193
|
+
|
|
194
|
+
[Ben A. Morgan](https://github.com/BenMorganIO)
|
|
195
|
+
|
|
196
|
+
* Added support for [Solidus](https://github.com/solidusio/solidus).
|
|
197
|
+
|
|
198
|
+
[Ben A. Morgan](https://github.com/BenMorganIO)
|
|
199
|
+
|
|
200
|
+
* In some instances, you would like to use the helper methods provided by the Spree V2 API, but unable to extend from the controller.
|
|
201
|
+
The render methods have been moved to a concern.
|
|
202
|
+
If you would like to include them in a controller without having to extend from the `Spree::Api::V2::BaseController`, then:
|
|
203
|
+
|
|
204
|
+
```ruby
|
|
205
|
+
module Api
|
|
206
|
+
class MyController < Api::BaseController
|
|
207
|
+
# include the concern
|
|
208
|
+
include Spree::Api::V2::Renderable
|
|
209
|
+
|
|
210
|
+
# example usage of rendering all products without calling
|
|
211
|
+
# +render_instance+ but providing page detail information that conforms
|
|
212
|
+
# to the JSON API spec.
|
|
213
|
+
def index
|
|
214
|
+
render json: @products, meta: { page: page_details(@products) }
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
[Ben A. Morgan](https://github.com/BenMorganIO)
|
|
221
|
+
|
|
222
|
+
## 0.1.0
|
|
223
|
+
|
|
224
|
+
Initial Release
|
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Copyright (c) 2015 Ben A. Morgan
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
5
|
+
are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
* Redistributions of source code must retain the above copyright notice,
|
|
8
|
+
this list of conditions and the following disclaimer.
|
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
|
11
|
+
and/or other materials provided with the distribution.
|
|
12
|
+
* Neither the name Solidus nor the names of its contributors may be used to
|
|
13
|
+
endorse or promote products derived from this software without specific
|
|
14
|
+
prior written permission.
|
|
15
|
+
|
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
17
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
18
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
19
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
20
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
21
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
22
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
23
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
24
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
25
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
26
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Solidus JSON API
|
|
2
|
+
|
|
3
|
+
[](https://circleci.com/gh/wildcardlabs/solidus_json_api)
|
|
4
|
+
[](https://coveralls.io/github/wildcardlabs/solidus_json_api?branch=master)
|
|
5
|
+
|
|
6
|
+
A JSON API for Solidus.
|
|
7
|
+
|
|
8
|
+
Documentation: [http://solidusapi.wildcardlabs.com](http://solidusapi.wildcardlabs.com)
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
Add solidus_json_api to your Gemfile:
|
|
13
|
+
|
|
14
|
+
```ruby
|
|
15
|
+
gem 'solidus_json_api', github: 'wildcardlabs/solidus_json_api'
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Road to 1.0
|
|
19
|
+
|
|
20
|
+
***
|
|
21
|
+
Please note that there actually has been a _lot_ of work done.
|
|
22
|
+
The lack of checked off boxes doesn't give this gem the respect it deserves.
|
|
23
|
+
***
|
|
24
|
+
|
|
25
|
+
There's several things blocking 1.0.
|
|
26
|
+
Below, you'll see a bullet list of requirements that are both specific to the app, the JSON API spec, and third parties.
|
|
27
|
+
|
|
28
|
+
- [ ] Manage permissions with CanCanCan.
|
|
29
|
+
- [ ] Add support for XML.
|
|
30
|
+
- [ ] Add support for pagination.
|
|
31
|
+
- [x] `page` keyword support for pagination.
|
|
32
|
+
- [ ] `links` document at the root for `self`, `next`, `prev`, `last`, and `first`.
|
|
33
|
+
- [ ] Add support for filtration.
|
|
34
|
+
- [x] Be able to filter onto the main data object.
|
|
35
|
+
- [ ] Be able to filter the included relationships.
|
|
36
|
+
- [ ] Provide JSON API specific error objects. Provide support for:
|
|
37
|
+
- [ ] `id`
|
|
38
|
+
- [ ] `links`
|
|
39
|
+
- [ ] `about`
|
|
40
|
+
- [x] `status`
|
|
41
|
+
- [x] `code`
|
|
42
|
+
- [x] `title`
|
|
43
|
+
- [x] `detail`
|
|
44
|
+
- [ ] `source`
|
|
45
|
+
- [x] `pointer`
|
|
46
|
+
- [ ] `parameter`
|
|
47
|
+
- [x] `meta`
|
|
48
|
+
- [ ] Only accept data in the JSON API format.
|
|
49
|
+
- [ ] Respond with header `Content-Type: application/vnd.api+json`.
|
|
50
|
+
- [ ] Add support for sparse fieldsets.
|
|
51
|
+
- [ ] Add support for sorting.
|
|
52
|
+
|
|
53
|
+
| Resource | index | create | show | update | destroy |
|
|
54
|
+
|------------------|:-------:|:-------:|:-------:|:-------:|:-------:|
|
|
55
|
+
| Adjustment | [ ] | [ ] | [ ] | [ ] | [ ] |
|
|
56
|
+
| Address | [ ] | [ ] | [ ] | [ ] | [ ] |
|
|
57
|
+
| Checkout | [ ] | [ ] | [ ] | [ ] | [ ] |
|
|
58
|
+
| Country | [x] | [ ] | [x] | [ ] | [ ] |
|
|
59
|
+
| Image | [x] | [ ] | [x] | [ ] | [ ] |
|
|
60
|
+
| Line Item | [ ] | [x] | [ ] | [ ] | [ ] |
|
|
61
|
+
| Option Type | [x] | [ ] | [x] | [ ] | [ ] |
|
|
62
|
+
| Option Value | [x] | [ ] | [x] | [ ] | [ ] |
|
|
63
|
+
| Order | [x] | [ ] | [x] | [ ] | [ ] |
|
|
64
|
+
| Payment | [ ] | [ ] | [ ] | [ ] | [ ] |
|
|
65
|
+
| Price | [x] | [ ] | [x] | [ ] | [ ] |
|
|
66
|
+
| Product | [x] | [ ] | [x] | [ ] | [ ] |
|
|
67
|
+
| Product Property | [ ] | [ ] | [ ] | [ ] | [ ] |
|
|
68
|
+
| Return Auth | [ ] | [ ] | [ ] | [ ] | [ ] |
|
|
69
|
+
| Shipment | [ ] | [ ] | [ ] | [ ] | [ ] |
|
|
70
|
+
| State | [x] | [ ] | [x] | [ ] | [ ] |
|
|
71
|
+
| Stock Location | [ ] | [ ] | [ ] | [ ] | [ ] |
|
|
72
|
+
| Stock Movement | [ ] | [ ] | [ ] | [ ] | [ ] |
|
|
73
|
+
| Stock Item | [ ] | [ ] | [ ] | [ ] | [ ] |
|
|
74
|
+
| Store | [ ] | [ ] | [ ] | [ ] | [ ] |
|
|
75
|
+
| Store Credit | [ ] | [ ] | [ ] | [ ] | [ ] |
|
|
76
|
+
| Tax Category | [ ] | [ ] | [ ] | [ ] | [ ] |
|
|
77
|
+
| Tax Rate | [ ] | [ ] | [ ] | [ ] | [ ] |
|
|
78
|
+
| Taxon | [x] | [ ] | [x] | [ ] | [ ] |
|
|
79
|
+
| Taxonomy | [x] | [ ] | [x] | [ ] | [ ] |
|
|
80
|
+
| User | [x] | [ ] | [x] | [ ] | [ ] |
|
|
81
|
+
| Variant | [x] | [ ] | [x] | [ ] | [ ] |
|
|
82
|
+
| Zone | [ ] | [ ] | [ ] | [ ] | [ ] |
|
|
83
|
+
|
|
84
|
+
## Testing
|
|
85
|
+
|
|
86
|
+
First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run the specs.
|
|
87
|
+
The dummy app can be regenerated by using `rake test_app`.
|
|
88
|
+
|
|
89
|
+
```shell
|
|
90
|
+
bundle
|
|
91
|
+
bundle exec rake
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Copyright © 2015 Ben A. Morgan, released under the New BSD License
|
data/Rakefile
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'bundler'
|
|
2
|
+
|
|
3
|
+
Bundler::GemHelper.install_tasks
|
|
4
|
+
|
|
5
|
+
require 'rspec/core/rake_task'
|
|
6
|
+
|
|
7
|
+
require 'generators/spree/dummy/dummy_generator'
|
|
8
|
+
require 'generators/spree/install/install_generator'
|
|
9
|
+
|
|
10
|
+
RSpec::Core::RakeTask.new
|
|
11
|
+
|
|
12
|
+
task :default do
|
|
13
|
+
if Dir['spec/dummy'].empty?
|
|
14
|
+
Rake::Task[:test_app].invoke
|
|
15
|
+
Dir.chdir('../../')
|
|
16
|
+
end
|
|
17
|
+
Rake::Task[:spec].invoke
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
desc 'Generates a dummy app for testing'
|
|
21
|
+
task :test_app do
|
|
22
|
+
ENV["RAILS_ENV"] = 'test'
|
|
23
|
+
|
|
24
|
+
Spree::DummyGeneratorHelper.inject_extension_requirements = true
|
|
25
|
+
Spree::DummyGenerator.start %w(--lib_name=solidus_json_api --quiet)
|
|
26
|
+
|
|
27
|
+
Spree::InstallGenerator.class_eval do
|
|
28
|
+
def config_spree_yml() end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
Spree::InstallGenerator.start %w(
|
|
32
|
+
--lib_name=solidus_json_api --auto-accept --migrate=false --seed=false
|
|
33
|
+
--sample=false --quiet --user_class=Spree::LegacyUser
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
puts 'Setting up dummy database...'
|
|
37
|
+
system "bundle exec rake db:drop db:create db:migrate > #{File::NULL}"
|
|
38
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
module Renderable
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
protected
|
|
8
|
+
|
|
9
|
+
def render_collection(collection = [])
|
|
10
|
+
collection = collection.where(filter_params).paginate(page_params)
|
|
11
|
+
render json: collection, include: params[:include],
|
|
12
|
+
meta: { page: page_details(collection) }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def render_instance(object = {})
|
|
16
|
+
render json: object, include: params[:include]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def filter_params
|
|
20
|
+
params.fetch(:filter, {}).permit(*filter_attributes).transform_values do |value|
|
|
21
|
+
value.respond_to?(:each) ? value : value.split(',')
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def render_error(resource, options = {})
|
|
28
|
+
response.status = options.delete(:status) || 400
|
|
29
|
+
options[:response] = response
|
|
30
|
+
render json: error_response(resource, options)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def error_response(resource, options = {})
|
|
34
|
+
Spree::ErrorSerializer.new(resource, options).as_json
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def filter_attributes
|
|
38
|
+
attributes = serializer_attributes
|
|
39
|
+
attributes << :id unless attributes.include?(:id)
|
|
40
|
+
attributes.map { |a| [{ a => [] }, a] }.flatten
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def page_details(collection)
|
|
44
|
+
{
|
|
45
|
+
total_items: collection.total_count,
|
|
46
|
+
total_pages: collection.total_pages,
|
|
47
|
+
number: (page_params[:number] || 1).to_i,
|
|
48
|
+
size: (page_params[:size] || Kaminari.config.default_per_page).to_i
|
|
49
|
+
}
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def page_params
|
|
53
|
+
params.fetch(:page, {}).permit(:number, :size)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def serializer_attributes
|
|
57
|
+
serializer = "Spree::#{controller_name.camelize.singularize}Serializer"
|
|
58
|
+
serializer.constantize._attributes
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
class ChildrenController < Spree::Api::V2::BaseController
|
|
5
|
+
skip_before_action :authenticate_user, only: [:index, :show]
|
|
6
|
+
|
|
7
|
+
def index
|
|
8
|
+
render_collection children.includes(:products, :taxonomy, :children, :parent)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def show
|
|
12
|
+
render_instance children.find(params[:id])
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def children
|
|
18
|
+
if params[:taxon_id]
|
|
19
|
+
Spree::Taxon.find(params[:taxon_id])
|
|
20
|
+
end.children
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def filter_attributes
|
|
24
|
+
Spree::TaxonSerializer._attributes
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
class CountriesController < Spree::Api::V2::BaseController
|
|
5
|
+
skip_before_action :authenticate_user, only: [:index, :show]
|
|
6
|
+
|
|
7
|
+
def index
|
|
8
|
+
render_collection Spree::Country.includes(:states)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def show
|
|
12
|
+
if params[:state_id].present?
|
|
13
|
+
render_instance Spree::State.find_country(params[:state_id])
|
|
14
|
+
else
|
|
15
|
+
render_instance Spree::Country.find(params[:id])
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
class ImagesController < Spree::Api::V2::BaseController
|
|
5
|
+
skip_before_action :authenticate_user, only: [:index, :show]
|
|
6
|
+
|
|
7
|
+
def index
|
|
8
|
+
render_collection images.includes(:viewable)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def show
|
|
12
|
+
render_instance images.find(params[:id])
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def images
|
|
18
|
+
if params[:product_id]
|
|
19
|
+
Spree::Product.find(params[:product_id]).images
|
|
20
|
+
elsif params[:variant_id]
|
|
21
|
+
Spree::Variant.find(params[:variant_id]).images
|
|
22
|
+
else
|
|
23
|
+
Spree::Image
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
class LineItemsController < Spree::Api::V2::BaseController
|
|
5
|
+
rescue_from ActiveRecord::RecordNotFound, with: :render_record_not_found_error
|
|
6
|
+
rescue_from Spree::Order::InsufficientStock, with: :render_insufficient_stock_error
|
|
7
|
+
rescue_from RangeError, with: :render_range_error
|
|
8
|
+
|
|
9
|
+
def create
|
|
10
|
+
variant = Spree::Variant.find(line_item_params[:variant_id])
|
|
11
|
+
order = @current_api_user.orders.find(line_item_params[:order_id])
|
|
12
|
+
line_item = order.contents.add(variant, line_item_params[:quantity])
|
|
13
|
+
render_instance line_item
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def line_item_params
|
|
19
|
+
params.require(:data).require(:attributes).permit(:variant_id, :order_id, :quantity)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def render_range_error
|
|
23
|
+
render_error :quantity_too_high
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def render_insufficient_stock_error
|
|
27
|
+
render_error :product_out_of_stock
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def render_record_not_found_error
|
|
31
|
+
render_error :record_not_found
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
class OptionTypesController < Spree::Api::V2::BaseController
|
|
5
|
+
skip_before_action :authenticate_user, only: [:index, :show]
|
|
6
|
+
|
|
7
|
+
def index
|
|
8
|
+
render_collection option_types.includes(:option_values, :products)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def show
|
|
12
|
+
if params[:option_value_id]
|
|
13
|
+
render_instance Spree::OptionValue.find(params[:option_value_id]).option_type
|
|
14
|
+
else
|
|
15
|
+
render_instance option_types.find(params[:id])
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def option_types
|
|
22
|
+
if params[:product_id]
|
|
23
|
+
Spree::Product.find(params[:product_id]).option_types
|
|
24
|
+
else
|
|
25
|
+
Spree::OptionType
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
class OptionValuesController < Spree::Api::V2::BaseController
|
|
5
|
+
skip_before_action :authenticate_user, only: [:index, :show]
|
|
6
|
+
|
|
7
|
+
def index
|
|
8
|
+
render_collection option_values.includes(:option_type, :variants)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def show
|
|
12
|
+
render_instance option_values.find(params[:id])
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def option_values
|
|
18
|
+
if params[:option_type_id]
|
|
19
|
+
Spree::OptionType.find(params[:option_type_id]).option_values
|
|
20
|
+
elsif params[:variant_id]
|
|
21
|
+
Spree::Variant.find(params[:variant_id]).option_values
|
|
22
|
+
else
|
|
23
|
+
Spree::OptionValue
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|