spree_api_v1 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +189 -0
  3. data/.gitignore +23 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +24 -0
  6. data/CHANGELOG.md +3 -0
  7. data/CODE_OF_CONDUCT.md +22 -0
  8. data/Gemfile +59 -0
  9. data/LICENSE +26 -0
  10. data/README.md +62 -0
  11. data/Rakefile +15 -0
  12. data/app/controllers/spree/api/v1/addresses_controller.rb +46 -0
  13. data/app/controllers/spree/api/v1/base_controller.rb +174 -0
  14. data/app/controllers/spree/api/v1/checkouts_controller.rb +106 -0
  15. data/app/controllers/spree/api/v1/classifications_controller.rb +21 -0
  16. data/app/controllers/spree/api/v1/countries_controller.rb +22 -0
  17. data/app/controllers/spree/api/v1/credit_cards_controller.rb +26 -0
  18. data/app/controllers/spree/api/v1/customer_returns_controller.rb +25 -0
  19. data/app/controllers/spree/api/v1/images_controller.rb +58 -0
  20. data/app/controllers/spree/api/v1/inventory_units_controller.rb +54 -0
  21. data/app/controllers/spree/api/v1/line_items_controller.rb +70 -0
  22. data/app/controllers/spree/api/v1/option_types_controller.rb +60 -0
  23. data/app/controllers/spree/api/v1/option_values_controller.rb +62 -0
  24. data/app/controllers/spree/api/v1/orders_controller.rb +160 -0
  25. data/app/controllers/spree/api/v1/payments_controller.rb +82 -0
  26. data/app/controllers/spree/api/v1/product_properties_controller.rb +73 -0
  27. data/app/controllers/spree/api/v1/products_controller.rb +131 -0
  28. data/app/controllers/spree/api/v1/promotions_controller.rb +30 -0
  29. data/app/controllers/spree/api/v1/properties_controller.rb +70 -0
  30. data/app/controllers/spree/api/v1/reimbursements_controller.rb +25 -0
  31. data/app/controllers/spree/api/v1/return_authorizations_controller.rb +70 -0
  32. data/app/controllers/spree/api/v1/shipments_controller.rb +196 -0
  33. data/app/controllers/spree/api/v1/states_controller.rb +36 -0
  34. data/app/controllers/spree/api/v1/stock_items_controller.rb +82 -0
  35. data/app/controllers/spree/api/v1/stock_locations_controller.rb +53 -0
  36. data/app/controllers/spree/api/v1/stock_movements_controller.rb +45 -0
  37. data/app/controllers/spree/api/v1/stores_controller.rb +56 -0
  38. data/app/controllers/spree/api/v1/taxonomies_controller.rb +67 -0
  39. data/app/controllers/spree/api/v1/taxons_controller.rb +100 -0
  40. data/app/controllers/spree/api/v1/users_controller.rb +97 -0
  41. data/app/controllers/spree/api/v1/variants_controller.rb +81 -0
  42. data/app/controllers/spree/api/v1/zones_controller.rb +55 -0
  43. data/app/helpers/spree/api/api_helpers.rb +190 -0
  44. data/app/models/spree/api_v1_configuration.rb +5 -0
  45. data/app/views/spree/api/errors/gateway_error.rabl +2 -0
  46. data/app/views/spree/api/errors/invalid_api_key.rabl +2 -0
  47. data/app/views/spree/api/errors/invalid_resource.rabl +3 -0
  48. data/app/views/spree/api/errors/must_specify_api_key.rabl +2 -0
  49. data/app/views/spree/api/errors/not_found.rabl +2 -0
  50. data/app/views/spree/api/errors/unauthorized.rabl +2 -0
  51. data/app/views/spree/api/v1/addresses/show.rabl +10 -0
  52. data/app/views/spree/api/v1/adjustments/show.rabl +4 -0
  53. data/app/views/spree/api/v1/countries/index.rabl +7 -0
  54. data/app/views/spree/api/v1/countries/show.rabl +5 -0
  55. data/app/views/spree/api/v1/credit_cards/index.rabl +7 -0
  56. data/app/views/spree/api/v1/credit_cards/show.rabl +3 -0
  57. data/app/views/spree/api/v1/customer_returns/index.rabl +7 -0
  58. data/app/views/spree/api/v1/images/index.rabl +4 -0
  59. data/app/views/spree/api/v1/images/new.rabl +3 -0
  60. data/app/views/spree/api/v1/images/show.rabl +6 -0
  61. data/app/views/spree/api/v1/inventory_units/show.rabl +2 -0
  62. data/app/views/spree/api/v1/line_items/new.rabl +3 -0
  63. data/app/views/spree/api/v1/line_items/show.rabl +14 -0
  64. data/app/views/spree/api/v1/option_types/index.rabl +3 -0
  65. data/app/views/spree/api/v1/option_types/new.rabl +3 -0
  66. data/app/views/spree/api/v1/option_types/show.rabl +5 -0
  67. data/app/views/spree/api/v1/option_values/index.rabl +3 -0
  68. data/app/views/spree/api/v1/option_values/new.rabl +3 -0
  69. data/app/views/spree/api/v1/option_values/show.rabl +2 -0
  70. data/app/views/spree/api/v1/orders/address.rabl +0 -0
  71. data/app/views/spree/api/v1/orders/canceled.rabl +0 -0
  72. data/app/views/spree/api/v1/orders/cart.rabl +0 -0
  73. data/app/views/spree/api/v1/orders/complete.rabl +0 -0
  74. data/app/views/spree/api/v1/orders/could_not_apply_coupon.rabl +2 -0
  75. data/app/views/spree/api/v1/orders/could_not_transition.rabl +3 -0
  76. data/app/views/spree/api/v1/orders/index.rabl +7 -0
  77. data/app/views/spree/api/v1/orders/insufficient_quantity.rabl +2 -0
  78. data/app/views/spree/api/v1/orders/invalid_shipping_method.rabl +2 -0
  79. data/app/views/spree/api/v1/orders/mine.rabl +9 -0
  80. data/app/views/spree/api/v1/orders/order.rabl +10 -0
  81. data/app/views/spree/api/v1/orders/payment.rabl +3 -0
  82. data/app/views/spree/api/v1/orders/show.rabl +51 -0
  83. data/app/views/spree/api/v1/payments/credit_over_limit.rabl +2 -0
  84. data/app/views/spree/api/v1/payments/index.rabl +7 -0
  85. data/app/views/spree/api/v1/payments/new.rabl +5 -0
  86. data/app/views/spree/api/v1/payments/show.rabl +2 -0
  87. data/app/views/spree/api/v1/payments/update_forbidden.rabl +2 -0
  88. data/app/views/spree/api/v1/product_properties/index.rabl +7 -0
  89. data/app/views/spree/api/v1/product_properties/new.rabl +2 -0
  90. data/app/views/spree/api/v1/product_properties/show.rabl +2 -0
  91. data/app/views/spree/api/v1/products/index.rabl +9 -0
  92. data/app/views/spree/api/v1/products/new.rabl +3 -0
  93. data/app/views/spree/api/v1/products/product.rabl +1 -0
  94. data/app/views/spree/api/v1/products/show.rabl +36 -0
  95. data/app/views/spree/api/v1/promotions/handler.rabl +5 -0
  96. data/app/views/spree/api/v1/promotions/show.rabl +2 -0
  97. data/app/views/spree/api/v1/properties/index.rabl +7 -0
  98. data/app/views/spree/api/v1/properties/new.rabl +2 -0
  99. data/app/views/spree/api/v1/properties/show.rabl +2 -0
  100. data/app/views/spree/api/v1/reimbursements/index.rabl +7 -0
  101. data/app/views/spree/api/v1/return_authorizations/index.rabl +7 -0
  102. data/app/views/spree/api/v1/return_authorizations/new.rabl +3 -0
  103. data/app/views/spree/api/v1/return_authorizations/show.rabl +2 -0
  104. data/app/views/spree/api/v1/shared/stock_location_required.rabl +2 -0
  105. data/app/views/spree/api/v1/shipments/big.rabl +48 -0
  106. data/app/views/spree/api/v1/shipments/cannot_ready_shipment.rabl +2 -0
  107. data/app/views/spree/api/v1/shipments/mine.rabl +9 -0
  108. data/app/views/spree/api/v1/shipments/show.rabl +32 -0
  109. data/app/views/spree/api/v1/shipments/small.rabl +37 -0
  110. data/app/views/spree/api/v1/shipping_rates/show.rabl +2 -0
  111. data/app/views/spree/api/v1/states/index.rabl +12 -0
  112. data/app/views/spree/api/v1/states/show.rabl +2 -0
  113. data/app/views/spree/api/v1/stock_items/index.rabl +7 -0
  114. data/app/views/spree/api/v1/stock_items/show.rabl +5 -0
  115. data/app/views/spree/api/v1/stock_locations/index.rabl +7 -0
  116. data/app/views/spree/api/v1/stock_locations/show.rabl +8 -0
  117. data/app/views/spree/api/v1/stock_movements/index.rabl +7 -0
  118. data/app/views/spree/api/v1/stock_movements/show.rabl +5 -0
  119. data/app/views/spree/api/v1/stores/index.rabl +4 -0
  120. data/app/views/spree/api/v1/stores/show.rabl +2 -0
  121. data/app/views/spree/api/v1/tags/index.rabl +9 -0
  122. data/app/views/spree/api/v1/taxonomies/index.rabl +7 -0
  123. data/app/views/spree/api/v1/taxonomies/jstree.rabl +7 -0
  124. data/app/views/spree/api/v1/taxonomies/nested.rabl +11 -0
  125. data/app/views/spree/api/v1/taxonomies/new.rabl +3 -0
  126. data/app/views/spree/api/v1/taxonomies/show.rabl +15 -0
  127. data/app/views/spree/api/v1/taxons/index.rabl +10 -0
  128. data/app/views/spree/api/v1/taxons/jstree.rabl +7 -0
  129. data/app/views/spree/api/v1/taxons/new.rabl +3 -0
  130. data/app/views/spree/api/v1/taxons/show.rabl +6 -0
  131. data/app/views/spree/api/v1/taxons/taxons.rabl +5 -0
  132. data/app/views/spree/api/v1/users/index.rabl +7 -0
  133. data/app/views/spree/api/v1/users/new.rabl +3 -0
  134. data/app/views/spree/api/v1/users/show.rabl +11 -0
  135. data/app/views/spree/api/v1/variants/big.rabl +14 -0
  136. data/app/views/spree/api/v1/variants/index.rabl +9 -0
  137. data/app/views/spree/api/v1/variants/new.rabl +2 -0
  138. data/app/views/spree/api/v1/variants/show.rabl +3 -0
  139. data/app/views/spree/api/v1/variants/small.rabl +18 -0
  140. data/app/views/spree/api/v1/zones/index.rabl +7 -0
  141. data/app/views/spree/api/v1/zones/show.rabl +6 -0
  142. data/config/initializers/rabl.rb +9 -0
  143. data/config/routes.rb +123 -0
  144. data/lib/spree/api_v1/controller_setup.rb +19 -0
  145. data/lib/spree/api_v1/engine.rb +27 -0
  146. data/lib/spree/api_v1/factories.rb +6 -0
  147. data/lib/spree/api_v1/responders/rabl_template.rb +28 -0
  148. data/lib/spree/api_v1/responders.rb +11 -0
  149. data/lib/spree/api_v1/testing_support/helpers.rb +44 -0
  150. data/lib/spree/api_v1/testing_support/setup.rb +16 -0
  151. data/lib/spree/api_v1/version.rb +9 -0
  152. data/lib/spree/api_v1.rb +9 -0
  153. data/lib/spree_api_v1.rb +3 -0
  154. data/script/rails +9 -0
  155. data/spec/fixtures/files/icon_256x256.jpg +0 -0
  156. data/spec/fixtures/thinking-cat.jpg +0 -0
  157. data/spree_api_v1.gemspec +26 -0
  158. metadata +261 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6b29a9a688a1080a3a177a72dc79a3d9672b625845bb7d66102f4f538c80a3ef
4
+ data.tar.gz: 54c30ed9a71decc6747cdee76d4e433e5e7cd176b2b0e4cd3e9949b2c0f35a77
5
+ SHA512:
6
+ metadata.gz: 01fc7632bbe6e33595f7b538e9a659de81796a87ce6aa6b35a9f1c1ec04d17fcd9ed2cf49515844485b42e10aeebd1848478727dfd17eb269849d3b769c31db0
7
+ data.tar.gz: a60545d2f100fac0029f0987435c89a38e881d5ae8014a53475edf39fea87dab83eef042f962f950e9e50a7ebb157f40aeee7af1b17b211cf47c1ec25a748259
@@ -0,0 +1,189 @@
1
+ version: 2.1
2
+
3
+ defaults: &defaults
4
+ environment: &environment
5
+ CIRCLE_TEST_REPORTS: /tmp/test-results
6
+ CIRCLE_ARTIFACTS: /tmp/test-artifacts
7
+ BUNDLE_JOBS: 4
8
+ BUNDLE_RETRY: 3
9
+ BUNDLE_PATH: ~/spree/vendor/bundle
10
+ RAILS_VERSION: '~> 7.0'
11
+ working_directory: ~/spree
12
+ docker:
13
+ - image: &ruby_2_7_image circleci/ruby:2.7-node-browsers
14
+ - image: &redis_image circleci/redis:6.2-alpine
15
+
16
+ defaults_3_0: &defaults_3_0
17
+ <<: *defaults
18
+ docker:
19
+ - image: &ruby_3_0_image circleci/ruby:3.0-node-browsers
20
+ - image: *redis_image
21
+
22
+ run_tests_2_7: &run_tests_2_7
23
+ <<: *defaults
24
+ parallelism: 2
25
+ steps:
26
+ - checkout
27
+ - restore_cache:
28
+ keys:
29
+ - spree-api-v1-bundle-v10-ruby-2-7-{{ .Branch }}
30
+ - spree-api-v1-bundle-v10-ruby-2-7
31
+ - run:
32
+ name: Install libvips
33
+ command: sudo apt-get install libvips
34
+ - run:
35
+ name: Set bundle path
36
+ command: bundle config --local path vendor/bundle
37
+ - run:
38
+ name: Ensure bundle Install
39
+ command: |
40
+ bundle check || bundle install
41
+ - run:
42
+ name: Create test app
43
+ command: |
44
+ bundle exec rake test_app
45
+ - run:
46
+ name: Run Rspec
47
+ command: |
48
+ TESTFILES=$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
49
+ bundle exec rspec --format documentation \
50
+ --format RspecJunitFormatter \
51
+ -o ~/rspec/rspec.xml \
52
+ -- ${TESTFILES}
53
+ - store_test_results:
54
+ path: ~/rspec
55
+ - store_artifacts:
56
+ path: /tmp/test-artifacts
57
+
58
+ run_tests_3_0: &run_tests_3_0
59
+ <<: *defaults_3_0
60
+ parallelism: 2
61
+ steps:
62
+ - checkout
63
+ - restore_cache:
64
+ keys:
65
+ - spree-api-v1-bundle-v10-ruby-3-0-{{ .Branch }}
66
+ - spree-api-v1-bundle-v10-ruby-3-0
67
+ - run:
68
+ name: Install libvips
69
+ command: sudo apt-get install libvips
70
+ - run:
71
+ name: Set bundle path
72
+ command: bundle config --local path vendor/bundle
73
+ - run:
74
+ name: Ensure bundle Install
75
+ command: |
76
+ bundle check || bundle install
77
+ - run:
78
+ name: Create test app
79
+ command: |
80
+ bundle exec rake test_app
81
+ - run:
82
+ name: Run Rspec
83
+ command: |
84
+ TESTFILES=$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
85
+ bundle exec rspec --format documentation \
86
+ --format RspecJunitFormatter \
87
+ -o ~/rspec/rspec.xml \
88
+ -- ${TESTFILES}
89
+ - store_test_results:
90
+ path: ~/rspec
91
+ - store_artifacts:
92
+ path: /tmp/test-artifacts
93
+
94
+ jobs:
95
+ bundle_ruby_2_7:
96
+ <<: *defaults
97
+ steps:
98
+ - checkout
99
+ - restore_cache:
100
+ keys:
101
+ - spree-api-v1-bundle-v10-ruby-2-7-{{ .Branch }}
102
+ - spree-api-v1-bundle-v10-ruby-2-7
103
+ - run:
104
+ name: Install libvips
105
+ command: sudo apt-get install libvips
106
+ - run:
107
+ name: Set bundle path
108
+ command: bundle config --local path vendor/bundle
109
+ - run:
110
+ name: Bundle Install
111
+ command: |
112
+ bundle check || bundle install
113
+ - save_cache:
114
+ paths:
115
+ - vendor/bundle
116
+ key: spree-api-v1-bundle-v10-ruby-2-7-{{ checksum "Gemfile.lock" }}
117
+
118
+ bundle_ruby_3_0:
119
+ <<: *defaults_3_0
120
+ steps:
121
+ - checkout
122
+ - restore_cache:
123
+ keys:
124
+ - spree-api-v1-bundle-v10-ruby-3-0-{{ .Branch }}
125
+ - spree-api-v1-bundle-v10-ruby-3-0
126
+ - run:
127
+ name: Install libvips
128
+ command: sudo apt-get install libvips
129
+ - run:
130
+ name: Set bundle path
131
+ command: bundle config --local path vendor/bundle
132
+ - run:
133
+ name: Bundle Install
134
+ command: |
135
+ bundle check || bundle install
136
+ - save_cache:
137
+ paths:
138
+ - vendor/bundle
139
+ key: spree-api-v1-bundle-v10-ruby-3-0-{{ checksum "Gemfile.lock" }}
140
+
141
+ tests_ruby_2_7_rails_7_0_postgres:
142
+ <<: *run_tests_2_7
143
+ environment: &postgres_environment
144
+ <<: *environment
145
+ DB: postgres
146
+ DB_HOST: localhost
147
+ DB_USERNAME: postgres
148
+ docker:
149
+ - image: *ruby_2_7_image
150
+ - image: *redis_image
151
+ - image: &postgres_image circleci/postgres:12-alpine
152
+ environment:
153
+ POSTGRES_USER: postgres
154
+
155
+ tests_ruby_3_0_rails_7_0_postgres:
156
+ <<: *run_tests_3_0
157
+ environment:
158
+ <<: *postgres_environment
159
+ docker:
160
+ - image: *ruby_3_0_image
161
+ - image: *postgres_image
162
+ - image: *redis_image
163
+
164
+ tests_ruby_2_7_rails_7_0_mysql:
165
+ <<: *run_tests_2_7
166
+ environment:
167
+ <<: *environment
168
+ DB: mysql
169
+ DB_HOST: 127.0.0.1
170
+ DB_USERNAME: root
171
+ COVERAGE: true
172
+ COVERAGE_DIR: /tmp/workspace/simplecov
173
+ docker:
174
+ - image: *ruby_2_7_image
175
+ - image: *redis_image
176
+ - image: &mysql_image circleci/mysql:8-ram
177
+
178
+ workflows:
179
+ version: 2
180
+ main:
181
+ jobs:
182
+ - bundle_ruby_2_7
183
+ - bundle_ruby_3_0
184
+ - tests_ruby_3_0_rails_7_0_postgres:
185
+ requires:
186
+ - bundle_ruby_3_0
187
+ - tests_ruby_2_7_rails_7_0_mysql:
188
+ requires:
189
+ - bundle_ruby_2_7
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .localeapp/locales
7
+ .project
8
+ .vscode
9
+ coverage
10
+ default
11
+ Gemfile.lock
12
+ tmp
13
+ nbproject
14
+ pkg
15
+ *.sw?
16
+ spec/dummy
17
+ .rvmrc
18
+ .sass-cache
19
+ public/spree
20
+ .ruby-version
21
+ .ruby-gemset
22
+ *.gem
23
+ */*.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ -r spec_helper
3
+ -f documentation
data/.rubocop.yml ADDED
@@ -0,0 +1,24 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ TargetRubyVersion: 2.5
4
+ Include:
5
+ - '**/Gemfile'
6
+ - '**/Rakefile'
7
+ - '**/Appraisals'
8
+ Exclude:
9
+ - 'spec/dummy/**/*'
10
+ - 'lib/generators/**/*'
11
+
12
+ Rails:
13
+ Enabled: true
14
+
15
+ Metrics/LineLength:
16
+ Max: 150
17
+
18
+ # DISABLED
19
+
20
+ Style/Documentation:
21
+ Enabled: false
22
+
23
+ Style/FrozenStringLiteralComment:
24
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## [4.5.0] - 2022-08-05
2
+
3
+ - Extract Spree Api V1 from Spree Api
@@ -0,0 +1,22 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
6
+
7
+ Examples of unacceptable behavior by participants include:
8
+
9
+ * The use of sexualized language or imagery
10
+ * Personal attacks
11
+ * Trolling or insulting/derogatory comments
12
+ * Public or private harassment
13
+ * Publishing other's private information, such as physical or electronic addresses, without explicit permission
14
+ * Other unethical or unprofessional conduct.
15
+
16
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
17
+
18
+ This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
19
+
20
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
21
+
22
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
data/Gemfile ADDED
@@ -0,0 +1,59 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]
4
+
5
+ %w[
6
+ actionmailer actionpack actionview activejob activemodel activerecord
7
+ activestorage activesupport railties
8
+ ].each do |rails_gem|
9
+ gem rails_gem, ENV.fetch('RAILS_VERSION', '~> 7.0.0'), require: false
10
+ end
11
+
12
+ platforms :jruby do
13
+ gem 'jruby-openssl'
14
+ end
15
+
16
+ platforms :ruby do
17
+ if ENV['DB'] == 'mysql'
18
+ gem 'mysql2'
19
+ else
20
+ gem 'pg', '~> 1.1'
21
+ end
22
+ end
23
+
24
+ gem 'sprockets-rails', '>= 2.0.0'
25
+
26
+ group :test do
27
+ gem 'database_cleaner', '~> 2.0'
28
+ gem 'factory_bot_rails', '~> 6.0'
29
+ gem 'multi_json'
30
+ gem 'rspec-activemodel-mocks', '~> 1.0'
31
+ gem 'rspec-rails', '~> 5.0'
32
+ gem 'rspec-retry'
33
+ gem 'rspec_junit_formatter'
34
+ gem 'simplecov', '0.17.1'
35
+ gem 'webmock', '~> 3.7'
36
+ gem 'timecop'
37
+ gem 'rails-controller-testing'
38
+ end
39
+
40
+ group :test, :development do
41
+ gem 'awesome_print'
42
+ gem 'gem-release'
43
+ gem 'redis'
44
+ gem 'rubocop', '~> 1.22.3', require: false # bumped
45
+ gem 'rubocop-rails', require: false
46
+ gem 'rubocop-rspec', require: false
47
+ gem 'pry-byebug'
48
+ gem 'ffaker'
49
+ end
50
+
51
+ group :development do
52
+ gem 'github_fast_changelog'
53
+ gem 'solargraph'
54
+ end
55
+
56
+ spree_opts = { github: 'spree/spree', branch: 'main' }
57
+ gem 'spree_core', spree_opts
58
+ gem 'spree_api', spree_opts
59
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2007-2015, Spree Commerce, Inc. and other contributors
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 Spree 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,62 @@
1
+ # Spree Api V1
2
+
3
+ This repository contains the deprecated V1 API, that was extracted from spree_api gem in Spree 4.5.
4
+
5
+ ## Installation
6
+
7
+ 1. Add this extension to your Gemfile with this line:
8
+
9
+ ```ruby
10
+ gem 'spree_api_v1'
11
+ ```
12
+
13
+ 2. Install the gem using Bundler
14
+
15
+ ```ruby
16
+ bundle install
17
+ ```
18
+
19
+ 3. Copy & run migrations
20
+
21
+ ```ruby
22
+ bundle exec rails g spree_api_v1:install
23
+ ```
24
+
25
+ 4. Restart your server
26
+
27
+ If your server was running, restart it so that it can find the assets properly.
28
+
29
+
30
+ ## Contributing
31
+
32
+ In the spirit of [free software][1], **everyone** is encouraged to help improve this project.
33
+
34
+ Here are some ways *you* can contribute:
35
+
36
+ * by using prerelease versions
37
+ * by reporting [bugs][2]
38
+ * by suggesting new features
39
+ * by writing or editing documentation
40
+ * by writing specifications
41
+ * by writing code (*no patch is too small*: fix typos, add comments, clean up inconsistent whitespace)
42
+ * by refactoring code
43
+ * by resolving [issues][2]
44
+ * by reviewing patches
45
+
46
+ Starting point:
47
+
48
+ * Fork the repo
49
+ * Clone your repo
50
+ * (You will need to `brew install mysql postgres` if you don't already have them installed)
51
+ * Run `bundle`
52
+ * (You may need to `bundle update` if bundler gets stuck)
53
+ * Run `bundle exec rake test_app` to create the test application in `spec/test_app`
54
+ * Make your changes
55
+ * Ensure specs pass by running `bundle exec rspec spec`
56
+ * Submit your pull request
57
+
58
+
59
+ License
60
+ ----------------------
61
+
62
+ Spree is released under the [New BSD License][3].
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rspec/core/rake_task'
5
+ require 'spree/testing_support/common_rake'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task default: :spec
10
+
11
+ desc "Generates a dummy app for testing"
12
+ task :test_app do
13
+ ENV['LIB_NAME'] = 'spree/api_v1'
14
+ Rake::Task['common:test_app'].invoke
15
+ end
@@ -0,0 +1,46 @@
1
+ module Spree
2
+ module Api
3
+ module V1
4
+ class AddressesController < Spree::Api::V1::BaseController
5
+ before_action :find_order
6
+
7
+ def show
8
+ authorize! :show, @order, order_token
9
+ @address = find_address
10
+ respond_with(@address)
11
+ end
12
+
13
+ def update
14
+ authorize! :update, @order, order_token
15
+ @address = find_address
16
+
17
+ if @address.update(address_params)
18
+ respond_with(@address, default_template: :show)
19
+ else
20
+ invalid_resource!(@address)
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def address_params
27
+ params.require(:address).permit(permitted_address_attributes)
28
+ end
29
+
30
+ def find_order
31
+ @order = Spree::Order.find_by!(number: order_id)
32
+ end
33
+
34
+ def find_address
35
+ if @order.bill_address_id == params[:id].to_i
36
+ @order.bill_address
37
+ elsif @order.ship_address_id == params[:id].to_i
38
+ @order.ship_address
39
+ else
40
+ raise CanCan::AccessDenied
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,174 @@
1
+
2
+ require_dependency 'spree/api_v1/controller_setup'
3
+
4
+ module Spree
5
+ module Api
6
+ module V1
7
+ class BaseController < ActionController::API
8
+ include Spree::ApiV1::ControllerSetup
9
+ include Spree::Core::ControllerHelpers::Store
10
+ include Spree::Core::ControllerHelpers::StrongParameters
11
+ include Spree::Core::ControllerHelpers::Locale
12
+ include Spree::Core::ControllerHelpers::Currency
13
+
14
+ attr_accessor :current_api_user
15
+
16
+ before_action :set_content_type
17
+ before_action :load_user
18
+ before_action :authorize_for_order, if: proc { order_token.present? }
19
+ before_action :authenticate_user
20
+ before_action :load_user_roles
21
+
22
+ rescue_from ActionController::ParameterMissing, with: :error_during_processing
23
+ rescue_from ActiveRecord::RecordInvalid, with: :error_during_processing
24
+ rescue_from ActiveRecord::RecordNotFound, with: :not_found
25
+ rescue_from CanCan::AccessDenied, with: :unauthorized
26
+ rescue_from Spree::Core::GatewayError, with: :gateway_error
27
+
28
+ helper Spree::Api::ApiHelpers
29
+
30
+ # users should be able to set price when importing orders via api
31
+ def permitted_line_item_attributes
32
+ if @current_user_roles.include?('admin')
33
+ super + [:price, :variant_id, :sku]
34
+ else
35
+ super
36
+ end
37
+ end
38
+
39
+ def content_type
40
+ case params[:format]
41
+ when 'json'
42
+ 'application/json; charset=utf-8'
43
+ when 'xml'
44
+ 'text/xml; charset=utf-8'
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def set_content_type
51
+ headers['Content-Type'] = content_type
52
+ end
53
+
54
+ def load_user
55
+ @current_api_user = Spree.user_class.find_by(spree_api_key: api_key.to_s)
56
+ end
57
+
58
+ def authenticate_user
59
+ return if @current_api_user
60
+
61
+ if requires_authentication? && api_key.blank? && order_token.blank?
62
+ must_specify_api_key and return
63
+ elsif order_token.blank? && (requires_authentication? || api_key.present?)
64
+ invalid_api_key and return
65
+ else
66
+ # An anonymous user
67
+ @current_api_user = Spree.user_class.new
68
+ end
69
+ end
70
+
71
+ def invalid_api_key
72
+ render 'spree/api/errors/invalid_api_key', status: 401
73
+ end
74
+
75
+ def must_specify_api_key
76
+ render 'spree/api/errors/must_specify_api_key', status: 401
77
+ end
78
+
79
+ def load_user_roles
80
+ @current_user_roles = @current_api_user ? @current_api_user.spree_roles.pluck(:name) : []
81
+ end
82
+
83
+ def unauthorized
84
+ render 'spree/api/errors/unauthorized', status: 401 and return
85
+ end
86
+
87
+ def error_during_processing(exception)
88
+ message = if exception.respond_to?(:original_message)
89
+ exception.original_message
90
+ else
91
+ exception.message
92
+ end
93
+
94
+ Rails.logger.error message
95
+ Rails.logger.error exception.backtrace.join("\n")
96
+
97
+ unprocessable_entity(message)
98
+ end
99
+
100
+ def unprocessable_entity(message)
101
+ render plain: { exception: message }.to_json, status: 422
102
+ end
103
+
104
+ def gateway_error(exception)
105
+ @order.errors.add(:base, exception.message)
106
+ invalid_resource!(@order)
107
+ end
108
+
109
+ def requires_authentication?
110
+ Spree::ApiV1::Config[:requires_authentication]
111
+ end
112
+
113
+ def not_found
114
+ render 'spree/api/errors/not_found', status: 404 and return
115
+ end
116
+
117
+ def current_ability
118
+ Spree::Dependencies.ability_class.constantize.new(current_api_user)
119
+ end
120
+
121
+ def invalid_resource!(resource)
122
+ @resource = resource
123
+ render 'spree/api/errors/invalid_resource', status: 422
124
+ end
125
+
126
+ def api_key
127
+ request.headers['X-Spree-Token'] || params[:token]
128
+ end
129
+ helper_method :api_key
130
+
131
+ def order_token
132
+ request.headers['X-Spree-Order-Token'] || params[:order_token]
133
+ end
134
+
135
+ def find_product(id)
136
+ @product = product_scope.friendly.distinct(false).find(id.to_s)
137
+ rescue ActiveRecord::RecordNotFound
138
+ @product = product_scope.find_by(id: id)
139
+ not_found unless @product
140
+ end
141
+
142
+ def product_scope
143
+ if @current_user_roles.include?('admin')
144
+ scope = Product.with_deleted.accessible_by(current_ability, :show).includes(*product_includes)
145
+
146
+ scope = scope.not_deleted unless params[:show_deleted]
147
+ scope = scope.not_discontinued unless params[:show_discontinued]
148
+ else
149
+ scope = Product.accessible_by(current_ability, :show).active.includes(*product_includes)
150
+ end
151
+
152
+ scope
153
+ end
154
+
155
+ def variants_associations
156
+ [{ option_values: :option_type }, :default_price, :images]
157
+ end
158
+
159
+ def product_includes
160
+ [:option_types, :taxons, product_properties: :property, variants: variants_associations, master: variants_associations]
161
+ end
162
+
163
+ def order_id
164
+ params[:order_id] || params[:checkout_id] || params[:order_number]
165
+ end
166
+
167
+ def authorize_for_order
168
+ @order = Spree::Order.find_by(number: order_id)
169
+ authorize! :show, @order, order_token
170
+ end
171
+ end
172
+ end
173
+ end
174
+ end